本文整理汇总了Python中test.test_support.captured_stdout方法的典型用法代码示例。如果您正苦于以下问题:Python test_support.captured_stdout方法的具体用法?Python test_support.captured_stdout怎么用?Python test_support.captured_stdout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.test_support
的用法示例。
在下文中一共展示了test_support.captured_stdout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_debug_mode
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_debug_mode(self):
# this covers the code called when DEBUG is set
sys.argv = ['setup.py', '--name']
with captured_stdout() as stdout:
distutils.core.setup(name='bar')
stdout.seek(0)
self.assertEqual(stdout.read(), 'bar\n')
distutils.core.DEBUG = True
try:
with captured_stdout() as stdout:
distutils.core.setup(name='bar')
finally:
distutils.core.DEBUG = False
stdout.seek(0)
wanted = "options (after parsing config files):\n"
self.assertEqual(stdout.readlines()[0], wanted)
示例2: test_debug_print
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_debug_print(self):
class MyCCompiler(CCompiler):
executables = {}
compiler = MyCCompiler()
with captured_stdout() as stdout:
compiler.debug_print('xxx')
stdout.seek(0)
self.assertEqual(stdout.read(), '')
debug.DEBUG = True
try:
with captured_stdout() as stdout:
compiler.debug_print('xxx')
stdout.seek(0)
self.assertEqual(stdout.read(), 'xxx\n')
finally:
debug.DEBUG = False
示例3: test_debug_mode
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_debug_mode(self):
with open(TESTFN, "w") as f:
f.write("[global]\n")
f.write("command_packages = foo.bar, splat")
self.addCleanup(unlink, TESTFN)
files = [TESTFN]
sys.argv.append("build")
with captured_stdout() as stdout:
self.create_distribution(files)
stdout.seek(0)
self.assertEqual(stdout.read(), '')
distutils.dist.DEBUG = True
try:
with captured_stdout() as stdout:
self.create_distribution(files)
stdout.seek(0)
self.assertEqual(stdout.read(), '')
finally:
distutils.dist.DEBUG = False
示例4: check
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def check(self, expected, args,
sep=NotDefined, end=NotDefined, file=NotDefined):
# Capture sys.stdout in a StringIO. Call print with args,
# and with sep, end, and file, if they're defined. Result
# must match expected.
# Look up the actual function to call, based on if sep, end, and file
# are defined
fn = dispatch[(sep is not NotDefined,
end is not NotDefined,
file is not NotDefined)]
with test_support.captured_stdout() as t:
fn(args, sep, end, file)
self.assertEqual(t.getvalue(), expected)
示例5: test_config_dict_invalid
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_config_dict_invalid(self):
cfg_name = self.get_cfg_file(invalid_test_config)
with support.captured_stdout() as stdout:
parsed_cfg = turtle.config_dict(cfg_name)
err_msg = stdout.getvalue()
self.assertIn('Bad line in config-file ', err_msg)
self.assertIn('fillcolor: blue', err_msg)
self.assertEqual(parsed_cfg, {
'pencolor': 'red',
'visible': False,
})
示例6: test_list_verbose
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_list_verbose(self):
with test_support.captured_stdout() as t:
self.tar.list(verbose=True)
out = t.getvalue()
# Make sure it prints files separated by one newline with 'ls -l'-like
# accessories if verbose flag is being used
# ...
# ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/conttype
# ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/regtype
# ...
self.assertRegexpMatches(out, (r'-rw-r--r-- tarfile/tarfile\s+7011 '
r'\d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d '
r'ustar/\w+type ?\r?\n') * 2)
# Make sure it prints the source of link with verbose flag
self.assertIn('ustar/symtype -> regtype', out)
self.assertIn('./ustar/linktest2/symtype -> ../linktest1/regtype', out)
self.assertIn('./ustar/linktest2/lnktype link to '
'./ustar/linktest1/regtype', out)
self.assertIn('gnu' + ('/123' * 125) + '/longlink link to gnu' +
('/123' * 125) + '/longname', out)
self.assertIn('pax' + ('/123' * 125) + '/longlink link to pax' +
('/123' * 125) + '/longname', out)
示例7: test_config_9_ok
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_config_9_ok(self):
with captured_stdout() as output:
self.apply_config(self.config9)
logger = logging.getLogger("compiler.parser")
#Nothing will be output since both handler and logger are set to WARNING
logger.info(self.next_message())
self.assert_log_lines([], stream=output)
self.apply_config(self.config9a)
#Nothing will be output since both handler is still set to WARNING
logger.info(self.next_message())
self.assert_log_lines([], stream=output)
self.apply_config(self.config9b)
#Message should now be output
logger.info(self.next_message())
self.assert_log_lines([
('INFO', '3'),
], stream=output)
示例8: test_config_10_ok
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_config_10_ok(self):
with captured_stdout() as output:
self.apply_config(self.config10)
logger = logging.getLogger("compiler.parser")
logger.warning(self.next_message())
logger = logging.getLogger('compiler')
#Not output, because filtered
logger.warning(self.next_message())
logger = logging.getLogger('compiler.lexer')
#Not output, because filtered
logger.warning(self.next_message())
logger = logging.getLogger("compiler.parser.codegen")
#Output, as not filtered
logger.error(self.next_message())
self.assert_log_lines([
('WARNING', '1'),
('ERROR', '4'),
], stream=output)
示例9: test_cgi_get
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_cgi_get(self):
with test_support.EnvironmentVarGuard() as env:
env['REQUEST_METHOD'] = 'GET'
# if the method is GET and no request_text is given, it runs handle_get
# get sysout output
with test_support.captured_stdout() as data_out:
self.cgi.handle_request()
# parse Status header
data_out.seek(0)
handle = data_out.read()
status = handle.split()[1]
message = ' '.join(handle.split()[2:4])
self.assertEqual(status, '400')
self.assertEqual(message, 'Bad Request')
示例10: test_listen_config_10_ok
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_listen_config_10_ok(self):
with captured_stdout() as output:
self.setup_via_listener(json.dumps(self.config10))
logger = logging.getLogger("compiler.parser")
logger.warning(self.next_message())
logger = logging.getLogger('compiler')
#Not output, because filtered
logger.warning(self.next_message())
logger = logging.getLogger('compiler.lexer')
#Not output, because filtered
logger.warning(self.next_message())
logger = logging.getLogger("compiler.parser.codegen")
#Output, as not filtered
logger.error(self.next_message())
self.assert_log_lines([
('WARNING', '1'),
('ERROR', '4'),
], stream=output)
示例11: test_show_formats
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_show_formats(self):
with captured_stdout() as stdout:
show_formats()
# the output should be a header line + one line per format
num_formats = len(ARCHIVE_FORMATS.keys())
output = [line for line in stdout.getvalue().split('\n')
if line.strip().startswith('--formats=')]
self.assertEqual(len(output), num_formats)
示例12: test_debug_print
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_debug_print(self):
file_list = FileList()
with captured_stdout() as stdout:
file_list.debug_print('xxx')
self.assertEqual(stdout.getvalue(), '')
debug.DEBUG = True
try:
with captured_stdout() as stdout:
file_list.debug_print('xxx')
self.assertEqual(stdout.getvalue(), 'xxx\n')
finally:
debug.DEBUG = False
示例13: test_debug_mode
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_debug_mode(self):
# this covers the code called when DEBUG is set
old_logs_len = len(self.logs)
install_module.DEBUG = True
try:
with captured_stdout():
self.test_record()
finally:
install_module.DEBUG = False
self.assertGreater(len(self.logs), old_logs_len)
示例14: test_show_help
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def test_show_help(self):
# smoke test, just makes sure some help is displayed
self.addCleanup(log.set_threshold, log._global_log.threshold)
dist = Distribution()
sys.argv = []
dist.help = 1
dist.script_name = 'setup.py'
with captured_stdout() as s:
dist.parse_command_line()
output = [line for line in s.getvalue().split('\n')
if line.strip() != '']
self.assertTrue(output)
示例15: run_main
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import captured_stdout [as 别名]
def run_main(self, seconds_per_increment=1.0, switches=None, timer=None):
if timer is None:
timer = FakeTimer(seconds_per_increment=seconds_per_increment)
if switches is None:
args = []
else:
args = switches[:]
args.append(self.fake_stmt)
# timeit.main() modifies sys.path, so save and restore it.
orig_sys_path = sys.path[:]
with captured_stdout() as s:
timeit.main(args=args, _wrap_timer=timer.wrap_timer)
sys.path[:] = orig_sys_path[:]
return s.getvalue()