本文整理汇总了Python中test.test_support.captured_stdout函数的典型用法代码示例。如果您正苦于以下问题:Python captured_stdout函数的具体用法?Python captured_stdout怎么用?Python captured_stdout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了captured_stdout函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_config_8_ok
def test_config_8_ok(self):
with captured_stdout() as output:
self.apply_config(self.config1)
logger = logging.getLogger("compiler.parser")
# Both will output a message
logger.info(self.next_message())
logger.error(self.next_message())
self.assert_log_lines([
('INFO', '1'),
('ERROR', '2'),
], stream=output)
# Original logger output is empty.
self.assert_log_lines([])
with captured_stdout() as output:
self.apply_config(self.config8)
logger = logging.getLogger("compiler.parser")
self.assertFalse(logger.disabled)
# Both will output a message
logger.info(self.next_message())
logger.error(self.next_message())
logger = logging.getLogger("compiler.lexer")
# Both will output a message
logger.info(self.next_message())
logger.error(self.next_message())
self.assert_log_lines([
('INFO', '3'),
('ERROR', '4'),
('INFO', '5'),
('ERROR', '6'),
], stream=output)
# Original logger output is empty.
self.assert_log_lines([])
示例2: test_debug_flag
def test_debug_flag(self):
with captured_stdout() as out:
re.compile('foo', re.DEBUG)
self.assertEqual(out.getvalue().splitlines(),
['literal 102', 'literal 111', 'literal 111'])
# Debug output is output again even a second time (bypassing
# the cache -- issue #20426).
with captured_stdout() as out:
re.compile('foo', re.DEBUG)
self.assertEqual(out.getvalue().splitlines(),
['literal 102', 'literal 111', 'literal 111'])
示例3: test_debug_print
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
示例4: test_debug_print
def test_debug_print(self):
cmd = self.cmd
with captured_stdout() as stdout:
cmd.debug_print('xxx')
stdout.seek(0)
self.assertEqual(stdout.read(), '')
debug.DEBUG = True
try:
with captured_stdout() as stdout:
cmd.debug_print('xxx')
stdout.seek(0)
self.assertEqual(stdout.read(), 'xxx\n')
finally:
debug.DEBUG = False
示例5: test_debug_print
def test_debug_print(self):
file_list = FileList()
with captured_stdout() as stdout:
file_list.debug_print("xxx")
stdout.seek(0)
self.assertEqual(stdout.read(), "")
debug.DEBUG = True
try:
with captured_stdout() as stdout:
file_list.debug_print("xxx")
stdout.seek(0)
self.assertEqual(stdout.read(), "xxx\n")
finally:
debug.DEBUG = False
示例6: test_tarfile_vs_tar
def test_tarfile_vs_tar(self):
root_dir, base_dir = self._create_files()
base_name = os.path.join(self.mkdtemp(), 'archive')
tarball = make_archive(base_name, 'gztar', root_dir, base_dir)
# check if the compressed tarball was created
self.assertEqual(tarball, base_name + '.tar.gz')
self.assertTrue(os.path.isfile(tarball))
# now create another tarball using `tar`
tarball2 = os.path.join(root_dir, 'archive2.tar')
tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir]
with support.change_cwd(root_dir), captured_stdout():
spawn(tar_cmd)
self.assertTrue(os.path.isfile(tarball2))
# let's compare both tarballs
self.assertEqual(self._tarinfo(tarball), self._tarinfo(tarball2))
# trying an uncompressed one
tarball = make_archive(base_name, 'tar', root_dir, base_dir)
self.assertEqual(tarball, base_name + '.tar')
self.assertTrue(os.path.isfile(tarball))
# now for a dry_run
tarball = make_archive(base_name, 'tar', root_dir, base_dir,
dry_run=True)
self.assertEqual(tarball, base_name + '.tar')
self.assertTrue(os.path.isfile(tarball))
示例7: report
def report(self, pat):
grep.engine._pat = pat
with captured_stdout() as s:
grep.grep_it(re.compile(pat), __file__)
lines = s.getvalue().split('\n')
lines.pop()
return lines
示例8: test_eval
def test_eval(self):
with open(_fname + '.dir', 'w') as stream:
stream.write("str(__import__('sys').stdout.write('Hacked!')), 0\n")
with test_support.captured_stdout() as stdout:
with self.assertRaises(ValueError):
dumbdbm.open(_fname).close()
self.assertEqual(stdout.getvalue(), '')
示例9: report
def report(self, pat):
grep.engine._pat = pat
with captured_stdout() as s:
grep.grep_it(re.compile(pat), __file__)
lines = s.getvalue().split("\n")
lines.pop() # remove bogus '' after last \n
return lines
示例10: test_debug_mode
def test_debug_mode(self):
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)
示例11: test_module_reuse
def test_module_reuse(self):
with util.uncache(u'__hello__'), captured_stdout() as stdout:
module1 = machinery.FrozenImporter.load_module(u'__hello__')
module2 = machinery.FrozenImporter.load_module(u'__hello__')
self.assertTrue(module1 is module2)
self.assertEqual(stdout.getvalue(),
u'Hello world!\nHello world!\n')
示例12: test_debug_print
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
示例13: test_namedtuple_public_underscore
def test_namedtuple_public_underscore(self):
NT = namedtuple('NT', ['abc', 'def'], rename=True)
with captured_stdout() as help_io:
help(NT)
helptext = help_io.getvalue()
self.assertIn('_1', helptext)
self.assertIn('_replace', helptext)
self.assertIn('_asdict', helptext)
示例14: test_module
def test_module(self):
with util.uncache(u'__hello__'), captured_stdout() as stdout:
module = machinery.FrozenImporter.load_module(u'__hello__')
check = {u'__name__': u'__hello__', u'__file__': u'<frozen>',
u'__package__': u'', u'__loader__': machinery.FrozenImporter}
for attr, value in check.items():
self.assertEqual(getattr(module, attr), value)
self.assertEqual(stdout.getvalue(), u'Hello world!\n')
示例15: test_debug_mode
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.assertEquals(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.assertEquals(stdout.readlines()[0], wanted)