Beispiel #1
0
    def test_package_fetch(self):
        """ Package.fetch() on nested, relative keys """
        package_ = Package().set_dir('/', DATA_DIR / 'nested')

        out_dir = 'output'
        new_package_ = package_.fetch(out_dir)

        expected = {'one.txt': '1', 'two.txt': '2', 'three.txt': '3'}
        file_count = 0
        for dirpath, _, files in os.walk(out_dir):
            for name in files:
                file_count += 1
                with open(os.path.join(dirpath, name)) as file_:
                    assert name in expected, 'unexpected file: {}'.format(
                        file_)
                    contents = file_.read().strip()
                    assert contents == expected[name], \
                        'unexpected contents in {}: {}'.format(name, contents)
        assert file_count == len(expected), \
            'fetch wrote {} files; expected: {}'.format(file_count, expected)

        # test that package re-rooting works as expected
        out_dir_abs_path = f'file://{pathlib.Path(out_dir).absolute().as_posix()}'
        assert all(entry.physical_keys[0].startswith(out_dir_abs_path)
                   for _, entry in new_package_.walk())
Beispiel #2
0
def test_package_fetch(tmpdir):
    """ Package.fetch() on nested, relative keys """
    input_dir = os.path.dirname(__file__)
    package_ = Package().set_dir('/', os.path.join(input_dir, 'data',
                                                   'nested'))

    out_dir = os.path.join(tmpdir, 'output')
    package_.fetch(out_dir)

    expected = {'one.txt': '1', 'two.txt': '2', 'three.txt': '3'}
    file_count = 0
    for dirpath, _, files in os.walk(out_dir):
        for name in files:
            file_count += 1
            with open(os.path.join(out_dir, dirpath, name)) as file_:
                assert name in expected, 'unexpected file: {}'.format(file_)
                contents = file_.read().strip()
                assert contents == expected[name], \
                    'unexpected contents in {}: {}'.format(name, contents)
    assert file_count == len(expected), \
        'fetch wrote {} files; expected: {}'.format(file_count, expected)