def run_0launch(self, args): old_stdout = sys.stdout old_stderr = sys.stderr try: sys.stdout = StringIO() sys.stderr = StringIO() ex = None try: cli.main(args) print("Finished") except NameError: raise except SystemExit: pass except TypeError: raise except AttributeError: raise except AssertionError: raise except Exception as ex2: ex = ex2 # Python 3 out = sys.stdout.getvalue() err = sys.stderr.getvalue() if ex is not None: err += str(ex.__class__) finally: sys.stdout = old_stdout sys.stderr = old_stderr return (out, err)
def run_0launch(self, args): old_stdout = sys.stdout old_stderr = sys.stderr try: sys.stdout = StringIO() sys.stderr = StringIO() ex = None try: cli.main(args) print "Finished" except NameError: raise except SystemExit: pass except TypeError: raise except AttributeError: raise except AssertionError: raise except Exception, ex: pass out = sys.stdout.getvalue() err = sys.stderr.getvalue() if ex is not None: err += str(ex.__class__)
def testBadFD(self): copy = os.dup(1) try: os.close(1) cli.main(['--list', 'UNKNOWN']) finally: os.dup2(copy, 1)
def testSelections(self): from zeroinstall.injector import cli root = qdom.parse(file("selections.xml")) sels = selections.Selections(root) class Options: dry_run = False with output_suppressed(): self.child = server.handle_requests( 'Hello.xml', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B', 'HelloWorld.tgz') sys.stdin = Reply("Y\n") try: self.config.stores.lookup_any( sels.selections['http://example.com:8000/Hello.xml']. digests) assert False except NotStored: pass cli.main(['--download-only', 'selections.xml'], config=self.config) path = self.config.stores.lookup_any( sels.selections['http://example.com:8000/Hello.xml'].digests) assert os.path.exists(os.path.join(path, 'HelloWorld', 'main')) assert sels.download_missing(self.config) is None
def testSelectionsWithFeed(self): from zeroinstall.injector import cli root = qdom.parse(file("selections.xml")) sels = selections.Selections(root) with output_suppressed(): self.child = server.handle_requests( "Hello.xml", "6FCF121BE2390E0B.gpg", "/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B", "HelloWorld.tgz", ) sys.stdin = Reply("Y\n") self.config.handler.wait_for_blocker( self.config.fetcher.download_and_import_feed( "http://example.com:8000/Hello.xml", self.config.iface_cache ) ) cli.main(["--download-only", "selections.xml"], config=self.config) path = self.config.stores.lookup_any(sels.selections["http://example.com:8000/Hello.xml"].digests) assert os.path.exists(os.path.join(path, "HelloWorld", "main")) assert sels.download_missing(self.config) is None
def testSelections(self): from zeroinstall.injector import cli root = qdom.parse(file("selections.xml")) sels = selections.Selections(root) class Options: dry_run = False with output_suppressed(): self.child = server.handle_requests( "Hello.xml", "6FCF121BE2390E0B.gpg", "/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B", "HelloWorld.tgz", ) sys.stdin = Reply("Y\n") try: self.config.stores.lookup_any(sels.selections["http://example.com:8000/Hello.xml"].digests) assert False except NotStored: pass cli.main(["--download-only", "selections.xml"]) path = self.config.stores.lookup_any(sels.selections["http://example.com:8000/Hello.xml"].digests) assert os.path.exists(os.path.join(path, "HelloWorld", "main")) assert sels.download_missing(self.config) is None
def testSelectionsWithFeed(self): from zeroinstall.injector import cli root = qdom.parse(open("selections.xml")) sels = selections.Selections(root) with output_suppressed(): run_server('Hello.xml', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B', 'HelloWorld.tgz') sys.stdin = Reply("Y\n") tasks.wait_for_blocker(self.config.fetcher.download_and_import_feed('http://example.com:8000/Hello.xml', self.config.iface_cache)) cli.main(['--download-only', 'selections.xml'], config = self.config) path = self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests) assert os.path.exists(os.path.join(path, 'HelloWorld', 'main')) assert sels.download_missing(self.config) is None
def testSelections(self): from zeroinstall.injector import cli root = qdom.parse(open("selections.xml")) sels = selections.Selections(root) class Options: dry_run = False with output_suppressed(): run_server('Hello.xml', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B', 'HelloWorld.tgz') sys.stdin = Reply("Y\n") try: self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests) assert False except NotStored: pass cli.main(['--download-only', 'selections.xml'], config = self.config) path = self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests) assert os.path.exists(os.path.join(path, 'HelloWorld', 'main')) assert sels.download_missing(self.config) is None
def testImport(self): from zeroinstall.injector import cli rootLogger = getLogger() rootLogger.disabled = True try: try: cli.main(['--import', '-v', 'NO-SUCH-FILE'], config = self.config) assert 0 except model.SafeException as ex: assert 'NO-SUCH-FILE' in str(ex) finally: rootLogger.disabled = False rootLogger.setLevel(WARN) hello = self.config.iface_cache.get_feed('http://localhost:8000/Hello') self.assertEqual(None, hello) with output_suppressed(): run_server('6FCF121BE2390E0B.gpg') sys.stdin = Reply("Y\n") assert not trust.trust_db.is_trusted('DE937DD411906ACF7C263B396FCF121BE2390E0B') cli.main(['--import', 'Hello'], config = self.config) assert trust.trust_db.is_trusted('DE937DD411906ACF7C263B396FCF121BE2390E0B') # Check we imported the interface after trusting the key hello = self.config.iface_cache.get_feed('http://localhost:8000/Hello', force = True) self.assertEqual(1, len(hello.implementations)) self.assertEqual(None, hello.local_path) # Shouldn't need to prompt the second time sys.stdin = None cli.main(['--import', 'Hello'], config = self.config)
def testImport(self): from zeroinstall.injector import cli rootLogger = getLogger() rootLogger.disabled = True try: try: cli.main(["--import", "-v", "NO-SUCH-FILE"]) assert 0 except model.SafeException, ex: assert "NO-SUCH-FILE" in str(ex) finally: rootLogger.disabled = False rootLogger.setLevel(WARN) hello = self.config.iface_cache.get_feed("http://localhost:8000/Hello") self.assertEquals(None, hello) with output_suppressed(): self.child = server.handle_requests("6FCF121BE2390E0B.gpg") sys.stdin = Reply("Y\n") assert not trust.trust_db.is_trusted("DE937DD411906ACF7C263B396FCF121BE2390E0B") cli.main(["--import", "Hello"]) assert trust.trust_db.is_trusted("DE937DD411906ACF7C263B396FCF121BE2390E0B") # Check we imported the interface after trusting the key hello = self.config.iface_cache.get_feed("http://localhost:8000/Hello", force=True) self.assertEquals(1, len(hello.implementations)) # Shouldn't need to prompt the second time sys.stdin = None cli.main(["--import", "Hello"])
def testSelectionsWithFeed(self): from zeroinstall.injector import cli root = qdom.parse(file("selections.xml")) sels = selections.Selections(root) with output_suppressed(): self.child = server.handle_requests( 'Hello.xml', '6FCF121BE2390E0B.gpg', '/key-info/key/DE937DD411906ACF7C263B396FCF121BE2390E0B', 'HelloWorld.tgz') sys.stdin = Reply("Y\n") self.config.handler.wait_for_blocker( self.config.fetcher.download_and_import_feed( 'http://example.com:8000/Hello.xml', self.config.iface_cache)) cli.main(['--download-only', 'selections.xml'], config=self.config) path = self.config.stores.lookup_any( sels.selections['http://example.com:8000/Hello.xml'].digests) assert os.path.exists(os.path.join(path, 'HelloWorld', 'main')) assert sels.download_missing(self.config) is None
def run(argv): # Break up the argument list on ';' boundaries and un-quote # escaped semicolons commands = [[]] for a in argv: if a == ';': commands.append([]) else: if a == r'\;': a = ';' commands[-1].append(a) # Because 0launch doesn't return, we need to invoke all but the # last one from a subprocess for c in commands[:-1]: p = Process(target = cli.main, args=(c,)) p.start() p.join() if p.exitcode: exit(p.exitcode) # The last one can be launched directly; we don't need control later. cli.main(commands[-1])
def testImport(self): from zeroinstall.injector import cli rootLogger = getLogger() rootLogger.disabled = True try: try: cli.main(['--import', '-v', 'NO-SUCH-FILE'], config=self.config) assert 0 except model.SafeException as ex: assert 'NO-SUCH-FILE' in str(ex) finally: rootLogger.disabled = False rootLogger.setLevel(WARN) hello = self.config.iface_cache.get_feed('http://localhost:8000/Hello') self.assertEqual(None, hello) with output_suppressed(): run_server('6FCF121BE2390E0B.gpg') sys.stdin = Reply("Y\n") assert not trust.trust_db.is_trusted( 'DE937DD411906ACF7C263B396FCF121BE2390E0B') cli.main(['--import', 'Hello'], config=self.config) assert trust.trust_db.is_trusted( 'DE937DD411906ACF7C263B396FCF121BE2390E0B') # Check we imported the interface after trusting the key hello = self.config.iface_cache.get_feed( 'http://localhost:8000/Hello', force=True) self.assertEqual(1, len(hello.implementations)) self.assertEqual(None, hello.local_path) # Shouldn't need to prompt the second time sys.stdin = None cli.main(['--import', 'Hello'], config=self.config)