def test(so, stdout, stderr): petmail = os.path.abspath(sys.argv[0]) petmail_executable.append(petmail) # to run bin/petmail in a subprocess from twisted.scripts import trial as twisted_trial sys.argv = ["trial"] + so.test_args twisted_trial.run() # this does not return sys.exit(0) # just in case
def run(): "Run the Ibid test suite. Bit of a hack" from twisted.scripts.trial import run import sys sys.argv.append("ibid") run()
def main(): trial_class = 'c2w.test.protocol.udp_client_test.c2wUdpChatClientTestCase' parser = argparse.ArgumentParser(description='Trial udp client test', formatter_class=SmartFormatter) with open(os.path.join(stockrsm_path, "data", "c2w", "test", "udp_client_tests_list.txt")) as tests_list: tests = list(l.rstrip('\n') for l in tests_list.readlines()) if not tests: print("Sorry, no test available for the moment") exit() # stupid hack for [""] + tests for getting the alignment of values. To be modified. parser.add_argument("--scenario", help='''R|Scenario name. Allowed values are ''' + '\n'.join([""] + tests,)).completer=ChoicesCompleter(tuple(tests)) argcomplete.autocomplete(parser) options = parser.parse_args() cmdLine = ['trial', trial_class + ".test_" + options.scenario] os.environ['STOCKRSMPATH'] = stockrsm_path del sys.argv[-1] del sys.argv[-1] sys.argv.append(trial_class + ".test_" + options.scenario) sys.path.insert(0, os.path.abspath(os.getcwd())) from twisted.scripts.trial import run run()
def runTrial(options): """Run Twisted trial based unittests, optionally with coverage. :type options: :class:`~bridgedb.opt.TestOptions` :param options: Parsed options for controlling the twisted.trial test run. All unrecognised arguments after the known options will be passed along to trial. """ from twisted.scripts import trial # Insert 'trial' as the first system cmdline argument: sys.argv = ['trial'] if options['coverage']: try: from coverage import coverage except ImportError as ie: print(ie.message) else: cov = coverage() cov.start() sys.argv.append('--coverage') sys.argv.append('--reporter=bwverbose') # Pass all arguments along to its options parser: if 'test_args' in options: for arg in options['test_args']: sys.argv.append(arg) # Tell trial to test the bridgedb package: sys.argv.append('bridgedb.test') trial.run() if options['coverage']: cov.stop() cov.html_report('_trial_temp/coverage/')
def main(): # init test cases if len(sys.argv)>1: test_case = ".".join([__file__.split('.')[0], sys.argv[1]]) else: test_case = __file__.split('.')[0] # launch trial sys.argv = [sys.argv[0], test_case] trial.run()
def main(): trial_class = 'sibyl.test.sibyl_server_test.SibylServerTestCase' cmdLine = ['trial', trial_class + '.test_sibyl_framing'] os.environ['STOCKRSMPATH'] = stockrsm_path sys.argv.append(trial_class + '.test_sibyl_framing') sys.path.insert(0, os.path.abspath(os.getcwd())) from twisted.scripts.trial import run run()
def trial(config): sys.argv = ['trial'] + config.trial_args from allmydata._version import full_version if full_version.endswith("-dirty"): print >>sys.stderr print >>sys.stderr, "WARNING: the source tree has been modified since the last commit." print >>sys.stderr, "(It is usually preferable to commit, then test, then amend the commit(s)" print >>sys.stderr, "if the tests fail.)" print >>sys.stderr # This does not return. twisted_trial.run()
def test_debuggerNotFound(self): """ When a debugger is not found, an error message is printed to the user. """ def _makeRunner(*args, **kwargs): raise trial._DebuggerNotFound('foo') self.patch(trial, "_makeRunner", _makeRunner) try: trial.run() except SystemExit as e: self.assertIn("foo", str(e)) else: self.fail("Should have exited due to non-existent debugger!")
def _run(self, test_loc): """ Executes the test step. @param test_loc: location of test module @type test_loc: str """ from twisted.scripts.trial import run # remove the 'test' option from argv sys.argv.remove('test') # Mimick the trial script by adding the path as the last arg sys.argv.append(test_loc) # Add the current dir to path and pull it all together sys.path.insert(0, os.path.curdir) sys.path[:] = map(os.path.abspath, sys.path) # GO! run()
def egg_test_runner(): """ Test collector and runner for setup.py test """ from twisted.scripts.trial import run original_args = list(sys.argv) sys.argv = ["", "resilience"] try: return run() finally: sys.argv = original_args
def _run(self, test_loc): """ Executes the test step. @param test_loc: location of test module @type test_loc: str """ from twisted.scripts.trial import run # Mimick the trial script by adding the path as the last arg sys.argv.append(test_loc) # No superuser should execute tests if hasattr(os, "getuid") and os.getuid() == 0: raise SystemExit('Do not test as a superuser! Exiting ...') # Add the current dir to path and pull it all together sys.path.insert(0, os.path.curdir) sys.path[:] = map(os.path.abspath, sys.path) # GO! run()
def run_trial(): from twisted.python import modules # We monkey patch PythonModule in order to avoid tests inside namespace packages # being run multiple times (see http://twistedmatrix.com/trac/ticket/5030) PythonModule = modules.PythonModule class PatchedPythonModule(PythonModule): def walkModules(self, *a, **kw): yielded = set() # calling super on PythonModule instead of PatchedPythonModule, since we're monkey patching PythonModule for module in super(PythonModule, self).walkModules(*a, **kw): if module.name in yielded: continue yielded.add(module.name) yield module modules.PythonModule = PatchedPythonModule from twisted.scripts.trial import run run()
def trial(config): sys.argv = ['trial'] + config.trial_args # This does not return. twisted_trial.run()
# -*- coding: utf-8 -*- import re import sys from twisted.scripts.trial import run if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(run())
def run(self): import sys from twisted.scripts import trial sys.argv = ["trial", "--rterrors", "foolscap.test"] trial.run() # does not return
def run(): "Run the Ibid test suite. Bit of a hack" from twisted.scripts.trial import run import sys sys.argv.append('ibid') run()
from twisted.scripts import trial with open(".py3.notworking.txt", "r") as f: not_working_list = f.read().splitlines() # Get a list of all the tests by using "trial -n" trial_output = subprocess.check_output( "trial -n --reporter=bwverbose buildbot.test | " "awk '/OK/ {print $1}'", shell=True) trial_output = trial_output.decode("utf-8") tests = trial_output.splitlines() # Filter out the tests which are not working for test in not_working_list: try: tests.remove(test) except ValueError as e: print("FAILED TO REMOVE ", test, type(test)) print("\n\nRunning tests with:\n\n", sys.version, "\n\n") # Run the tests. To avoid "Argument list too long" # errors, invoke twisted.scripts.trial.run() directly # instead of invoking the trial script. sys.argv[0] = "trial" sys.argv.append("--reporter=bwverbose") sys.argv += tests sys.exit(trial.run())
def test(so, stdout, stderr): from twisted.scripts import trial sys.argv = ["trial"] + list(so.test_args) trial.run() sys.exit(0) # just in case
def run(self): import sys from twisted.scripts import trial sys.argv = ['trial', '--rterrors', 'foolscap.test'] trial.run() # does not return
ack=False)) # we're acking the frames ourselves yield self._got_message disconnected = client.disconnected client.send('/queue/fake', b'shutdown') # tell the broker to drop the connection try: yield disconnected except StompConnectionError: pass else: raise Exception( 'Expected unexpected loss of connection, but disconnect went gracefully.' ) self.wait.callback(None) @defer.inlineCallbacks def _on_message(self, client, msg): client.nack(msg) self.wait = defer.Deferred() self._got_message.callback(None) yield self.wait if __name__ == '__main__': import sys from twisted.scripts import trial sys.argv.extend([sys.argv[0]]) trial.run()
@defer.inlineCallbacks def test_outbind(self): client = SMPPClientReceiver(self.config, self.msgHandler) smpp = yield client.connect() yield smpp.getDisconnectedDeferred() class SMPPClientServiceBindTimeoutTestCase(SimulatorTestCase): configArgs = { 'sessionInitTimerSecs': 0.1, } def test_bind_transmitter_timeout(self): client = SMPPClientTransmitter(self.config) svc = SMPPClientService(client) stopDeferred = svc.getStopDeferred() startDeferred = svc.startService() return defer.DeferredList([ self.assertFailure(startDeferred, SMPPSessionInitTimoutError), self.assertFailure(stopDeferred, SMPPSessionInitTimoutError), ]) if __name__ == '__main__': observer = log.PythonLoggingObserver() observer.start() logging.basicConfig(level=logging.DEBUG) import sys from twisted.scripts import trial sys.argv.extend([sys.argv[0]]) trial.run()
def buttonClick(self): if not self.running: from twisted.scripts import trial trial.run()
def button_click(self): if not self.running: from twisted.scripts import trial trial.run()
# This is a tiny helper module, to let "python -m allmydata.test.run_trial # ARGS" does the same thing as running "trial ARGS" (unfortunately # twisted/scripts/trial.py does not have a '__name__=="__main__"' clause). # # This makes it easier to run trial under coverage from tox: # * "coverage run trial ARGS" is how you'd usually do it # * but "trial" must be the one in tox's virtualenv # * "coverage run `which trial` ARGS" works from a shell # * but tox doesn't use a shell # So use: # "coverage run -m allmydata.test.run_trial ARGS" from twisted.scripts.trial import run run()