本文整理汇总了Python中nose.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autohelp_directive
def autohelp_directive(dirname, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
"""produces rst from nose help"""
config = Config(parserClass=OptBucket,
plugins=BuiltinPluginManager())
parser = config.getParser(TestProgram.usage())
rst = ViewList()
for line in parser.format_help().split('\n'):
rst.append(line, '<autodoc>')
rst.append('Options', '<autodoc>')
rst.append('-------', '<autodoc>')
rst.append('', '<autodoc>')
for opt in parser:
rst.append(opt.options(), '<autodoc>')
rst.append(' \n', '<autodoc>')
rst.append(' ' + opt.help + '\n', '<autodoc>')
rst.append('\n', '<autodoc>')
node = nodes.section()
node.document = state.document
surrounding_title_styles = state.memo.title_styles
surrounding_section_level = state.memo.section_level
state.memo.title_styles = []
state.memo.section_level = 0
state.nested_parse(rst, 0, node, match_titles=1)
state.memo.title_styles = surrounding_title_styles
state.memo.section_level = surrounding_section_level
return node.children
示例2: run
def run(*arg, **kw):
"""
Specialized version of nose.run for use inside of doctests that
test test runs.
This version of run() prints the result output to stdout. Before
printing, the output is processed by replacing the timing
information with an ellipsis (...), removing traceback stacks, and
removing trailing whitespace.
Use this version of run wherever you are writing a doctest that
tests nose (or unittest) test result output.
Note: do not use doctest: +ELLIPSIS when testing nose output,
since ellipses ("test_foo ... ok") in your expected test runner
output may match multiple lines of output, causing spurious test
passes!
"""
from nose import run
from nose.config import Config
from nose.plugins.manager import PluginManager
buffer = StringIO()
if 'config' not in kw:
plugins = kw.pop('plugins', None)
env = kw.pop('env', {})
kw['config'] = Config(env=env, plugins=PluginManager(plugins=plugins))
if 'argv' not in kw:
kw['argv'] = ['nosetests', '-v']
kw['config'].stream = buffer
run(*arg, **kw)
out = buffer.getvalue()
print munge_nose_output_for_doctest(out)
示例3: collector
def collector():
"""TestSuite replacement entry point. Use anywhere you might use a
unittest.TestSuite. The collector will, by default, load options from
all config files and execute loader.loadTestsFromNames() on the
configured testNames, or '.' if no testNames are configured.
"""
# plugins that implement any of these methods are disabled, since
# we don't control the test runner and won't be able to run them
# finalize() is also not called, but plugins that use it aren't disabled,
# because capture needs it.
setuptools_incompat = ('report', 'prepareTest',
'prepareTestLoader', 'prepareTestRunner',
'setOutputStream')
plugins = RestrictedPluginManager(exclude=setuptools_incompat)
conf = Config(files=all_config_files(),
plugins=plugins)
conf.configure(argv=['collector'])
loader = defaultTestLoader(conf)
if conf.testNames:
suite = loader.loadTestsFromNames(conf.testNames)
else:
suite = loader.loadTestsFromNames(('.',))
return FinalizingSuiteWrapper(suite, plugins.finalize)
示例4: run
def run(*arg, **kw):
"""
Specialized version of nose.run for use inside of doctests that
test test runs.
This version of run() prints the result output to stdout. Before
printing, the output is processed by replacing the timing
information with an ellipsis (...), removing traceback stacks, and
removing trailing whitespace.
Use this version of run wherever you are writing a doctest that
tests nose (or unittest) test result output.
Note: do not use doctest: +ELLIPSIS when testing nose output,
since ellipses ("test_foo ... ok") in your expected test runner
output may match multiple lines of output, causing spurious test
passes!
"""
from nose import run
from nose.config import Config
from nose.plugins.manager import PluginManager
buffer = Buffer()
if 'config' not in kw:
plugins = kw.pop('plugins', [])
if isinstance(plugins, list):
plugins = PluginManager(plugins=plugins)
env = kw.pop('env', {})
kw['config'] = Config(env=env, plugins=plugins)
if 'argv' not in kw:
kw['argv'] = ['nosetests', '-v']
kw['config'].stream = buffer
# Set up buffering so that all output goes to our buffer,
# or warn user if deprecated behavior is active. If this is not
# done, prints and warnings will either be out of place or
# disappear.
stderr = sys.stderr
stdout = sys.stdout
if kw.pop('buffer_all', False):
sys.stdout = sys.stderr = buffer
restore = True
else:
restore = False
warn("The behavior of nose.plugins.plugintest.run() will change in "
"the next release of nose. The current behavior does not "
"correctly account for output to stdout and stderr. To enable "
"correct behavior, use run_buffered() instead, or pass "
"the keyword argument buffer_all=True to run().",
DeprecationWarning, stacklevel=2)
try:
run(*arg, **kw)
finally:
if restore:
sys.stderr = stderr
sys.stdout = stdout
out = buffer.getvalue()
print munge_nose_output_for_doctest(out)
示例5: test_exclude
def test_exclude(self):
s = Selector(Config())
c = Config()
c.exclude = [re.compile(r'me')]
s2 = Selector(c)
assert s.matches('test_foo')
assert s2.matches('test_foo')
assert s.matches('test_me')
assert not s2.matches('test_me')
示例6: test_ignore_files_override
def test_ignore_files_override(self):
"""Override the configuration to skip only specified files."""
c = Config()
c.ignoreFiles = [re.compile(r'^test_favourite_colour\.py$')]
s = Selector(c)
assert s.wantFile('_test_underscore.py')
assert s.wantFile('.test_hidden.py')
assert not s.wantFile('setup.py') # Actually excluded because of testMatch
assert not s.wantFile('test_favourite_colour.py')
示例7: test_mp_process_args_pickleable
def test_mp_process_args_pickleable():
test = case.Test(T('runTest'))
config = Config()
config.multiprocess_workers = 2
config.multiprocess_timeout = 0.1
runner = multiprocess.MultiProcessTestRunner(
stream=_WritelnDecorator(sys.stdout),
verbosity=2,
loaderClass=TestLoader,
config=config)
runner.run(test)
示例8: test_isolation
def test_isolation(self):
"""root logger settings ignored"""
root = logging.getLogger('')
nose = logging.getLogger('nose')
config = Config()
config.configureLogging()
root.setLevel(logging.DEBUG)
self.assertEqual(nose.level, logging.WARN)
示例9: test_mp_process_args_pickleable
def test_mp_process_args_pickleable():
# TODO(Kumar) this test needs to be more succint.
# If you start seeing it timeout then perhaps we need to skip it again.
# raise SkipTest('this currently gets stuck in poll() 90% of the time')
test = case.Test(T('runTest'))
config = Config()
config.multiprocess_workers = 2
config.multiprocess_timeout = 5
runner = multiprocess.MultiProcessTestRunner(
stream=_WritelnDecorator(sys.stdout),
verbosity=10,
loaderClass=TestLoader,
config=config)
runner.run(test)
示例10: TestIdTest
class TestIdTest(unittest.TestCase):
tests_location = "tests/data/testid/testid.py"
idfile_location = "data/testid/.noseids"
def setUp(self):
self.idfile = os.path.abspath(
os.path.join(os.path.dirname(__file__), self.idfile_location))
parser = optparse.OptionParser()
argv = [
# 0 is always program
"lode_runner",
"--failed",
"--with-id",
"--id-file=%s" % self.idfile
]
self.x = TestId()
self.x.add_options(parser, env={})
(options, args) = parser.parse_args(argv)
self.config = Config()
self.x.configure(options, self.config)
self.config.plugins = PluginManager()
self.config.plugins.addPlugin(Dataprovider())
self.config.plugins.addPlugin(TestId())
self.config.configure(argv)
def tearDown(self):
try:
os.remove(self.idfile)
except OSError:
pass
def test_load_tests_path_with_no_info_in_idfile(self):
names = self.x.loadTestsFromNames([self.tests_location])
self.assertEqual((None, [self.tests_location]), names)
def test_loaded_names_with_failing_tests_in_idfile(self):
stream = StringIO()
tests = TestLoader(config=self.config).loadTestsFromName(self.tests_location)
result = LodeTestResult(stream, None, 0)
tests.run(result)
# generate needed idfile
self.config.plugins.finalize(result)
names = self.x.loadTestsFromNames([self.tests_location])
loaded_tests = [(parse_test_name(name)[1], parse_test_name(name)[2]) for name in names[1]]
self.assertEqual(
[('DataprovidedTestCase','test_with_dataprovider_failing_on_everything_except_2_1'),
('DataprovidedTestCase','test_with_dataprovider_failing_on_everything_except_2_3')], loaded_tests)
示例11: test_queue_manager_timing_out
def test_queue_manager_timing_out(self):
class Options(object):
gevented_timeout = .05
config = Config()
config.options = Options()
queue_manager = gmultiprocess.TestsQueueManager(config=config)
tasks = [gmultiprocess.get_task_key(('test_addr', 'arg'))]
with self.assertRaisesRegexp(Exception, 'Timing out'):
queue_manager.process_test_results(
tasks,
global_result=None,
output_stream=None,
stop_on_error=False,
)
示例12: DiscoverTest
class DiscoverTest(unittest.TestCase):
tests_location = "tests/data/dataprovided/dataprovided.py"
tested_test = ":TestCase.test_with_dataprovider_fixture_2"
argv = []
ran_1_test = "Ran 1 test"
no_such_test = "ValueError: No such test"
def setUp(self):
self.config = Config()
self.config.plugins = PluginManager()
self.config.plugins.addPlugin(Dataprovider())
self.config.configure(self.argv)
def tearDown(self):
del sys.modules["dataprovided"]
self.argv = []
示例13: test_include
def test_include(self):
s = Selector(Config())
c = Config()
c.include = [re.compile(r"me")]
s2 = Selector(c)
assert s.matches("test")
assert s2.matches("test")
assert not s.matches("meatball")
assert s2.matches("meatball")
assert not s.matches("toyota")
assert not s2.matches("toyota")
c.include.append(re.compile("toy"))
assert s.matches("test")
assert s2.matches("test")
assert not s.matches("meatball")
assert s2.matches("meatball")
assert not s.matches("toyota")
assert s2.matches("toyota")
示例14: _execPlugin
def _execPlugin(self):
"""execute the plugin on the internal test suite.
"""
from nose.config import Config
from nose.core import TestProgram
from nose.plugins.manager import PluginManager
suite = None
stream = Buffer()
conf = Config(env=self.env,
stream=stream,
plugins=PluginManager(plugins=self.plugins))
if self.ignoreFiles is not None:
conf.ignoreFiles = self.ignoreFiles
if not self.suitepath:
suite = self.makeSuite()
self.nose = TestProgram(argv=self.argv, config=conf, suite=suite,
exit=False)
self.output = AccessDecorator(stream)
示例15: test_include
def test_include(self):
s = Selector(Config())
c = Config()
c.include = [re.compile(r'me')]
s2 = Selector(c)
assert s.matches('test')
assert s2.matches('test')
assert not s.matches('meatball')
assert s2.matches('meatball')
assert not s.matches('toyota')
assert not s2.matches('toyota')
c.include.append(re.compile('toy'))
assert s.matches('test')
assert s2.matches('test')
assert not s.matches('meatball')
assert s2.matches('meatball')
assert not s.matches('toyota')
assert s2.matches('toyota')