本文整理汇总了Python中test.test_support.captured_stdout函数的典型用法代码示例。如果您正苦于以下问题:Python captured_stdout函数的具体用法?Python captured_stdout怎么用?Python captured_stdout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了captured_stdout函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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([])
开发者ID:pratz,项目名称:Code,代码行数:32,代码来源:test_dictconfig.py
示例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'])
开发者ID:tklikifi,项目名称:python-pcre,代码行数:11,代码来源:test_pcre_re_compat.py
示例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
开发者ID:webiumsk,项目名称:WOT-0.9.15.1,代码行数:12,代码来源:test_filelist.py
示例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
开发者ID:aevitas,项目名称:wotsdk,代码行数:14,代码来源:teststest_cmd.py
示例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
开发者ID:B-Rich,项目名称:edk2,代码行数:15,代码来源:test_filelist.py
示例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))
开发者ID:gitter-badger,项目名称:node-cpython,代码行数:29,代码来源:test_shutil.py
示例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
开发者ID:webiumsk,项目名称:WOT-0.9.12-CT,代码行数:7,代码来源:test_grep.py
示例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(), '')
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_dumbdbm.py
示例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
开发者ID:uestcheng,项目名称:odoo,代码行数:7,代码来源:test_grep.py
示例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)
开发者ID:webiumsk,项目名称:WOT-0.9.12,代码行数:16,代码来源:test_core.py
示例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')
开发者ID:ralphbean,项目名称:importlib_full,代码行数:7,代码来源:test_loader.py
示例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
开发者ID:webiumsk,项目名称:WOT-0.9.14-CT,代码行数:17,代码来源:test_ccompiler.py
示例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)
开发者ID:49476291,项目名称:android-plus-plus,代码行数:8,代码来源:test_pydoc.py
示例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')
开发者ID:ralphbean,项目名称:importlib_full,代码行数:8,代码来源:test_loader.py
示例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)
开发者ID:johnbowker,项目名称:main,代码行数:17,代码来源:test_core.py
示例16: test_namedtuple_public_underscore
def test_namedtuple_public_underscore(self):
NT = namedtuple("NT", ["abc", "def"], rename=True)
with captured_stdout() as help_io:
pydoc.help(NT)
helptext = help_io.getvalue()
self.assertIn("_1", helptext)
self.assertIn("_replace", helptext)
self.assertIn("_asdict", helptext)
开发者ID:bq,项目名称:witbox-updater,代码行数:8,代码来源:test_pydoc.py
示例17: test_show_formats
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)
开发者ID:plirof,项目名称:minibloq_v0.83,代码行数:8,代码来源:test_sdist.py
示例18: test_show_help
def test_show_help(self):
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)
开发者ID:webiumsk,项目名称:WOT-0.9.15.1,代码行数:9,代码来源:test_dist.py
示例19: test_read_comm_kludge_compname_odd
def test_read_comm_kludge_compname_odd(self):
b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
b += 'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
b += 'NONE' + struct.pack('B', 3) + 'odd'
b += 'SSND' + struct.pack('>L', 8) + '\x00' * 8
with captured_stdout() as s:
f = aifc.open(io.BytesIO(b))
self.assertEqual(s.getvalue(), 'Warning: bad COMM chunk size\n')
self.assertEqual(f.getcompname(), 'odd')
开发者ID:grumpycoders,项目名称:Igor,代码行数:9,代码来源:test_aifc.py
示例20: test_get_code
def test_get_code(self):
# Make sure that the code object is good.
name = u'__hello__'
with captured_stdout() as stdout:
code = machinery.FrozenImporter.get_code(name)
mod = imp.new_module(name)
exec(code, mod.__dict__)
self.assertTrue(hasattr(mod, u'initialized'))
self.assertEqual(stdout.getvalue(), u'Hello world!\n')
开发者ID:ralphbean,项目名称:importlib_full,代码行数:9,代码来源:test_loader.py
注:本文中的test.test_support.captured_stdout函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论