summaryrefslogtreecommitdiff
path: root/tests/test_debug.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2013-09-12 07:32:21 -0400
committerNed Batchelder <ned@nedbatchelder.com>2013-09-12 07:32:21 -0400
commitb638afe3a6bf28b5a0d9e3d52079cbb6d96ae69c (patch)
tree9550228c78f7ef0ca33ecc2a98c1953575cdafd7 /tests/test_debug.py
parentcdbdcb48ee378234cf269ea87dbd314db4bea66e (diff)
downloadpython-coveragepy-b638afe3a6bf28b5a0d9e3d52079cbb6d96ae69c.tar.gz
Tests for debug tracing features.
Diffstat (limited to 'tests/test_debug.py')
-rw-r--r--tests/test_debug.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/test_debug.py b/tests/test_debug.py
index f3ae31f..0132c1c 100644
--- a/tests/test_debug.py
+++ b/tests/test_debug.py
@@ -1,5 +1,10 @@
"""Tests of coverage/debug.py"""
+import os
+import re
+
+import coverage
+from coverage.backward import StringIO
from coverage.debug import info_formatter
from tests.coveragetest import CoverageTest
@@ -23,3 +28,86 @@ class InfoFormatterTest(CoverageTest):
' jkl',
' nothing: -none-',
])
+
+
+class DebugTraceTest(CoverageTest):
+ """Tests of debug output."""
+
+ 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, debug_file=debug_out)
+ self.start_import_stop(cov, "f1")
+
+ out_lines = debug_out.getvalue().splitlines()
+ return out_lines
+
+ def test_debug_no_trace(self):
+ out_lines = self.f1_debug_output([])
+
+ # We should have no output at all.
+ self.assertFalse(out_lines)
+
+ def test_debug_trace(self):
+ out_lines = self.f1_debug_output(["trace"])
+
+ # We should have a line like "Tracing 'f1.py'"
+ self.assertIn("Tracing 'f1.py'", out_lines)
+
+ # We should lines like "Not tracing 'collector.py'..."
+ coverage_lines = lines_matching(
+ out_lines,
+ r"^Not tracing .*: is part of coverage.py$"
+ )
+ self.assertTrue(coverage_lines)
+
+ def test_debug_trace_pid(self):
+ out_lines = self.f1_debug_output(["trace", "pid"])
+
+ # Now our lines are always prefixed with the process id.
+ pid_prefix = "^pid %5d: " % os.getpid()
+ pid_lines = lines_matching(out_lines, pid_prefix)
+ self.assertEqual(pid_lines, out_lines)
+
+ # We still have some tracing, and some not tracing.
+ self.assertTrue(lines_matching(out_lines, pid_prefix + "Tracing "))
+ self.assertTrue(lines_matching(out_lines, pid_prefix + "Not tracing "))
+
+ def test_debug_config(self):
+ out_lines = self.f1_debug_output(["config"])
+
+ labels = """
+ attempted_config_files branch config_files cover_pylib data_file
+ debug exclude_list extra_css html_dir html_title ignore_errors
+ include omit parallel partial_always_list partial_list paths
+ precision show_missing source timid xml_output
+ """.split()
+ for label in labels:
+ label_pat = r"^\s*%s: " % label
+ self.assertEqual(len(lines_matching(out_lines, label_pat)), 1)
+
+ def test_debug_sys(self):
+ out_lines = self.f1_debug_output(["sys"])
+
+ labels = """
+ version coverage cover_dir pylib_dirs tracer config_files
+ configs_read data_path python platform implementation executable
+ cwd path environment command_line cover_match pylib_match
+ """.split()
+ for label in labels:
+ label_pat = r"^\s*%s: " % label
+ self.assertEqual(len(lines_matching(out_lines, label_pat)), 1)
+
+
+def lines_matching(lines, pat):
+ """Gives the list of lines from `lines` that match `pat`."""
+ return [l for l in lines if re.search(pat, l)]