Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_plugin2_with_text_report(self):
self.make_render_and_caller()
cov = coverage.Coverage(branch=True, omit=["*quux*"])
cov.set_option("run:plugins", ["tests.plugin2"])
self.start_import_stop(cov, "caller")
repout = StringIO()
total = cov.report(file=repout, include=["*.html"], omit=["uni*.html"], show_missing=True)
report = repout.getvalue().splitlines()
expected = [
'Name Stmts Miss Branch BrPart Cover Missing',
'--------------------------------------------------------',
'bar_4.html 4 2 0 0 50% 1, 4',
'foo_7.html 7 5 0 0 29% 1-3, 6-7',
'--------------------------------------------------------',
'TOTAL 11 7 0 0 36%',
]
self.assertEqual(expected, report)
self.assertAlmostEqual(total, 36.36, places=2)
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")
cov.save()
out_lines = debug_out.getvalue()
return out_lines
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
""")
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,
skip_empty=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)
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.
old_stdout = sys.stdout
self.captured_stdout = StringIO()
sys.stdout = Tee(sys.stdout, self.captured_stdout)
old_stderr = sys.stderr
self.captured_stderr = StringIO()
sys.stderr = self.captured_stderr
self.addCleanup(self.cleanup_std_streams, old_stdout, old_stderr)
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()
The arguments are tuples: (name, value) for Coverage.set_option.
"""
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
for name, value in options:
cov.set_option(name, value)
printer = SummaryReporter(cov)
destination = StringIO()
printer.report([], destination)
return destination.getvalue()
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