本文整理汇总了Python中test.support.captured_stdout函数的典型用法代码示例。如果您正苦于以下问题:Python captured_stdout函数的具体用法?Python captured_stdout怎么用?Python captured_stdout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了captured_stdout函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_frozen
def test_frozen(self):
with captured_stdout() as stdout:
try:
import __hello__
except ImportError as x:
self.fail("import __hello__ failed:" + str(x))
self.assertEqual(__hello__.initialized, True)
expect = set(self.module_attrs)
expect.add('initialized')
self.assertEqual(set(dir(__hello__)), expect)
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
with captured_stdout() as stdout:
try:
import __phello__
except ImportError as x:
self.fail("import __phello__ failed:" + str(x))
self.assertEqual(__phello__.initialized, True)
expect = set(self.package_attrs)
expect.add('initialized')
if not "__phello__.spam" in sys.modules:
self.assertEqual(set(dir(__phello__)), expect)
else:
expect.add('spam')
self.assertEqual(set(dir(__phello__)), expect)
self.assertEqual(__phello__.__path__, [__phello__.__name__])
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
with captured_stdout() as stdout:
try:
import __phello__.spam
except ImportError as x:
self.fail("import __phello__.spam failed:" + str(x))
self.assertEqual(__phello__.spam.initialized, True)
spam_expect = set(self.module_attrs)
spam_expect.add('initialized')
self.assertEqual(set(dir(__phello__.spam)), spam_expect)
phello_expect = set(self.package_attrs)
phello_expect.add('initialized')
phello_expect.add('spam')
self.assertEqual(set(dir(__phello__)), phello_expect)
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
try:
import __phello__.foo
except ImportError:
pass
else:
self.fail("import __phello__.foo should have failed")
try:
import __phello__.foo
except ImportError:
pass
else:
self.fail("import __phello__.foo should have failed")
del sys.modules['__hello__']
del sys.modules['__phello__']
del sys.modules['__phello__.spam']
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:60,代码来源:test_frozen.py
示例2: 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:1st1,项目名称:cpython,代码行数:13,代码来源:test_filelist.py
示例3: test_frozen
def test_frozen(self):
with captured_stdout() as stdout:
try:
import __hello__
except ImportError as x:
self.fail("import __hello__ failed:" + str(x))
self.assertEqual(__hello__.initialized, True)
self.assertEqual(len(dir(__hello__)), 7, dir(__hello__))
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
with captured_stdout() as stdout:
try:
import __phello__
except ImportError as x:
self.fail("import __phello__ failed:" + str(x))
self.assertEqual(__phello__.initialized, True)
if not "__phello__.spam" in sys.modules:
self.assertEqual(len(dir(__phello__)), 8, dir(__phello__))
else:
self.assertEqual(len(dir(__phello__)), 9, dir(__phello__))
self.assertEqual(__phello__.__path__, [__phello__.__name__])
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
with captured_stdout() as stdout:
try:
import __phello__.spam
except ImportError as x:
self.fail("import __phello__.spam failed:" + str(x))
self.assertEqual(__phello__.spam.initialized, True)
self.assertEqual(len(dir(__phello__.spam)), 7)
self.assertEqual(len(dir(__phello__)), 9)
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
try:
import __phello__.foo
except ImportError:
pass
else:
self.fail("import __phello__.foo should have failed")
try:
import __phello__.foo
except ImportError:
pass
else:
self.fail("import __phello__.foo should have failed")
del sys.modules['__hello__']
del sys.modules['__phello__']
del sys.modules['__phello__.spam']
开发者ID:7modelsan,项目名称:kbengine,代码行数:50,代码来源:test_frozen.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:5outh,项目名称:Databases-Fall2014,代码行数:15,代码来源:test_cmd.py
示例5: run_test
def run_test(self, leftovers=False, dump=False, verbose=False):
"""Parse the input buffer prepared through the 'add_' functions
and compare the results to the expected output. `leftovers`
should be `True` if the input buffer is expected to have excess
data in it. If `dump` is `True`, the state of the mock socket
will be dumped after parsing."""
if verbose:
print("Initial state of socket")
self.sock.dump()
self.expected_output.append("")
with contextlib.ExitStack() as stack:
for parse_error in self.expected_parse_errors:
stack.enter_context(self.assertRaises(ParseError,
msg=parse_error))
with support.captured_stdout() as stdout:
mtapi = mtcmds.MTAPI(self.sock)
mtapi()
while mtapi.state != mtapi.read_sof:
mtapi()
if dump:
print("Final state of socket")
self.sock.dump()
if leftovers:
self.assertFalse(self.sock.eof())
else:
self.assertTrue(self.sock.eof())
if verbose:
print("Parse output:")
print(stdout.getvalue())
actual_output = stdout.getvalue().split("\n")
for (expected, actual) in zip(self.expected_output, actual_output):
self.assertEqual(expected, actual)
开发者ID:kynesim,项目名称:MTConsole,代码行数:32,代码来源:base_test.py
示例6: test_frozen
def test_frozen(self):
name = '__hello__'
if name in sys.modules:
del sys.modules[name]
with captured_stdout() as out:
import __hello__
self.assertEqual(out.getvalue(), 'Hello world!\n')
开发者ID:Eyepea,项目名称:cpython,代码行数:7,代码来源:test_frozen.py
示例7: test_resolve_false
def test_resolve_false(self):
# Issue #23008: pydoc enum.{,Int}Enum failed
# because bool(enum.Enum) is False.
with captured_stdout() as help_io:
pydoc.help('enum.Enum')
helptext = help_io.getvalue()
self.assertIn('class Enum', helptext)
开发者ID:Martiusweb,项目名称:cpython,代码行数:7,代码来源:test_pydoc.py
示例8: test_compile_file_pathlike
def test_compile_file_pathlike(self):
self.assertFalse(os.path.isfile(self.bc_path))
# we should also test the output
with support.captured_stdout() as stdout:
self.assertTrue(compileall.compile_file(pathlib.Path(self.source_path)))
self.assertRegex(stdout.getvalue(), r'Compiling ([^WindowsPath|PosixPath].*)')
self.assertTrue(os.path.isfile(self.bc_path))
开发者ID:1st1,项目名称:cpython,代码行数:7,代码来源:test_compileall.py
示例9: test_help
def test_help(self):
for opt in '-h', '--help':
with self.subTest(opt=opt):
with support.captured_stdout() as out, \
self.assertRaises(SystemExit):
libregrtest._parse_args([opt])
self.assertIn('Run Python regression tests.', out.getvalue())
开发者ID:grantjenks,项目名称:cpython,代码行数:7,代码来源:test_regrtest.py
示例10: test_compile_dir_pathlike
def test_compile_dir_pathlike(self):
self.assertFalse(os.path.isfile(self.bc_path))
with support.captured_stdout() as stdout:
compileall.compile_dir(pathlib.Path(self.directory))
line = stdout.getvalue().splitlines()[0]
self.assertRegex(line, r'Listing ([^WindowsPath|PosixPath].*)')
self.assertTrue(os.path.isfile(self.bc_path))
开发者ID:1st1,项目名称:cpython,代码行数:7,代码来源:test_compileall.py
示例11: 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:5outh,项目名称:Databases-Fall2014,代码行数:7,代码来源:test_grep.py
示例12: test_module_reuse
def test_module_reuse(self):
with util.uncache('__hello__'), captured_stdout() as stdout:
module1 = machinery.FrozenImporter.load_module('__hello__')
module2 = machinery.FrozenImporter.load_module('__hello__')
self.assertTrue(module1 is module2)
self.assertEqual(stdout.getvalue(),
'Hello world!\nHello world!\n')
开发者ID:Qointum,项目名称:pypy,代码行数:7,代码来源:test_loader.py
示例13: test_repr
def test_repr(self):
with support.captured_stdout() as template:
A = recordclass('A', 'x')
self.assertEqual(repr(A(1)), 'A(x=1)')
# repr should show the name of the subclass
class B(A):
pass
self.assertEqual(repr(B(1)), 'B(x=1)')
开发者ID:intellimath,项目名称:recordclass,代码行数:8,代码来源:test_recordclass.py
示例14: 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:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:8,代码来源:test_pydoc.py
示例15: 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:francois-wellenreiter,项目名称:cpython,代码行数:8,代码来源:test_sdist.py
示例16: test_eval
def test_eval(self):
with open(_fname + '.dir', 'w') as stream:
stream.write("str(print('Hacked!')), 0\n")
with support.captured_stdout() as stdout:
with self.assertRaises(ValueError):
with dumbdbm.open(_fname) as f:
pass
self.assertEqual(stdout.getvalue(), '')
开发者ID:CabbageHead-360,项目名称:cpython,代码行数:8,代码来源:test_dbm_dumb.py
示例17: 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:524777134,项目名称:cpython,代码行数:8,代码来源:test_pydoc.py
示例18: test_module
def test_module(self):
with util.uncache('__hello__'), captured_stdout() as stdout:
module = machinery.FrozenImporter.load_module('__hello__')
check = {'__name__': '__hello__', '__file__': '<frozen>',
'__package__': '', '__loader__': machinery.FrozenImporter}
for attr, value in check.items():
self.assertEqual(getattr(module, attr), value)
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
开发者ID:Qointum,项目名称:pypy,代码行数:8,代码来源:test_loader.py
示例19: 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.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:Connor124,项目名称:Gran-Theft-Crop-Toe,代码行数:17,代码来源:test_core.py
示例20: test_repr
def test_repr(self):
with support.captured_stdout() as template:
A = namedtuple('A', 'x', verbose=True)
self.assertEqual(repr(A(1)), 'A(x=1)')
# repr should show the name of the subclass
class B(A):
pass
self.assertEqual(repr(B(1)), 'B(x=1)')
开发者ID:469306621,项目名称:Languages,代码行数:8,代码来源:test_collections.py
注:本文中的test.support.captured_stdout函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论