def test_fetch_default_dest(tmpdir): """Verify fetching a package entry to a default destination.""" with patch('quilt3.packages.copy_file') as copy_mock: (Package() .set('foo', os.path.join(os.path.dirname(__file__), 'data', 'foo.txt'))['foo'] .fetch()) filepath = fix_url(os.path.join(os.path.dirname(__file__), 'data', 'foo.txt')) copy_mock.assert_called_once_with(filepath, ANY)
def get_package_registry(path=None) -> PackageRegistry: """ Returns the package registry for a given path """ # TODO: Don't check if it's PackageRegistry? Then we need better separation # to external functions that receive string and internal that receive # PackageRegistry. if isinstance(path, PackageRegistry): return path if not isinstance(path, PhysicalKey): path = PhysicalKey.from_url( get_from_config('default_local_registry') if path is None else fix_url(path) ) return (LocalPackageRegistryV1 if path.is_local() else S3PackageRegistryV1)(path)
def test_browse_package_from_registry(self): """ Verify loading manifest locally and from s3 """ with patch('quilt3.Package._from_path') as pkgmock: registry = LOCAL_REGISTRY.resolve().as_uri() pkg = Package() pkgmock.return_value = pkg top_hash = pkg.top_hash pkg = Package.browse('Quilt/nice-name', 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('quilt3.packages.get_bytes') as dl_mock: dl_mock.return_value = (top_hash.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, 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('Quilt/nice-name', 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('quilt3.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] # registry failure case with patch('quilt3.packages.get_from_config', return_value=fix_url(os.path.dirname(__file__))): with pytest.raises(FileNotFoundError): Package.browse('Quilt/nice-name')
def test_remote_install(self): """Verify that installing from a local package works as expected.""" remote_registry = Path('.').resolve().as_uri() quilt3.config(default_local_registry=remote_registry, default_remote_registry=remote_registry) with patch('quilt3.Package.push') as push_mock: pkg = Package() pkg.build('Quilt/nice-name') with patch('quilt3.Package._materialize') as materialize_mock, \ patch('quilt3.Package.build') as build_mock: materialize_mock.return_value = pkg dest_registry = quilt3.util.get_from_config( 'default_local_registry') quilt3.Package.install('Quilt/nice-name', dest='./') materialize_mock.assert_called_once_with(fix_url('./')) build_mock.assert_called_once_with('Quilt/nice-name', message=None, registry=dest_registry)