Example #1
0
def test_build(tmpdir):
    """Verify that build dumps the manifest to appdirs directory."""
    new_pkg = Package()

    # Create a dummy file to add to the package.
    test_file_name = 'bar'
    with open(test_file_name, "w") as fd:
        fd.write('test_file_content_string')
        test_file = Path(fd.name)

    # Build a new package into the local registry.
    new_pkg = new_pkg.set('foo', test_file_name)
    top_hash = new_pkg.build("Quilt/Test")

    # Verify manifest is registered by hash.
    out_path = Path(BASE_PATH, ".quilt/packages", top_hash)
    with open(out_path) as fd:
        pkg = Package.load(fd)
        assert test_file.resolve().as_uri() == pkg['foo'].physical_keys[0]

    # Verify latest points to the new location.
    named_pointer_path = Path(BASE_PATH,
                              ".quilt/named_packages/Quilt/Test/latest")
    with open(named_pointer_path) as fd:
        assert fd.read().replace('\n', '') == top_hash

    # Test unnamed packages.
    new_pkg = Package()
    new_pkg = new_pkg.set('bar', test_file_name)
    top_hash = new_pkg.build()
    out_path = Path(BASE_PATH, ".quilt/packages", top_hash)
    with open(out_path) as fd:
        pkg = Package.load(fd)
        assert test_file.resolve().as_uri() == pkg['bar'].physical_keys[0]
Example #2
0
    def test_default_registry(self):
        new_pkg = Package()

        # Create a dummy file to add to the package.
        test_file_name = 'bar'
        with open(test_file_name, "w") as fd:
            fd.write('test_file_content_string')
            test_file = Path(fd.name)

        # Build a new package into the local registry.
        new_pkg = new_pkg.set('foo', test_file_name)
        top_hash = new_pkg.build("Quilt/Test").top_hash

        # Verify manifest is registered by hash.
        out_path = Path(BASE_PATH, ".quilt/packages", top_hash)
        with open(out_path) as fd:
            pkg = Package.load(fd)
            assert test_file.resolve().as_uri() == pkg['foo'].physical_keys[0]

        # Verify latest points to the new location.
        named_pointer_path = Path(BASE_PATH,
                                  ".quilt/named_packages/Quilt/Test/latest")
        with open(named_pointer_path) as fd:
            assert fd.read().replace('\n', '') == top_hash

        # Test unnamed packages.
        new_pkg = Package()
        new_pkg = new_pkg.set('bar', test_file_name)
        top_hash = new_pkg.build().top_hash
        out_path = Path(BASE_PATH, ".quilt/packages", top_hash)
        with open(out_path) as fd:
            pkg = Package.load(fd)
            assert test_file.resolve().as_uri() == pkg['bar'].physical_keys[0]

        new_base_path = Path(BASE_PATH, ".quilttest")
        with patch('t4.packages.get_from_config') as mock_config:
            mock_config.return_value = new_base_path
            top_hash = new_pkg.build("Quilt/Test").top_hash
            out_path = Path(new_base_path, ".quilt/packages",
                            top_hash).resolve()
            with open(out_path) as fd:
                pkg = Package.load(fd)
                assert test_file.resolve().as_uri(
                ) == pkg['bar'].physical_keys[0]

        with patch('t4.packages.get_from_config') as mock_config:
            mock_config.return_value = new_base_path
            new_pkg.push("Quilt/Test")
            with open(out_path) as fd:
                pkg = Package.load(fd)
                assert pkg['bar'].physical_keys[0].endswith(
                    '.quilttest/Quilt/Test/bar')
Example #3
0
def test_dir_meta(tmpdir):
    test_meta = {'test': 'meta'}
    pkg = Package()
    pkg.set('asdf/jkl', LOCAL_MANIFEST)
    pkg.set('asdf/qwer', LOCAL_MANIFEST)
    pkg.set('qwer/asdf', LOCAL_MANIFEST)
    pkg.set('qwer/as/df', LOCAL_MANIFEST)
    pkg.build()
    assert pkg['asdf'].get_meta() == {}
    assert pkg.get_meta() == {}
    assert pkg['qwer']['as'].get_meta() == {}
    pkg['asdf'].set_meta(test_meta)
    assert pkg['asdf'].get_meta() == test_meta
    pkg['qwer']['as'].set_meta(test_meta)
    assert pkg['qwer']['as'].get_meta() == test_meta
    pkg.set_meta(test_meta)
    assert pkg.get_meta() == test_meta
    dump_path = os.path.join(tmpdir, 'test_meta')
    with open(dump_path, 'w') as f:
        pkg.dump(f)
    with open(dump_path) as f:
        pkg2 = Package.load(f)
    assert pkg2['asdf'].get_meta() == test_meta
    assert pkg2['qwer']['as'].get_meta() == test_meta
    assert pkg2.get_meta() == test_meta
Example #4
0
def test_materialize_from_remote(tmpdir):
    """ Verify loading data and mainfest transforms from S3. """
    with patch('botocore.client.BaseClient._make_api_call',
               new=mock_make_api_call):
        with open(REMOTE_MANIFEST) as fd:
            pkg = Package.load(fd)
        with patch('t4.data_transfer._download_file'), \
                patch('t4.Package.build', new=no_op_mock), \
                patch('t4.packages.get_remote_registry') as config_mock:
            config_mock.return_value = tmpdir
            mat_pkg = pkg.push('Quilt/test_pkg_name', tmpdir / 'pkg')
Example #5
0
    def test_commit_message_on_push(self):
        """ Verify commit messages populate correctly on push."""
        with patch('botocore.client.BaseClient._make_api_call',
                   new=mock_make_api_call):
            with open(REMOTE_MANIFEST) as fd:
                pkg = Package.load(fd)
            pkg.push('Quilt/test_pkg_name', 'pkg', message='test_message')
            assert pkg._meta['message'] == 'test_message'

            # ensure messages are strings
            with pytest.raises(ValueError):
                pkg.push('Quilt/test_pkg_name', 'pkg', message={})
Example #6
0
def test_commit_message_on_push(tmpdir):
    """ Verify commit messages populate correctly on push."""
    with patch('botocore.client.BaseClient._make_api_call',
               new=mock_make_api_call):
        with open(REMOTE_MANIFEST) as fd:
            pkg = Package.load(fd)
        with patch('t4.data_transfer._download_file'), \
                patch('t4.Package.build', new=no_op_mock), \
                patch('t4.packages.get_remote_registry') as config_mock:
            config_mock.return_value = BASE_DIR
            pkg.push('Quilt/test_pkg_name',
                     tmpdir / 'pkg',
                     message='test_message')
            assert pkg._meta['message'] == 'test_message'

            # ensure messages are strings
            with pytest.raises(ValueError):
                pkg.push('Quilt/test_pkg_name', tmpdir / 'pkg', message={})
Example #7
0
def test_read_manifest(tmpdir):
    """ Verify reading serialized manifest from disk. """
    with open(LOCAL_MANIFEST) as fd:
        pkg = Package.load(fd)

    out_path = os.path.join(tmpdir, 'new_manifest.jsonl')
    with open(out_path, 'w') as fd:
        pkg.dump(fd)

    # Insepct the jsonl to verify everything is maintained, i.e.
    # that load/dump results in an equivalent set.
    # todo: Use load/dump once __eq__ implemented.
    with open(LOCAL_MANIFEST) as fd:
        original_set = list(jsonlines.Reader(fd))
    with open(out_path) as fd:
        written_set = list(jsonlines.Reader(fd))
    assert len(original_set) == len(written_set)
    assert sorted(original_set, key=lambda k: k.get('logical_key','manifest')) \
        == sorted(written_set, key=lambda k: k.get('logical_key','manifest'))