diff options
Diffstat (limited to 'tests/test_debug.py')
-rw-r--r-- | tests/test_debug.py | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/tests/test_debug.py b/tests/test_debug.py index 38f31f58..63edc84f 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -1,5 +1,5 @@ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 -# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt +# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt """Tests of coverage/debug.py""" @@ -10,9 +10,10 @@ import pytest import coverage from coverage.backward import StringIO from coverage.debug import filter_text, info_formatter, info_header, short_id, short_stack +from coverage.env import C_TRACER from tests.coveragetest import CoverageTest -from tests.helpers import re_lines +from tests.helpers import re_line, re_lines class InfoFormatterTest(CoverageTest): @@ -128,24 +129,29 @@ class DebugTraceTest(CoverageTest): def test_debug_callers(self): out_lines = self.f1_debug_output(["pid", "dataop", "dataio", "callers"]) print(out_lines) - # For every real message, there should be a stack - # trace with a line like "f1_debug_output : /Users/ned/coverage/tests/test_debug.py @71" + # For every real message, there should be a stack trace with a line like + # "f1_debug_output : /Users/ned/coverage/tests/test_debug.py @71" real_messages = re_lines(out_lines, r" @\d+", match=False).splitlines() frame_pattern = r"\s+f1_debug_output : .*tests[/\\]test_debug.py @\d+$" frames = re_lines(out_lines, frame_pattern).splitlines() self.assertEqual(len(real_messages), len(frames)) # The last message should be "Writing data", and the last frame should - # be write_file in data.py. - self.assertRegex(real_messages[-1], r"^\s*\d+\.\w{4}: Writing data") + # be _write_file in data.py. last_line = out_lines.splitlines()[-1] - self.assertRegex(last_line, r"\s+write_file : .*coverage[/\\]data.py @\d+$") + from coverage.data import STORAGE + if STORAGE == "json": + self.assertRegex(real_messages[-1], r"^\s*\d+\.\w{4}: Writing data") + self.assertRegex(last_line, r"\s+_write_file : .*coverage[/\\]data.py @\d+$") + else: + self.assertRegex(real_messages[-1], r"^\s*\d+\.\w{4}: Adding lines") + self.assertRegex(last_line, r"\s+add_lines : .*coverage[/\\]sqldata.py @\d+$") def test_debug_config(self): out_lines = self.f1_debug_output(["config"]) labels = """ - attempted_config_files branch config_files cover_pylib data_file + attempted_config_files branch config_files_read config_file cover_pylib data_file debug exclude_list extra_css html_dir html_title ignore_errors run_include run_omit parallel partial_always_list partial_list paths precision show_missing source timid xml_output @@ -155,16 +161,17 @@ class DebugTraceTest(CoverageTest): label_pat = r"^\s*%s: " % label self.assertEqual( len(re_lines(out_lines, label_pat).splitlines()), - 1 + 1, + msg="Incorrect lines for %r" % label, ) def test_debug_sys(self): out_lines = self.f1_debug_output(["sys"]) labels = """ - version coverage cover_paths pylib_paths tracer config_files - configs_read data_path python platform implementation executable - cwd path environment command_line cover_match pylib_match + version coverage cover_paths pylib_paths tracer configs_attempted config_file + configs_read data_file python platform implementation executable + pid cwd path environment command_line cover_match pylib_match """.split() for label in labels: label_pat = r"^\s*%s: " % label @@ -174,6 +181,15 @@ class DebugTraceTest(CoverageTest): msg="Incorrect lines for %r" % label, ) + def test_debug_sys_ctracer(self): + out_lines = self.f1_debug_output(["sys"]) + tracer_line = re_line(out_lines, r"CTracer:").strip() + if C_TRACER: + expected = "CTracer: available" + else: + expected = "CTracer: unavailable" + self.assertEqual(tracer_line, expected) + def f_one(*args, **kwargs): """First of the chain of functions for testing `short_stack`.""" |