summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-01-24 10:28:44 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-01-24 10:28:44 -0500
commit4ddf53a6d962a001782a0838b1b8748041125be4 (patch)
treefff894b694537d9ada8e0d2a12c24847c28b8cd3
parentc1bfa7352368b63f3a9b30c02f242408d07a7ab2 (diff)
downloadpython-coveragepy-git-4ddf53a6d962a001782a0838b1b8748041125be4.tar.gz
Make the two forms of debug output more uniform
-rw-r--r--coverage/cmdline.py6
-rw-r--r--coverage/control.py12
-rw-r--r--coverage/debug.py10
-rw-r--r--tests/test_cmdline.py4
-rw-r--r--tests/test_debug.py12
5 files changed, 33 insertions, 11 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index f0160845..3b624724 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -9,7 +9,7 @@ import traceback
from coverage import env
from coverage.execfile import run_python_file, run_python_module
from coverage.misc import CoverageException, ExceptionDuringRun, NoSource
-from coverage.debug import info_formatter
+from coverage.debug import info_formatter, info_header
class Opts(object):
@@ -571,12 +571,12 @@ class CoverageScript(object):
for info in args:
if info == 'sys':
sysinfo = self.coverage.sysinfo()
- print("-- sys ----------------------------------------")
+ print(info_header("sys"))
for line in info_formatter(sysinfo):
print(" %s" % line)
elif info == 'data':
self.coverage.load()
- print("-- data ---------------------------------------")
+ print(info_header("data"))
print("path: %s" % self.coverage.data.filename)
print("has_arcs: %r" % self.coverage.data.has_arcs())
summary = self.coverage.data.summary(fullpath=True)
diff --git a/coverage/control.py b/coverage/control.py
index 36687fe5..8ae96fcf 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -293,14 +293,18 @@ class Coverage(object):
self.omit_match = FnmatchMatcher(self.omit)
# The user may want to debug things, show info if desired.
+ wrote_any = False
if self.debug.should('config'):
- self.debug.write("Configuration values:")
config_info = sorted(self.config.__dict__.items())
- self.debug.write_formatted_info(config_info)
+ self.debug.write_formatted_info("config", config_info)
+ wrote_any = True
if self.debug.should('sys'):
- self.debug.write("Debugging info:")
- self.debug.write_formatted_info(self.sysinfo())
+ self.debug.write_formatted_info("sys", self.sysinfo())
+ wrote_any = True
+
+ if wrote_any:
+ self.debug.write_formatted_info("end", ())
def _canonical_dir(self, morf):
"""Return the canonical directory of the module or file `morf`."""
diff --git a/coverage/debug.py b/coverage/debug.py
index c441dffd..74315231 100644
--- a/coverage/debug.py
+++ b/coverage/debug.py
@@ -28,12 +28,18 @@ class DebugControl(object):
self.output.write(msg+"\n")
self.output.flush()
- def write_formatted_info(self, info):
+ def write_formatted_info(self, header, info):
"""Write a sequence of (label,data) pairs nicely."""
+ self.write(info_header(header))
for line in info_formatter(info):
self.write(" %s" % line)
+def info_header(label):
+ """Make a nice header string."""
+ return "--{0:-<60s}".format(" "+label+" ")
+
+
def info_formatter(info):
"""Produce a sequence of formatted lines from info.
@@ -42,6 +48,8 @@ def info_formatter(info):
"""
info = list(info)
+ if not info:
+ return
label_len = max(len(l) for l, _d in info)
for label, data in info:
if data == []:
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 266cb957..ebf5ab59 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -229,7 +229,7 @@ class CmdLineTest(BaseCmdLineTest):
)
self.command_line("debug data", _covpkg=fake)
self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
- -- data ---------------------------------------
+ -- data ------------------------------------------------------
path: FILENAME
has_arcs: False
@@ -242,7 +242,7 @@ class CmdLineTest(BaseCmdLineTest):
fake = FakeCoverageForDebugData(summary={})
self.command_line("debug data", _covpkg=fake)
self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
- -- data ---------------------------------------
+ -- data ------------------------------------------------------
path: FILENAME
has_arcs: False
No data collected
diff --git a/tests/test_debug.py b/tests/test_debug.py
index 8aad9257..8dd13a57 100644
--- a/tests/test_debug.py
+++ b/tests/test_debug.py
@@ -5,7 +5,7 @@ import re
import coverage
from coverage.backward import StringIO
-from coverage.debug import info_formatter
+from coverage.debug import info_formatter, info_header
from tests.coveragetest import CoverageTest
@@ -35,6 +35,16 @@ class InfoFormatterTest(CoverageTest):
lines = list(info_formatter(('info%d' % i, i) for i in range(3)))
self.assertEqual(lines, ['info0: 0', 'info1: 1', 'info2: 2'])
+ def test_info_header(self):
+ self.assertEqual(
+ info_header("x"),
+ "-- x ---------------------------------------------------------"
+ )
+ self.assertEqual(
+ info_header("hello there"),
+ "-- hello there -----------------------------------------------"
+ )
+
class DebugTraceTest(CoverageTest):
"""Tests of debug output."""