コード例 #1
0
def test_create_nested_dirs():
    fs = FakeFileSystem()
    fs.create_dir('plugins/portals')
    fs.create_dir('plugins/portals/src')
    assert fs.dir_exists('plugins') is True
    assert fs.dir_exists('plugins/portals') is True
    assert fs.dir_exists('plugins/portals/src') is True
コード例 #2
0
def test_ls_ext_deps_come_before_local():
    fs = FakeFileSystem()
    fs.create_dir('plugins/portals')

    # local deps
    deplist = "fileupload\nunderscore\n"
    fs.create_file('plugins/portals/dependencies', deplist)

    # external deps
    package = {
        'dependencies': {
            'fileupload': '/some/url',
            'underscore': '/other/url'
        }
    }
    fs.create_file('plugins/portals/package.json', json.dumps(package))
    fs.create_dir('plugins/portals/node_modules/fileupload/src')
    fs.create_dir('plugins/portals/node_modules/underscore/src')

    scan_path = ScanPath(fs, 'plugins')
    paths = scan_path.ls('portals')
    assert paths == [
        'plugins/portals/node_modules/fileupload',
        'plugins/portals/node_modules/underscore',
        'plugins/common/fileupload',
        'plugins/common/underscore',
        'plugins/portals'
    ]
コード例 #3
0
def test_ls_no_deps():
    fs = FakeFileSystem()
    fs.create_dir('plugins/portals')
    scan_path = ScanPath(fs, 'plugins')
    paths = scan_path.ls('portals')
    assert paths == [
        'plugins/portals'
    ]
コード例 #4
0
def test_create_files_same_dir():
    fs = FakeFileSystem()
    fs.create_dir('test-dir')
    fs.create_file('test-dir/hi.txt', 'hi')
    fs.create_file('test-dir/hello.txt', 'hello')

    with fs.open('test-dir/hi.txt') as f:
        assert f.read() == 'hi'
    with fs.open('test-dir/hello.txt') as f:
        assert f.read() == 'hello'
コード例 #5
0
def test_create_dir_and_file():
    fs = FakeFileSystem()
    fs.create_dir('/plugins/portals')

    dependency_file_content = 'fileupload\nunderscore\n'
    fs.create_file('/plugins/portals/dependencies', dependency_file_content)

    with fs.open('/plugins/portals/dependencies') as f:
        dependency_names = f.read().splitlines()
        assert dependency_names[0] == 'fileupload'
コード例 #6
0
def test_paths_with_extension_when_flat_dir():
    fs = FakeFileSystem()
    fs.create_dir('test-dir')
    fs.create_file('test-dir/hi.txt')
    fs.create_file('test-dir/hello.js')
    fs.create_file('test-dir/hello.txt')
    fs.create_file('test-dir/something.css')
    fs.create_file('test-dir/.gitignore')

    paths = fs.paths_with_extension('test-dir', 'txt')
    assert paths == ['test-dir/hi.txt', 'test-dir/hello.txt']
コード例 #7
0
def test_ls_when_package_json_without_external_deps():
    fs = FakeFileSystem()
    fs.create_dir('plugins/portals')
    package = {
        'name': 'portal'
    }
    fs.create_file('plugins/portals/package.json', json.dumps(package))
    scan_path = ScanPath(fs, 'plugins')
    paths = scan_path.ls('portals')
    assert paths == [
        'plugins/portals'
    ]
コード例 #8
0
def test_ls_local_deps():
    fs = FakeFileSystem()
    fs.create_dir('plugins/portals')
    deplist = "fileupload\nunderscore\n"
    fs.create_file('plugins/portals/dependencies', deplist)
    scan_path = ScanPath(fs, 'plugins')
    paths = scan_path.ls('portals')
    assert paths == [
        'plugins/common/fileupload',
        'plugins/common/underscore',
        'plugins/portals'
    ]
コード例 #9
0
def test_ls_when_package_json_with_external_dep_without_src_folder():
    fs = FakeFileSystem()
    fs.create_dir('plugins/portals')
    package = {
        'dependencies': {
            'fileupload': '/some/url'
        }
    }
    fs.create_file('plugins/portals/package.json', json.dumps(package))
    fs.create_dir('plugins/portals/node_modules/fileupload')
    scan_path = ScanPath(fs, 'plugins')
    paths = scan_path.ls('portals')
    assert paths == [
        'plugins/portals'
    ]
コード例 #10
0
def test_paths_with_extension_when_nested_dirs():
    fs = FakeFileSystem()
    fs.create_dir('test-dir')
    fs.create_file('test-dir/hi.txt')
    fs.create_dir('test-dir/src')
    fs.create_file('test-dir/src/hello.js')
    fs.create_dir('test-dir/docs')
    fs.create_file('test-dir/docs/hello.txt')
    fs.create_file('test-dir/.gitignore')

    paths = fs.paths_with_extension('test-dir', 'txt')
    assert paths == ['test-dir/hi.txt', 'test-dir/docs/hello.txt']
コード例 #11
0
def test_ls_when_package_json_with_external_deps():
    fs = FakeFileSystem()
    fs.create_dir('plugins/portals')
    package = """{
        "dependencies": {
            "zn-underscore": "/other/url",
            "apples": "/other/url",
            "fileupload": "/some/url"
        }
    }"""
    fs.create_file('plugins/portals/package.json', package)
    fs.create_dir('plugins/portals/node_modules/zn-underscore/src')
    fs.create_dir('plugins/portals/node_modules/apples/src')
    fs.create_dir('plugins/portals/node_modules/fileupload/src')
    scan_path = ScanPath(fs, 'plugins')
    paths = scan_path.ls('portals')
    assert paths == [
        'plugins/portals/node_modules/zn-underscore',
        'plugins/portals/node_modules/apples',
        'plugins/portals/node_modules/fileupload',
        'plugins/portals'
    ]