def test_list_local_packages(tmpdir): """Verify that list returns packages in the appdirs directory.""" temp_local_registry = Path(os.path.join(tmpdir, 'test_registry')).as_uri() with patch('t4.packages.get_package_registry', lambda path: temp_local_registry), \ patch('t4.api.get_package_registry', lambda path: temp_local_registry): # Build a new package into the local registry. Package().build("Quilt/Foo") Package().build("Quilt/Bar") Package().build("Quilt/Test") # Verify packages are returned. pkgs = t4.list_packages() assert len(pkgs) == 3 assert "Quilt/Foo" in pkgs assert "Quilt/Bar" in pkgs # Test unnamed packages are not added. Package().build() pkgs = t4.list_packages() assert len(pkgs) == 3 # Verify manifest is registered by hash when local path given pkgs = t4.list_packages("/") assert "Quilt/Foo" in pkgs assert "Quilt/Bar" in pkgs
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_local_package_delete(tmpdir): """Verify local package delete works.""" top_hash = Package().build("Quilt/Test") t4.delete_package('Quilt/Test', registry=BASE_PATH) assert 'Quilt/Test' not in t4.list_packages() assert top_hash not in [ p.name for p in Path(BASE_PATH, '.quilt/packages').iterdir() ]
def test_local_package_delete_overlapping(tmpdir): """ Verify local package delete works when multiple packages reference the same tophash. """ top_hash = Package().build("Quilt/Test1") top_hash = Package().build("Quilt/Test2") t4.delete_package('Quilt/Test1', registry=BASE_PATH) assert 'Quilt/Test1' not in t4.list_packages() assert top_hash in [ p.name for p in Path(BASE_PATH, '.quilt/packages').iterdir() ] t4.delete_package('Quilt/Test2', registry=BASE_PATH) assert 'Quilt/Test2' not in t4.list_packages() assert top_hash not in [ p.name for p in Path(BASE_PATH, '.quilt/packages').iterdir() ]
def test_list_remote_packages(): with patch('t4.api.list_objects', return_value=([{ 'Prefix': 'foo' }, { 'Prefix': 'bar' }], [])) as mock: pkgs = t4.list_packages('s3://my_test_bucket/') assert mock.call_args_list[0][0] == ('my_test_bucket', '.quilt/named_packages/') assert True
def test_list_local_packages(self): """Verify that list returns packages in the appdirs directory.""" temp_local_registry = Path( 'test_registry').resolve().as_uri() + '/.quilt' with patch('t4.packages.get_package_registry', lambda path: temp_local_registry), \ patch('t4.api.get_package_registry', lambda path: temp_local_registry): # Build a new package into the local registry. Package().build("Quilt/Foo") Package().build("Quilt/Bar") Package().build("Quilt/Test") # Verify packages are returned. pkgs = t4.list_packages() assert len(pkgs) == 3 assert "Quilt/Foo" in pkgs assert "Quilt/Bar" in pkgs # Verify 'local' keyword works as expected. assert list(pkgs) == list(t4.list_packages('local')) # Verify specifying a local path explicitly works as expected. assert list(pkgs) == list( t4.list_packages( pathlib.Path(temp_local_registry).parent.as_posix())) # Verify package repr is as expected. pkgs_repr = str(pkgs) assert 'Quilt/Test:latest' in pkgs_repr assert 'Quilt/Foo:latest' in pkgs_repr assert 'Quilt/Bar:latest' in pkgs_repr # Test unnamed packages are not added. Package().build() pkgs = t4.list_packages() assert len(pkgs) == 3 # Verify manifest is registered by hash when local path given pkgs = t4.list_packages("/") assert "Quilt/Foo" in pkgs assert "Quilt/Bar" in pkgs
def test_list_remote_packages(self): """Verify that listing remote packages works as expected.""" def pseudo_list_objects(bucket, prefix, recursive): if prefix == '.quilt/named_packages/': return ([{'Prefix': '.quilt/named_packages/foo/'}], []) elif prefix == '.quilt/named_packages/foo/': return ([{'Prefix': '.quilt/named_packages/foo/bar/'}], []) elif prefix == '.quilt/named_packages/foo/bar/': import datetime return ([], [{ 'Key': '.quilt/named_packages/foo/bar/1549931300', 'LastModified': datetime.datetime.now() - datetime.timedelta(seconds=30) }, { 'Key': '.quilt/named_packages/foo/bar/1549931634', 'LastModified': datetime.datetime.now() }, { 'Key': '.quilt/named_packages/foo/bar/latest', 'LastModified': datetime.datetime.now() }]) else: raise ValueError def pseudo_get_bytes(src): if src.endswith('foo/bar/latest') or src.endswith( 'foo/bar/1549931634'): return (b'100', None) elif src.endswith('foo/bar/1549931300'): return (b'90', None) else: raise ValueError with patch('t4.api.list_objects', side_effect=pseudo_list_objects), \ patch('t4.api.get_bytes', side_effect=pseudo_get_bytes), \ patch('t4.Package.browse', return_value=Package()): pkgs = t4.list_packages('s3://my_test_bucket/') assert len(pkgs) == 1 assert list(pkgs) == ['foo/bar'] expected = ( 'PACKAGE \tTOP HASH \tCREATED \tSIZE \t\n' 'foo/bar:latest \t100 \tnow \t0 Bytes\t\n' 'foo/bar \t90 \t30 seconds ago \t0 Bytes\t\n' ) assert str(pkgs) == expected