def test_dir_meta(self): 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('Quilt/Test') assert pkg['asdf'].meta == {} assert pkg.meta == {} assert pkg['qwer']['as'].meta == {} pkg['asdf'].set_meta(test_meta) assert pkg['asdf'].meta == test_meta pkg['qwer']['as'].set_meta(test_meta) assert pkg['qwer']['as'].meta == test_meta pkg.set_meta(test_meta) assert pkg.meta == test_meta dump_path = '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'].meta == test_meta assert pkg2['qwer']['as'].meta == test_meta assert pkg2.meta == test_meta
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 = LOCAL_REGISTRY / ".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 = LOCAL_REGISTRY / ".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("Quilt/Test").top_hash out_path = LOCAL_REGISTRY / ".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]
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("Quilt/Test") 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]
def test_manifest(self): pkg = Package() pkg.set('as/df', LOCAL_MANIFEST) pkg.set('as/qw', LOCAL_MANIFEST) top_hash = pkg.build('foo/bar').top_hash manifest = list(pkg.manifest) pkg2 = Package.browse('foo/bar', top_hash=top_hash) assert list(pkg.manifest) == list(pkg2.manifest)
def test_verify(self): pkg = Package() pkg.set('foo', b'Hello, World!') pkg.build('quilt/test') Package.install('quilt/test', LOCAL_REGISTRY, dest='test') assert pkg.verify('test') Path('test/blah').write_text('123') assert not pkg.verify('test') assert pkg.verify('test', extra_files_ok=True) Path('test/foo').write_text('123') assert not pkg.verify('test') assert not pkg.verify('test', extra_files_ok=True) Path('test/foo').write_text('Hello, World!') Path('test/blah').unlink() assert pkg.verify('test')
def test_tophash_changes(self): test_file = Path('test.txt') test_file.write_text('asdf', 'utf-8') pkg = Package() th1 = pkg.top_hash pkg.set('asdf', test_file) pkg.build('foo/bar') th2 = pkg.top_hash assert th1 != th2 test_file.write_text('jkl', 'utf-8') pkg.set('jkl', test_file) pkg.build('foo/bar') th3 = pkg.top_hash assert th1 != th3 assert th2 != th3 pkg.delete('jkl') th4 = pkg.top_hash assert th2 == th4
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)
def test_rollback(self): p = Package() p.set('foo', DATA_DIR / 'foo.txt') p.build('quilt/tmp') good_hash = p.top_hash assert 'foo' in Package.browse('quilt/tmp') p.delete('foo') p.build('quilt/tmp') assert 'foo' not in Package.browse('quilt/tmp') Package.rollback('quilt/tmp', LOCAL_REGISTRY, good_hash) assert 'foo' in Package.browse('quilt/tmp') with self.assertRaises(QuiltException): Package.rollback('quilt/tmp', LOCAL_REGISTRY, '12345678' * 8) with self.assertRaises(QuiltException): Package.rollback('quilt/blah', LOCAL_REGISTRY, good_hash)
def test_diff(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") p1 = Package.browse('Quilt/Test') p2 = Package.browse('Quilt/Test') assert p1.diff(p2) == ([], [], [])
def upload_test_resources(args: Args): # Try running the download pipeline try: # Get test resources dir resources_dir = (Path(__file__).parent.parent / "aicsimageio" / "tests" / "resources").resolve(strict=True) # Report with directory will be used for upload log.info(f"Using contents of directory: {resources_dir}") # Create quilt package package = Package() package.set_dir("resources", resources_dir) # Report package contents log.info(f"Package contents: {package}") # Construct package name package_name = "aicsimageio/test_resources" # Check for dry run if args.dry_run: # Attempt to build the package built = package.build(package_name) # Get resolved save path manifest_save_path = Path("upload_manifest.jsonl").resolve() with open(manifest_save_path, "w") as manifest_write: package.dump(manifest_write) # Report where manifest was saved log.info( f"Dry run generated manifest stored to: {manifest_save_path}") log.info( f"Completed package dry run. Result hash: {built.top_hash}") # Upload else: # Check pre-approved push if args.preapproved: confirmation = True else: # Get upload confirmation confirmation = None while confirmation is None: # Get user input user_input = input("Upload [y]/n? ") # If the user simply pressed enter assume yes if len(user_input) == 0: user_input = "y" # Get first character and lowercase else: user_input = user_input[0].lower() # Set confirmation from None to a value if user_input == "y": confirmation = True elif user_input == "n": confirmation = False # Check confirmation if confirmation: pushed = package.push( package_name, "s3://aics-modeling-packages-test-resources", message= f"Test resources for `aicsimageio` version: {__version__}.", ) log.info( f"Completed package push. Result hash: {pushed.top_hash}") else: log.info(f"Upload canceled.") # Catch any exception except Exception as e: log.error("=============================================") if args.debug: log.error("\n\n" + traceback.format_exc()) log.error("=============================================") log.error("\n\n" + str(e) + "\n") log.error("=============================================") sys.exit(1)