本文整理汇总了Python中coverage.backward.StringIO.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.getvalue方法的具体用法?Python StringIO.getvalue怎么用?Python StringIO.getvalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.backward.StringIO
的用法示例。
在下文中一共展示了StringIO.getvalue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StdStreamCapturingMixin
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
class StdStreamCapturingMixin(TestCase):
"""A test case mixin that captures stdout and stderr."""
def setUp(self):
super(StdStreamCapturingMixin, self).setUp()
# Capture stdout and stderr so we can examine them in tests.
# nose keeps stdout from littering the screen, so we can safely Tee it,
# but it doesn't capture stderr, so we don't want to Tee stderr to the
# real stderr, since it will interfere with our nice field of dots.
self.old_stdout = sys.stdout
self.captured_stdout = StringIO()
sys.stdout = Tee(sys.stdout, self.captured_stdout)
self.old_stderr = sys.stderr
self.captured_stderr = StringIO()
sys.stderr = self.captured_stderr
self.addCleanup(self.cleanup_std_streams)
def cleanup_std_streams(self):
"""Restore stdout and stderr."""
sys.stdout = self.old_stdout
sys.stderr = self.old_stderr
def stdout(self):
"""Return the data written to stdout during the test."""
return self.captured_stdout.getvalue()
def stderr(self):
"""Return the data written to stderr during the test."""
return self.captured_stderr.getvalue()
示例2: test_plugin_with_no_sys_info
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def test_plugin_with_no_sys_info(self):
self.make_file(
"plugin_no_sys_info.py",
"""\
import coverage
class Plugin(coverage.CoveragePlugin):
pass
def coverage_init(reg, options):
reg.add_noop(Plugin())
""",
)
debug_out = StringIO()
cov = coverage.Coverage(debug=["sys"])
cov._debug_file = debug_out
cov.config["run:plugins"] = ["plugin_no_sys_info"]
cov.load()
out_lines = debug_out.getvalue().splitlines()
expected_end = [
"-- sys: plugin_no_sys_info.Plugin ----------------------------",
"-- end -------------------------------------------------------",
]
self.assertEqual(expected_end, out_lines[-len(expected_end) :])
示例3: pretend_to_be_pytestcov
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def pretend_to_be_pytestcov(self, append):
"""Act like pytest-cov."""
self.make_file("prog.py", """\
a = 1
b = 2
if b == 1:
c = 4
""")
self.make_file(".coveragerc", """\
[run]
parallel = True
source = .
""")
cov = coverage.Coverage(source=None, branch=None, config_file='.coveragerc')
if append:
cov.load()
else:
cov.erase()
self.start_import_stop(cov, "prog")
cov.combine()
cov.save()
report = StringIO()
cov.report(show_missing=None, ignore_errors=True, file=report, skip_covered=None)
self.assertEqual(report.getvalue(), textwrap.dedent("""\
Name Stmts Miss Cover
-----------------------------
prog.py 4 1 75%
"""))
self.assert_file_count(".coverage", 0)
self.assert_file_count(".coverage.*", 1)
示例4: test_plugin_with_no_sys_info
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def test_plugin_with_no_sys_info(self):
self.make_file("plugin_no_sys_info.py", """\
import coverage
class Plugin(coverage.CoveragePlugin):
pass
def coverage_init(reg, options):
reg.add_configurer(Plugin())
""")
debug_out = StringIO()
cov = coverage.Coverage(debug=["sys"])
cov._debug_file = debug_out
cov.set_option("run:plugins", ["plugin_no_sys_info"])
cov.start()
cov.stop() # pragma: nested
out_lines = [line.strip() for line in debug_out.getvalue().splitlines()]
self.assertIn('plugins.file_tracers: -none-', out_lines)
self.assertIn('plugins.configurers: plugin_no_sys_info.Plugin', out_lines)
expected_end = [
"-- sys: plugin_no_sys_info.Plugin ----------------------------",
"-- end -------------------------------------------------------",
]
self.assertEqual(expected_end, out_lines[-len(expected_end):])
示例5: test_plugin_sys_info
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def test_plugin_sys_info(self):
self.make_file(
"plugin_sys_info.py",
"""\
import coverage
class Plugin(coverage.CoveragePlugin):
def sys_info(self):
return [("hello", "world")]
def coverage_init(reg, options):
reg.add_noop(Plugin())
""",
)
debug_out = StringIO()
cov = coverage.Coverage(debug=["sys"])
cov._debug_file = debug_out
cov.set_option("run:plugins", ["plugin_sys_info"])
cov.load()
out_lines = debug_out.getvalue().splitlines()
expected_end = [
"-- sys: plugin_sys_info.Plugin -------------------------------",
" hello: world",
"-- end -------------------------------------------------------",
]
self.assertEqual(expected_end, out_lines[-len(expected_end) :])
示例6: get_report
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def get_report(self, cov):
"""Get the report from `cov`, and canonicalize it."""
repout = StringIO()
cov.report(file=repout, show_missing=False)
report = repout.getvalue().replace('\\', '/')
report = re.sub(r" +", " ", report)
return report
示例7: coverage_usepkgs
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def coverage_usepkgs(self, **kwargs):
"""Try coverage.report()."""
cov = coverage.coverage()
cov.start()
import usepkgs # pragma: nested # pylint: disable=F0401,W0612
cov.stop() # pragma: nested
report = StringIO()
cov.report(file=report, **kwargs)
return report.getvalue()
示例8: coverage_usepkgs
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def coverage_usepkgs(self, **kwargs):
"""Try coverage.report()."""
cov = coverage.Coverage()
cov.start()
import usepkgs # pragma: nested # pylint: disable=import-error,unused-variable
cov.stop() # pragma: nested
report = StringIO()
cov.report(file=report, **kwargs)
return report.getvalue()
示例9: test_defer_to_python
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def test_defer_to_python(self):
# A plugin that measures, but then wants built-in python reporting.
self.make_file(
"fairly_odd_plugin.py",
"""\
# A plugin that claims all the odd lines are executed, and none of
# the even lines, and then punts reporting off to the built-in
# Python reporting.
import coverage.plugin
class Plugin(coverage.CoveragePlugin):
def file_tracer(self, filename):
return OddTracer(filename)
def file_reporter(self, filename):
return "python"
class OddTracer(coverage.plugin.FileTracer):
def __init__(self, filename):
self.filename = filename
def source_filename(self):
return self.filename
def line_number_range(self, frame):
lineno = frame.f_lineno
if lineno % 2:
return (lineno, lineno)
else:
return (-1, -1)
def coverage_init(reg, options):
reg.add_file_tracer(Plugin())
""",
)
self.make_file(
"unsuspecting.py",
"""\
a = 1
b = 2
c = 3
d = 4
e = 5
f = 6
""",
)
cov = coverage.Coverage(include=["unsuspecting.py"])
cov.set_option("run:plugins", ["fairly_odd_plugin"])
self.start_import_stop(cov, "unsuspecting")
repout = StringIO()
total = cov.report(file=repout)
report = repout.getvalue().splitlines()
expected = [
"Name Stmts Miss Cover Missing",
"-----------------------------------------------",
"unsuspecting.py 6 3 50% 2, 4, 6",
]
self.assertEqual(report, expected)
self.assertEqual(total, 50)
示例10: get_summary_text
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def get_summary_text(self, coverage_data, options):
"""Get text output from the SummaryReporter."""
cov = Coverage()
cov.start()
cov.stop() # pragma: nested
cov.data = coverage_data
printer = SummaryReporter(cov, options)
destination = StringIO()
printer.report([], destination)
return destination.getvalue()
示例11: test_report_file
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def test_report_file(self):
# The file= argument of coverage.report makes the report go there.
self.do_report_work("mycode3")
fout = StringIO()
coverage.report(["mycode3.py"], file=fout)
self.assertEqual(self.stdout(), "")
self.assertEqual(fout.getvalue(), textwrap.dedent("""\
Name Stmts Miss Cover Missing
------------------------------------------
mycode3.py 7 3 57% 4-6
"""))
示例12: test_empty_files
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def test_empty_files(self):
# Shows that empty files like __init__.py are listed as having zero
# statements, not one statement.
cov = coverage.Coverage()
cov.start()
import usepkgs # pragma: nested # pylint: disable=import-error,unused-variable
cov.stop() # pragma: nested
repout = StringIO()
cov.report(file=repout, show_missing=False)
report = repout.getvalue().replace('\\', '/')
report = re.sub(r"\s+", " ", report)
self.assertIn("tests/modules/pkg1/__init__.py 1 0 100%", report)
self.assertIn("tests/modules/pkg2/__init__.py 0 0 100%", report)
示例13: test_empty_files
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def test_empty_files(self):
# Shows that empty files like __init__.py are listed as having zero
# statements, not one statement.
cov = coverage.coverage()
cov.start()
import usepkgs # pylint: disable=F0401,W0612
cov.stop()
repout = StringIO()
cov.report(file=repout, show_missing=False)
report = repout.getvalue().replace('\\', '/')
report = re.sub(r"\s+", " ", report)
self.assert_("test/modules/pkg1/__init__ 1 0 100%" in report)
self.assert_("test/modules/pkg2/__init__ 0 0 100%" in report)
示例14: get_summary_text
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def get_summary_text(self, options):
"""Get text output from the SummaryReporter."""
self.make_rigged_file("file1.py", 339, 155)
self.make_rigged_file("file2.py", 13, 3)
self.make_rigged_file("file3.py", 234, 228)
self.make_file("doit.py", "import file1, file2, file3")
cov = Coverage(source=["."], omit=["doit.py"])
cov.start()
import doit # pragma: nested # pylint: disable=import-error, unused-import
cov.stop() # pragma: nested
printer = SummaryReporter(cov, options)
destination = StringIO()
printer.report([], destination)
return destination.getvalue()
示例15: f1_debug_output
# 需要导入模块: from coverage.backward import StringIO [as 别名]
# 或者: from coverage.backward.StringIO import getvalue [as 别名]
def f1_debug_output(self, debug):
"""Runs some code with `debug` option, returns the debug output."""
# Make code to run.
self.make_file("f1.py", """\
def f1(x):
return x+1
for i in range(5):
f1(i)
""")
debug_out = StringIO()
cov = coverage.Coverage(debug=debug)
cov._debug_file = debug_out
self.start_import_stop(cov, "f1")
out_lines = debug_out.getvalue().splitlines()
return out_lines