コード例 #1
0
def test_s3_set_dir(tmpdir):
    """ Verify building a package from an S3 directory. """
    with patch(
            't4.packages.list_object_versions') as list_object_versions_mock:
        pkg = Package()

        list_object_versions_mock.return_value = ([
            dict(Key='foo/a.txt', VersionId='xyz', IsLatest=True),
            dict(Key='foo/x/y.txt', VersionId='null', IsLatest=True),
            dict(Key='foo/z.txt', VersionId='123', IsLatest=False),
        ], [])

        pkg.set_dir('', 's3://bucket/foo/')

        assert pkg['a.txt'].physical_keys[
            0] == 's3://bucket/foo/a.txt?versionId=xyz'
        assert pkg['x']['y.txt'].physical_keys[0] == 's3://bucket/foo/x/y.txt'

        list_object_versions_mock.assert_called_with('bucket', 'foo/')

        list_object_versions_mock.reset_mock()

        pkg.set_dir('bar', 's3://bucket/foo')

        assert pkg['bar']['a.txt'].physical_keys[
            0] == 's3://bucket/foo/a.txt?versionId=xyz'
        assert pkg['bar']['x']['y.txt'].physical_keys[
            0] == 's3://bucket/foo/x/y.txt'

        list_object_versions_mock.assert_called_with('bucket', 'foo/')
コード例 #2
0
def test_local_set_dir(tmpdir):
    """ Verify building a package from a local directory. """
    pkg = Package()

    # Create some nested example files that contain their names.
    foodir = pathlib.Path("foo_dir")
    bazdir = pathlib.Path(foodir, "baz_dir")
    bazdir.mkdir(parents=True, exist_ok=True)
    with open('bar', 'w') as fd:
        fd.write(fd.name)
    with open('foo', 'w') as fd:
        fd.write(fd.name)
    with open(bazdir / 'baz', 'w') as fd:
        fd.write(fd.name)
    with open(foodir / 'bar', 'w') as fd:
        fd.write(fd.name)

    pkg = pkg.set_dir("/", ".")

    assert pathlib.Path(
        'foo').resolve().as_uri() == pkg['foo'].physical_keys[0]
    assert pathlib.Path(
        'bar').resolve().as_uri() == pkg['bar'].physical_keys[0]
    assert (bazdir / 'baz'
            ).resolve().as_uri() == pkg['foo_dir/baz_dir/baz'].physical_keys[0]
    assert (foodir /
            'bar').resolve().as_uri() == pkg['foo_dir/bar'].physical_keys[0]

    pkg = Package()
    pkg = pkg.set_dir('/', 'foo_dir/baz_dir/')
    # todo nested at set_dir site or relative to set_dir path.
    assert (bazdir / 'baz').resolve().as_uri() == pkg['baz'].physical_keys[0]

    pkg = Package()
    pkg = pkg.set_dir('my_keys', 'foo_dir/baz_dir/')
    # todo nested at set_dir site or relative to set_dir path.
    assert (bazdir /
            'baz').resolve().as_uri() == pkg['my_keys/baz'].physical_keys[0]

    # Verify ignoring files in the presence of a dot-quiltignore
    with open('.quiltignore', 'w') as fd:
        fd.write('foo\n')
        fd.write('bar')

    pkg = Package()
    pkg = pkg.set_dir("/", ".")
    assert 'foo_dir' in pkg.keys()
    assert 'foo' not in pkg.keys() and 'bar' not in pkg.keys()

    with open('.quiltignore', 'w') as fd:
        fd.write('foo_dir')

    pkg = Package()
    pkg = pkg.set_dir("/", ".")
    assert 'foo_dir' not in pkg.keys()

    with open('.quiltignore', 'w') as fd:
        fd.write('foo_dir\n')
        fd.write('foo_dir/baz_dir')

    pkg = Package()
    pkg = pkg.set_dir("/", ".")
    assert 'foo_dir/baz_dir' not in pkg.keys() and 'foo_dir' not in pkg.keys()