本文整理汇总了Python中nose2.tests._common.support_file函数的典型用法代码示例。如果您正苦于以下问题:Python support_file函数的具体用法?Python support_file怎么用?Python support_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了support_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_name_from_path
def test_name_from_path(self):
test_module = support_file('scenario/tests_in_package/pkg1/test/test_things.py')
test_package_path = support_file('scenario/tests_in_package')
self.assertEqual(
util.name_from_path(test_module),
('pkg1.test.test_things', test_package_path)
)
示例2: test_session_config_cacheing
def test_session_config_cacheing(self):
"""Test cacheing of config sections works"""
# Create new session (generic one likely already cached
# depending on test order)
cache_sess = session.Session()
cache_sess.loadConfigFiles(support_file('cfg', 'a.cfg'))
# First access to given section, should read from config file
firstaccess = cache_sess.get('a')
assert firstaccess.as_int("a") == 1
# Hack cached Config object internals to make the stored value
# something different
cache_sess.configCache["a"]._mvd["a"] = "0"
newitems = []
for item in cache_sess.configCache["a"]._items:
if item != ("a", "1"):
newitems.append(item)
else:
newitems.append(("a", "0"))
cache_sess.configCache["a"]._items = newitems
# Second access to given section, confirm returns cached value
# rather than parsing config file again
secondaccess = cache_sess.get("a")
assert secondaccess.as_int("a") == 0
示例3: test_module_name_with_start_dir
def test_module_name_with_start_dir(self):
proc = self.runIn(
'.', '-v', '-s', support_file('scenario/tests_in_package'),
'pkg1.test.test_things')
self.assertTestRunOutputMatches(proc, stderr='Ran 25 tests')
self.assertEqual(proc.poll(), 1)
示例4: test_dispatch_tests_receive_events
def test_dispatch_tests_receive_events(self):
ssn = {
'config': self.session.config,
'verbosity': 1,
'startDir': support_file('scenario/tests_in_package'),
'topLevelDir': support_file('scenario/tests_in_package'),
'logLevel': 100,
'pluginClasses': [discovery.DiscoveryLoader,
testcases.TestCaseLoader,
buffer.OutputBufferPlugin]
}
conn = Conn(['pkg1.test.test_things.SomeTests.test_ok',
'pkg1.test.test_things.SomeTests.test_failed'])
procserver(ssn, conn)
# check conn calls
expect = [('pkg1.test.test_things.SomeTests.test_ok',
[('startTest', {}),
('setTestOutcome', {'outcome': 'passed'}),
('testOutcome', {'outcome': 'passed'}),
('stopTest', {})]
),
('pkg1.test.test_things.SomeTests.test_failed',
[('startTest', {}),
('setTestOutcome', {
'outcome': 'failed',
'expected': False,
'metadata': {'stdout': 'Hello stdout\n'}}),
('testOutcome', {
'outcome': 'failed',
'expected': False,
'metadata': {'stdout': 'Hello stdout\n'}}),
('stopTest', {})]
),
]
for val in conn.sent:
if val is None:
break
test, events = val
exp_test, exp_events = expect.pop(0)
self.assertEqual(test, exp_test)
for method, event in events:
exp_meth, exp_attr = exp_events.pop(0)
self.assertEqual(method, exp_meth)
for attr, val in exp_attr.items():
self.assertEqual(getattr(event, attr), val)
示例5: test_start_directory_inside_package
def test_start_directory_inside_package(self):
proc = self.runIn(
'scenario/tests_in_package/pkg1/test',
'-v',
'-t',
support_file('scenario/tests_in_package'))
self.assertTestRunOutputMatches(proc, stderr='Ran 25 tests')
self.assertEqual(proc.poll(), 1)
示例6: test_discovery_supports_code_in_lib_dir
def test_discovery_supports_code_in_lib_dir(self):
self.session.startDir = support_file('scenario/package_in_lib')
event = events.LoadFromNamesEvent(self.loader, [], None)
result = self.session.hooks.loadTestsFromNames(event)
assert isinstance(result, self.loader.suiteClass)
self.assertEqual(len(result._tests), 1)
self.assertEqual(len(self.watcher.called), 1)
self.assertEqual(self.watcher.called[0].module.__name__, 'tests')
示例7: test_can_discover_test_modules_in_packages
def test_can_discover_test_modules_in_packages(self):
self.session.startDir = support_file('scenario/tests_in_package')
event = events.LoadFromNamesEvent(self.loader, [], None)
result = self.session.hooks.loadTestsFromNames(event)
assert isinstance(result, self.loader.suiteClass)
self.assertEqual(len(result._tests), 1)
self.assertEqual(len(self.watcher.called), 1)
self.assertEqual(self.watcher.called[0].module.__name__,
'pkg1.test.test_things')
示例8: test_flatten_respects_module_fixtures
def test_flatten_respects_module_fixtures(self):
sys.path.append(support_file('scenario/module_fixtures'))
import test_mf_testcase as mod
suite = unittest.TestSuite()
suite.addTest(mod.Test('test_1'))
suite.addTest(mod.Test('test_2'))
flat = list(self.plugin._flatten(suite))
self.assertEqual(flat, ['test_mf_testcase'])
示例9: run_with_junitxml_loaded
def run_with_junitxml_loaded(self, scenario, *args):
work_dir = os.getcwd()
test_dir = support_file(*scenario)
junit_report = os.path.join(work_dir, 'nose2-junit.xml')
proc = self.runIn(work_dir,
'-s%s' % test_dir,
'--plugin=nose2.plugins.junitxml',
'-v',
*args)
return junit_report, proc
示例10: test_flatten_without_fixtures
def test_flatten_without_fixtures(self):
sys.path.append(support_file('scenario/slow'))
import test_slow as mod
suite = unittest.TestSuite()
suite.addTest(mod.TestSlow('test_ok'))
suite.addTest(mod.TestSlow('test_fail'))
suite.addTest(mod.TestSlow('test_err'))
flat = list(self.plugin._flatten(suite))
self.assertEqual(len(flat), 3)
示例11: test_match_path_event_can_prevent_discovery
def test_match_path_event_can_prevent_discovery(self):
class NoTestsForYou(events.Plugin):
def matchPath(self, event):
event.handled = True
return False
mp = NoTestsForYou(session=self.session)
mp.register()
self.session.startDir = support_file('scenario/tests_in_package')
event = events.LoadFromNamesEvent(self.loader, [], None)
result = self.session.hooks.loadTestsFromNames(event)
assert isinstance(result, self.loader.suiteClass)
self.assertEqual(len(result._tests), 0)
self.assertEqual(len(self.watcher.called), 0)
示例12: test_run
def test_run(self):
# ensure there is no .coverage file at the start of test
reportfile = support_file('scenario/test_with_module/.coverage')
try:
os.remove(reportfile)
except OSError:
pass
proc = self.runIn(
'scenario/test_with_module',
'-v',
'--with-coverage',
'--coverage=lib/'
)
self.assertProcOutputPattern(proc, 'lib', '\s+8\s+5\s+38%')
self.assertTrue(os.path.exists(reportfile))
示例13: test_handle_file_event_can_add_tests
def test_handle_file_event_can_add_tests(self):
class TextTest(TestCase):
def test(self):
pass
class TestsInText(events.Plugin):
def handleFile(self, event):
if event.path.endswith('.txt'):
event.extraTests.append(TextTest('test'))
mp = TestsInText(session=self.session)
mp.register()
self.session.startDir = support_file('scenario/tests_in_package')
event = events.LoadFromNamesEvent(self.loader, [], None)
result = self.session.hooks.loadTestsFromNames(event)
assert isinstance(result, self.loader.suiteClass)
self.assertEqual(len(result._tests), 2)
self.assertEqual(len(self.watcher.called), 1)
示例14: run_with_junitxml_loaded
def run_with_junitxml_loaded(self, scenario, *args):
work_dir = os.getcwd()
test_dir = support_file(*scenario)
junit_report = os.path.join(work_dir, 'nose2-junit.xml')
config = os.path.join(test_dir, 'unittest.cfg')
config_args = ()
if os.path.exists(junit_report):
os.remove(junit_report)
if os.path.exists(config):
config_args = ('-c', config)
proc = self.runIn(work_dir,
'-s%s' % test_dir,
'--plugin=nose2.plugins.junitxml',
'-v',
*(config_args + args))
return junit_report, proc
示例15: test_flatten_respects_class_fixtures
def test_flatten_respects_class_fixtures(self):
sys.path.append(support_file('scenario/class_fixtures'))
import test_cf_testcase as mod
suite = unittest.TestSuite()
suite.addTest(mod.Test('test_1'))
suite.addTest(mod.Test('test_2'))
suite.addTest(mod.Test2('test_1'))
suite.addTest(mod.Test2('test_2'))
suite.addTest(mod.Test3('test_3'))
flat = list(self.plugin._flatten(suite))
self.assertEqual(flat, ['test_cf_testcase.Test2.test_1',
'test_cf_testcase.Test2.test_2',
'test_cf_testcase.Test',
'test_cf_testcase.Test3',
])