本文整理汇总了Python中twisted.scripts.trial._makeRunner函数的典型用法代码示例。如果您正苦于以下问题:Python _makeRunner函数的具体用法?Python _makeRunner怎么用?Python _makeRunner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_makeRunner函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeRunner
def makeRunner(self):
"""
Return a L{runner.TrialRunner} object that is safe to use in tests.
"""
runner = trial._makeRunner(self.config)
runner.stream = StringIO.StringIO()
return runner
示例2: call_trial
def call_trial(*tests):
import spyne.test
from glob import glob
from itertools import chain
global _ctr
_ctr += 1
file_name = 'test_result.%d.subunit' % _ctr
with SubUnitTee(file_name):
tests_dir = os.path.dirname(spyne.test.__file__)
sys.argv = ['trial', '--reporter=subunit']
sys.argv.extend(chain(*[glob(join(tests_dir, test)) for test in tests]))
from twisted.scripts.trial import Options
from twisted.scripts.trial import _makeRunner
from twisted.scripts.trial import _getSuite
config = Options()
config.parseOptions()
trialRunner = _makeRunner(config)
suite = _getSuite(config)
test_result = trialRunner.run(suite)
try:
subunit2junitxml(_ctr)
except Exception as e:
# this is not super important.
print e
return int(not test_result.wasSuccessful())
示例3: test_exitfirst
def test_exitfirst(self):
"""
Passing C{--exitfirst} wraps the reporter with a
L{reporter._ExitWrapper} that stops on any non-success.
"""
self.options.parseOptions(["--exitfirst"])
runner = trial._makeRunner(self.options)
self.assertTrue(runner._exitFirst)
示例4: run
def run():
config = Options()
config.parseOptions()
trialRunner = _makeRunner(config)
suite = _getSuite(config)
test_result = trialRunner.run(suite)
return int(not test_result.wasSuccessful())
示例5: test_dryRunWithJobs
def test_dryRunWithJobs(self):
"""
L{_makeRunner} returns a L{TrialRunner} instance in C{DRY_RUN} mode
when the C{--dry-run} option is passed, even if C{--jobs} is set.
"""
self.options.parseOptions(["--jobs", "4", "--dry-run"])
runner = trial._makeRunner(self.options)
self.assertIsInstance(runner, TrialRunner)
self.assertEqual(TrialRunner.DRY_RUN, runner.mode)
示例6: test_jobs
def test_jobs(self):
"""
L{_makeRunner} returns a L{DistTrialRunner} instance when the C{--jobs}
option is passed, and passes the C{workerNumber} and C{workerArguments}
parameters to it.
"""
self.options.parseOptions(["--jobs", "4", "--force-gc"])
runner = trial._makeRunner(self.options)
self.assertIsInstance(runner, DistTrialRunner)
self.assertEqual(4, runner._workerNumber)
self.assertEqual(["--force-gc"], runner._workerArguments)
示例7: getRunner
def getRunner(self):
r = trial._makeRunner(self.config)
r.stream = NativeStringIO()
# XXX The runner should always take care of cleaning this up itself.
# It's not clear why this is necessary. The runner always tears down
# its log file.
self.addCleanup(r._tearDownLogFile)
# XXX The runner should always take care of cleaning this up itself as
# well. It's necessary because TrialRunner._setUpTestdir might raise
# an exception preventing Reporter.done from being run, leaving the
# observer added by Reporter.__init__ still present in the system.
# Something better needs to happen inside
# TrialRunner._runWithoutDecoration to remove the need for this cludge.
r._log = log.LogPublisher()
return r
示例8: test_basic_test
def test_basic_test(self):
pkgname='fakepackage4'
modname='fakemodule4'
modcontents='\n\
def foofunc():\n\
x=1\n\
y=x\n\
'
testcontents='\n\
from twisted.trial import unittest\n\
from %s import %s\n\
class T(unittest.TestCase):\n\
def test_thing(self):\n\
%s.foofunc()\n\
' % (pkgname, modname, modname)
mockstdout = Mock()
realstdout=sys.stdout
sys.stdout = mockstdout
mockstderr = Mock()
realstderr=sys.stderr
sys.stderr = mockstderr
something = None
try:
fileutil.make_dirs(pkgname)
fileutil.write_file(os.path.join(pkgname, '__init__.py'), '')
fileutil.write_file(os.path.join(pkgname, modname+'.py'), modcontents)
fileutil.make_dirs(os.path.join(pkgname, 'test'))
fileutil.write_file(os.path.join(pkgname, 'test', '__init__.py'), '')
fileutil.write_file(os.path.join(pkgname, 'test', 'test_'+modname+'.py'), testcontents)
sys.path.append(os.getcwd())
trialcoverage.init_paths()
trialcoverage.start_coverage()
config = trial.Options()
config.parseOptions(['--reporter', 'bwverbose-coverage', '%s.test' % pkgname])
trial._initialDebugSetup(config)
trialRunner = trial._makeRunner(config)
suite = trial._getSuite(config)
something = trialRunner.run(suite)
finally:
sys.stdout = realstdout
sys.stderr = realstderr
if sys.modules.has_key(pkgname):
del sys.modules[pkgname]
fileutil.rm_dir(pkgname)
示例9: run_tests
def run_tests(self):
# We do the import from Twisted inside the function instead of the top
# of the file because since Twisted is a setup_requires, we can't
# assume that Twisted will be installed on the user's system prior, so
# if we don't do the import here, then importing from this plugin will
# fail.
from twisted.scripts import trial
if not self.testmodule:
self.testmodule = "bridgedb.test"
# Handle parsing the trial options passed through the setuptools
# trial command.
cmd_options = []
for opt in self.boolean_options:
if getattr(self, opt.replace('-', '_'), None):
cmd_options.append('--%s' % opt)
for opt in ('debugger', 'jobs', 'random', 'reactor', 'reporter',
'testmodule', 'tbformat', 'without-module'):
value = getattr(self, opt.replace('-', '_'), None)
if value is not None:
cmd_options.extend(['--%s' % opt, value])
config = trial.Options()
config.parseOptions(cmd_options)
config['tests'] = [self.testmodule,]
trial._initialDebugSetup(config)
trialRunner = trial._makeRunner(config)
suite = trial._getSuite(config)
# run the tests
if self.until_failure:
test_result = trialRunner.runUntilFailure(suite)
else:
test_result = trialRunner.run(suite)
if test_result.wasSuccessful():
return 0 # success
return 1 # failure
示例10: len
r = datastore.Redis.instance()
r.flushdb()
else:
from nova.tests.real_flags import *
if len(argv) == 1 and len(config['tests']) == 0:
# If no tests were specified run the ones imported in this file
# NOTE(termie): "tests" is not a flag, just some Trial related stuff
config['tests'].update(['__main__'])
elif len(config['tests']):
# If we specified tests check first whether they are in __main__
for arg in config['tests']:
key = arg.split('.')[0]
if hasattr(__main__, key):
config['tests'].remove(arg)
config['tests'].add('__main__.%s' % arg)
trial_script._initialDebugSetup(config)
trialRunner = trial_script._makeRunner(config)
suite = trial_script._getSuite(config)
if config['until-failure']:
test_result = trialRunner.runUntilFailure(suite)
else:
test_result = trialRunner.run(suite)
if config.tracer:
sys.settrace(None)
results = config.tracer.results()
results.write_results(show_missing=1, summary=False,
coverdir=config.coverdir)
sys.exit(not test_result.wasSuccessful())
示例11: getRunner
def getRunner(self):
r = trial._makeRunner(self.config)
self.runners.append(r)
return r
示例12: run_tests
def run_tests(self):
global all_modules
all_modules = self.distribution.get_command_obj(
'build_py').find_all_modules()
# We do the import from Twisted inside the function instead of the top
# of the file because since Twisted is a setup_requires, we can't
# assume that Twisted will be installed on the user's system prior
# to using Tahoe, so if we don't do the import here, then importing
# from this plugin will fail.
from twisted.scripts import trial
# Handle parsing the trial options passed through the setuptools
# trial command.
cmd_options = []
if self.reactor is not None:
cmd_options.extend(['--reactor', self.reactor])
else:
# Cygwin requires the poll reactor to work at all. Linux
# requires the poll reactor to avoid twisted bug #3218.
# In general, the poll reactor is better than the select reactor,
# but it is not available on all platforms. According to
# exarkun on IRC, it is available but buggy on some versions of
# Mac OS X, so just because you can install it doesn't mean we
# want to use it on every platform.
# Unfortunately this leads to this error with some
# combinations of tools:
# twisted.python.usage.UsageError: The specified reactor cannot be
# used, failed with error: reactor already installed.
if sys.platform in ("cygwin"):
cmd_options.extend(['--reactor', 'poll'])
if self.reporter is not None:
cmd_options.extend(['--reporter', self.reporter])
if self.rterrors is not None:
cmd_options.append('--rterrors')
if self.debug_stacktraces is not None:
cmd_options.append('--debug-stacktraces')
config = trial.Options()
config.parseOptions(cmd_options)
args = self.test_args
if type(args) == str:
args = [args, ]
config['tests'] = args
if self.coverage:
config.opt_coverage()
trial._initialDebugSetup(config)
trialRunner = trial._makeRunner(config)
suite = trial._getSuite(config)
# run the tests
if self.until_failure:
test_result = trialRunner.runUntilFailure(suite)
else:
test_result = trialRunner.run(suite)
# write coverage data
if config.tracer:
sys.settrace(None)
results = config.tracer.results()
results.write_results(show_missing=1, summary=False,
coverdir=config.coverdir)
if test_result.wasSuccessful():
sys.exit(0) # success
else:
sys.exit(1) # failure
示例13: getRunner
def getRunner(self):
r = trial._makeRunner(self.config)
r.stream = StringIO.StringIO()
self.addCleanup(r._tearDownLogFile)
return r
示例14: main
def main():
always_succeed = '--always-succeed' in sys.argv
if always_succeed:
sys.argv.remove('--always-succeed')
# Copypasta from twisted.scripts.trial.run, to tweak the return values
if len(sys.argv) == 1:
sys.argv.append("--help")
config = trial.Options()
try:
config.parseOptions()
except usage.error, ue:
raise SystemExit, "%s: %s" % (sys.argv[0], ue)
trial._initialDebugSetup(config)
trialRunner = trial._makeRunner(config)
suite = trial._getSuite(config)
if config['until-failure']:
test_result = trialRunner.runUntilFailure(suite)
else:
test_result = trialRunner.run(suite)
if config.tracer:
sys.settrace(None)
results = config.tracer.results()
results.write_results(show_missing=1, summary=False,
coverdir=config.coverdir)
# Copypasta ends here
if always_succeed or test_result.wasSuccessful():
return 0
else:
return 2