def test_write_read_remote_1(): out = StringIO() r0 = Remote('remote') r0.write(out) out.seek(0) r1 = Remote.read(out) assert r0 == r1
def test_remote_generate_uploaders_skip(): mock = Mock() with patch('owmeta_core.bundle.UPLOADER_CLASSES', [mock]): r0 = Remote('remote') r0.add_config(URLConfig('http://example.org/bundle_remote0')) for ul in r0.generate_uploaders(): pass mock.can_upload_to.assert_called()
def test_get_http_url_loaders(): ''' Find loaders for HTTP URLs ''' load_entry_point_loaders() r0 = Remote('remote') r0.add_config(URLConfig('http://example.org/bundle_remote0')) for l in r0.generate_loaders(): if isinstance(l, HTTPBundleLoader): return raise AssertionError('No HTTPBundleLoader was created')
def test_remote_bundle(pytester): # Set up a remote remote = Remote( 'test', (FileURLConfig(f'file://{pytester.path}/remote-bundles'), )) sio = StringIO() remote.write(sio) pytester.makefile('.remote', test=sio.getvalue()) # Set up the test that will be run pytester.copy_example('bundle_remote_test.py') # Copy the bundle(s) we use in the test shutil.copytree(Path(CWD, 'bundles'), Path(pytester.path, 'remote-bundles')) # Run the test, asserting that one test passes and none fail (implicit) pytester.runpytest().assert_outcomes(passed=1)
def test_write_read_remote_2(): out = StringIO() r0 = Remote('remote') r0.add_config(URLConfig('http://example.org/bundle_remote0')) r0.add_config(URLConfig('http://example.org/bundle_remote1')) r0.write(out) out.seek(0) r1 = Remote.read(out) assert r0 == r1
def test_deploy_archive_no_manifest_not_a_bundle(tempdir): ''' Test missing manifest ''' bundle_path = p(tempdir, 'bundle.tar.xz') with tarfile.open(bundle_path, 'w:xz') as tf: pass rem = Remote('remote') cut = Deployer() with raises(NotABundlePath): cut.deploy(bundle_path, remotes=(rem, ))
def test_deploy_archive_manifest_emptyfile_not_a_bundle(tempdir): ''' Test manifest empty/malformed ''' bundle_path = p(tempdir, 'bundle.tar.xz') with tarfile.open(bundle_path, 'w:xz') as tf: tinfo = tarfile.TarInfo('manifest') tf.addfile(tinfo) rem = Remote('remote') cut = Deployer() with raises(NotABundlePath): cut.deploy(bundle_path, remotes=(rem, ))
def test_deploy_archive_manifest_isdir_not_a_bundle(tempdir): ''' Test missing manifest ''' bundle_path = p(tempdir, 'bundle.tar.xz') with tarfile.open(bundle_path, 'w:xz') as tf: tinfo = tarfile.TarInfo('manifest') tinfo.type = tarfile.DIRTYPE tf.addfile(tinfo) rem = Remote('remote') cut = Deployer() with raises(NotABundlePath): cut.deploy(bundle_path, remotes=(rem, ))
def core_bundle(request): CoreBundle = namedtuple('CoreBundle', ('id', 'version', 'source_directory', 'remote')) version_mark = request.node.get_closest_marker('core_bundle_version') if not version_mark: raise Exception('Must specify a version of the core bundle') version = version_mark.args[0] source_directory = find_bundle_directory('bundles', 'openworm/owmeta-core', version) class TestAC(AccessorConfig): def __eq__(self, other): return other is self def __hash__(self): return object.__hash__(self) class TestBundleLoader(Loader): def __init__(self, ac): pass def bundle_versions(self): return [1] @classmethod def can_load_from(cls, ac): if isinstance(ac, TestAC): return True return False def can_load(self, ident, version): return True def load(self, ident, version): shutil.copytree(source_directory, self.base_directory) TestBundleLoader.register() remote = Remote('test', (TestAC(), )) yield CoreBundle('openworm/owmeta-core', version, source_directory, remote)
def test_remote_str_no_configs(): s = str(Remote('test')) assert '<none>' in s assert 'test' in s
def test_remote_inequality_by_name(): uc = URLConfig('http://example.org/bluh') cut1 = Remote('test1', (uc, )) cut2 = Remote('test2', (uc, )) assert cut1 != cut2
def test_remote_inequality_by_accessors(): uc = URLConfig('http://example.org/bluh') cut1 = Remote('test', (uc, )) cut2 = Remote('test', ()) assert cut1 != cut2
def test_remote_equality(): uc = URLConfig('http://example.org/bluh') cut1 = Remote('test', (uc, )) cut2 = Remote('test', (uc, )) assert cut1 == cut2
def test_remote_add_config_no_dupe(): uc = URLConfig('http://example.org/bluh') cut = Remote('test', (uc, )) cut.add_config(uc) assert len(cut.accessor_configs) == 1
def test_remote_repr(): r = repr(Remote('test')) assert repr([]) in r assert repr('test') in r
def bundle(request): # Raises a BundleNotFound exception if the bundle can't be found nonlocal version, bundle_id if bundle_id is None and version is None: try: bundle_id, version = request.param except AttributeError as e: raise Exception('Use the bundles decorator to declare bundle' ' versions for this test') from e elif version is None: try: version = request.param except AttributeError as e: raise Exception( 'Use the bundle_versions decorator to declare bundle' ' versions for this test') from e TestBundleLoader = None try: source_directory = find_bundle_directory(TEST_BUNDLES_DIRECTORY, bundle_id, version) except BundleNotFound: marker = request.node.get_closest_marker("bundle_remote") test_bundles_remote = marker.args[0] if marker else None if not test_bundles_remote: raise try: with open(test_bundles_remote) as inp: remote = Remote.read(inp) except FileNotFoundError: remote = retrieve_remote_by_name(p(DEFAULT_OWM_DIR, 'remotes'), test_bundles_remote) if remote is None: raise source_directory = None else: class TestAC(AccessorConfig): def __eq__(self, other): return other is self def __hash__(self): return object.__hash__(self) class TestBundleLoader(Loader): def __init__(self, ac): pass def bundle_versions(self): return [version] @classmethod def can_load_from(cls, ac): if isinstance(ac, TestAC): return True return False def can_load(self, ident, version): return True def load(self, ident, version): shutil.copytree(source_directory, self.base_directory) TestBundleLoader.register() remote = Remote(f'test_{request.fixturename}', (TestAC(), )) yield BundleData(bundle_id, version, source_directory, remote) if TestBundleLoader: TestBundleLoader.unregister()