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) == ([], [], [])
def exec_module(cls, module): """ Module executor. """ name_parts = module.__name__.split('.') registry = get_from_config('default_local_registry') if module.__name__ == 't4.data': # __path__ must be set even if the package is virtual. Since __path__ will be # scanned by all other finders preceding this one in sys.meta_path order, make sure # it points to someplace lacking importable objects module.__path__ = MODULE_PATH return module elif len(name_parts) == 3: # e.g. module.__name__ == t4.data.foo namespace = name_parts[2] # we do not know the name the user will ask for, so populate all valid names for pkg in list_packages(): pkg_user, pkg_name = pkg.split('/') if pkg_user == namespace: module.__dict__[pkg_name] = Package.browse( pkg, registry=registry) module.__path__ = MODULE_PATH return module else: assert False
def test_browse_package_from_registry(self): """ Verify loading manifest locally and from s3 """ with patch('t4.Package._from_path') as pkgmock: registry = BASE_PATH.as_uri() pkg = Package() pkgmock.return_value = pkg top_hash = pkg.top_hash # local registry load pkg = Package.browse(registry='local', top_hash=top_hash) assert '{}/.quilt/packages/{}'.format(registry, top_hash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() pkg = Package.browse('Quilt/nice-name', registry='local', top_hash=top_hash) assert '{}/.quilt/packages/{}'.format(registry, top_hash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() with patch('t4.packages.get_bytes') as dl_mock: dl_mock.return_value = (top_hash.encode('utf-8'), None) pkg = Package.browse('Quilt/nice-name', registry='local') assert registry + '/.quilt/named_packages/Quilt/nice-name/latest' \ == dl_mock.call_args_list[0][0][0] assert '{}/.quilt/packages/{}'.format(registry, top_hash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() remote_registry = 's3://asdf/foo' # remote load pkg = Package.browse('Quilt/nice-name', registry=remote_registry, top_hash=top_hash) assert '{}/.quilt/packages/{}'.format(remote_registry, top_hash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() pkg = Package.browse(top_hash=top_hash, registry=remote_registry) assert '{}/.quilt/packages/{}'.format(remote_registry, top_hash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() with patch('t4.packages.get_bytes') as dl_mock: dl_mock.return_value = (top_hash.encode('utf-8'), None) pkg = Package.browse('Quilt/nice-name', registry=remote_registry) assert '{}/.quilt/packages/{}'.format(remote_registry, top_hash) \ in [x[0][0] for x in pkgmock.call_args_list] # default remote registry failure case with patch('t4.packages.get_from_config', return_value=None): with pytest.raises(QuiltException): Package.browse('Quilt/nice-name')
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)
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)
def test_top_hash_stable(): """Ensure that top_hash() never changes for a given manifest""" registry = Path(__file__).parent / 'data' pkg_hash = '20de5433549a4db332a11d8d64b934a82bdea8f144b4aecd901e7d4134f8e733' pkg = Package.browse(registry=registry, pkg_hash=pkg_hash) assert pkg.top_hash() == pkg_hash, \ "Unexpected top_hash for {}/.quilt/packages/{}".format(registry, pkg_hash)
def test_top_hash_stable(self): """Ensure that top_hash() never changes for a given manifest""" registry = DATA_DIR top_hash = '20de5433549a4db332a11d8d64b934a82bdea8f144b4aecd901e7d4134f8e733' pkg = Package.browse(registry=registry, top_hash=top_hash) assert pkg.top_hash == top_hash, \ "Unexpected top_hash for {}/.quilt/packages/{}".format(registry, top_hash)
def test_browse_package_from_registry(): """ Verify loading manifest locally and from s3 """ with patch('t4.Package._from_path') as pkgmock: registry = BASE_PATH.as_uri() pkg = Package() pkgmock.return_value = pkg pkghash = pkg.top_hash() # default registry load pkg = Package.browse(pkg_hash=pkghash) assert '{}/.quilt/packages/{}'.format(registry, pkghash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() pkg = Package.browse('Quilt/nice-name', pkg_hash=pkghash) assert '{}/.quilt/packages/{}'.format(registry, pkghash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() with patch('t4.packages.get_bytes') as dl_mock: dl_mock.return_value = (pkghash.encode('utf-8'), None) pkg = Package.browse('Quilt/nice-name') assert registry + '/.quilt/named_packages/Quilt/nice-name/latest' \ == dl_mock.call_args_list[0][0][0] assert '{}/.quilt/packages/{}'.format(registry, pkghash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() remote_registry = 's3://asdf/foo' # remote load pkg = Package.browse('Quilt/nice-name', registry=remote_registry, pkg_hash=pkghash) assert '{}/.quilt/packages/{}'.format(remote_registry, pkghash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() pkg = Package.browse(pkg_hash=pkghash, registry=remote_registry) assert '{}/.quilt/packages/{}'.format(remote_registry, pkghash) \ in [x[0][0] for x in pkgmock.call_args_list] pkgmock.reset_mock() with patch('t4.packages.get_bytes') as dl_mock: dl_mock.return_value = (pkghash.encode('utf-8'), None) pkg = Package.browse('Quilt/nice-name', registry=remote_registry) assert '{}/.quilt/packages/{}'.format(remote_registry, pkghash) \ in [x[0][0] for x in pkgmock.call_args_list]