示例#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]
示例#2
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
示例#3
0
def test_brackets():
    pkg = Package()
    pkg.set('asdf/jkl', LOCAL_MANIFEST)
    pkg.set('asdf/qwer', LOCAL_MANIFEST)
    pkg.set('qwer/asdf', LOCAL_MANIFEST)
    assert set(pkg.keys()) == {'asdf', 'qwer'}

    pkg2 = pkg['asdf']
    assert set(pkg2.keys()) == {'jkl', 'qwer'}

    assert pkg['asdf']['qwer'].get() == pathlib.Path(LOCAL_MANIFEST).as_uri()

    assert pkg['asdf']['qwer'] == pkg['asdf/qwer'] == pkg[('asdf', 'qwer')]
    assert pkg[[]] == pkg

    pkg = (Package().set(
        'foo', os.path.join(os.path.dirname(__file__), 'data', 'foo.txt'),
        {'foo': 'blah'}))
    pkg['foo'].meta['target'] = 'unicode'

    pkg.build()

    assert pkg['foo'].deserialize() == '123\n'
    assert pkg['foo']() == '123\n'

    with pytest.raises(KeyError):
        pkg['baz']

    with pytest.raises(TypeError):
        pkg[b'asdf']

    with pytest.raises(TypeError):
        pkg[0]
示例#4
0
    def test_brackets(self):
        pkg = Package()
        pkg.set('asdf/jkl', LOCAL_MANIFEST)
        pkg.set('asdf/qwer', LOCAL_MANIFEST)
        pkg.set('qwer/asdf', LOCAL_MANIFEST)
        assert set(pkg.keys()) == {'asdf', 'qwer'}

        pkg2 = pkg['asdf']
        assert set(pkg2.keys()) == {'jkl', 'qwer'}

        assert pkg['asdf']['qwer'].get() == LOCAL_MANIFEST.as_uri()

        assert pkg['asdf']['qwer'] == pkg['asdf/qwer'] == pkg[('asdf', 'qwer')]
        assert pkg[[]] == pkg

        pkg = (Package().set('foo', DATA_DIR / 'foo.txt', {'foo': 'blah'}))
        pkg['foo'].meta['target'] = 'unicode'

        pkg.build()

        assert pkg['foo'].deserialize() == '123\n'
        assert pkg['foo']() == '123\n'

        with pytest.raises(KeyError):
            pkg['baz']

        with pytest.raises(TypeError):
            pkg[b'asdf']

        with pytest.raises(TypeError):
            pkg[0]
示例#5
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')
示例#6
0
    def test_remote_install(self):
        """Verify that installing from a local package works as expected."""
        with patch('t4.packages.get_from_config') as get_config_mock, \
            patch('t4.Package.push') as push_mock:
            remote_registry = '.'
            get_config_mock.return_value = remote_registry
            pkg = Package()
            pkg.build('Quilt/nice-name')

            t4.Package.install('Quilt/nice-name', dest='./')
            push_mock.assert_called_once_with(dest='./',
                                              name='Quilt/nice-name',
                                              registry=remote_registry)
示例#7
0
def test_manifest():
    pkg = Package()
    pkg.set('as/df', LOCAL_MANIFEST)
    pkg.set('as/qw', LOCAL_MANIFEST)
    top_hash = pkg.build()
    manifest = list(pkg.manifest)

    pkg2 = Package.browse(pkg_hash=top_hash)
    assert list(pkg.manifest) == list(pkg2.manifest)
示例#8
0
    def test_manifest(self):
        pkg = Package()
        pkg.set('as/df', LOCAL_MANIFEST)
        pkg.set('as/qw', LOCAL_MANIFEST)
        top_hash = pkg.build().top_hash
        manifest = list(pkg.manifest)

        pkg2 = Package.browse(top_hash=top_hash, registry='local')
        assert list(pkg.manifest) == list(pkg2.manifest)
示例#9
0
def test_tophash_changes(tmpdir):
    test_file = tmpdir / 'test.txt'
    test_file.write_text('asdf', 'utf-8')

    pkg = Package()
    th1 = pkg.top_hash()
    pkg.set('asdf', test_file)
    pkg.build()
    th2 = pkg.top_hash()
    assert th1 != th2

    test_file.write_text('jkl', 'utf-8')
    pkg.set('jkl', test_file)
    pkg.build()
    th3 = pkg.top_hash()
    assert th1 != th3
    assert th2 != th3

    pkg.delete('jkl')
    th4 = pkg.top_hash()
    assert th2 == th4
示例#10
0
def test_diff():
    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")

    p1 = Package.browse('Quilt/Test')
    p2 = Package.browse('Quilt/Test')
    assert p1.diff(p2) == ([], [], [])