summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-10-26 16:08:29 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-10-26 16:08:29 -0400
commite9e969c5d733647b4bdaabf1f5e384bc79345326 (patch)
treed9430876aaada2e7afbb1880db76a55994b9862f
parent8cd2b7477b1e58cdace3ebcffc343d45a1f4b729 (diff)
downloadpython-coveragepy-e9e969c5d733647b4bdaabf1f5e384bc79345326.tar.gz
Allow the --debug switch on any command
-rw-r--r--CHANGES.txt2
-rw-r--r--coverage/cmdline.py15
-rw-r--r--coverage/control.py46
-rw-r--r--tests/test_debug.py6
4 files changed, 36 insertions, 33 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 724fe95..3338be1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -18,6 +18,8 @@ Latest
index page, and only modules with that text in the name will be shown.
Thanks, Danny Allen.
+- The ``--debug`` switch can now be used on any command.
+
- You can now programmatically adjust the configuration of coverage by setting
items on `Coverage.config` after construcion.
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 3d1f5f6..e3a09bb 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -1,6 +1,6 @@
"""Command-line support for Coverage."""
-import glob, optparse, os, sys, time, traceback
+import glob, optparse, os, sys, traceback
from coverage.execfile import run_python_file, run_python_module
from coverage.misc import CoverageException, ExceptionDuringRun, NoSource
@@ -218,8 +218,9 @@ class CmdOptionParser(CoverageOptionParser):
return (other == "<CmdOptionParser:%s>" % self.cmd)
GLOBAL_ARGS = [
- Opts.rcfile,
+ Opts.debug,
Opts.help,
+ Opts.rcfile,
]
CMDS = {
@@ -293,7 +294,6 @@ CMDS = {
Opts.append,
Opts.branch,
Opts.concurrency,
- Opts.debug,
Opts.pylib,
Opts.parallel_mode,
Opts.module,
@@ -577,12 +577,13 @@ class CoverageScript(object):
return ERR
for info in args:
if info == 'sys':
+ sysinfo = self.coverage.sysinfo()
print("-- sys ----------------------------------------")
- for line in info_formatter(self.coverage.sysinfo()):
+ for line in info_formatter(sysinfo):
print(" %s" % line)
elif info == 'data':
- print("-- data ---------------------------------------")
self.coverage.load()
+ print("-- data ---------------------------------------")
print("path: %s" % self.coverage.data.filename)
print("has_arcs: %r" % self.coverage.data.has_arcs())
summary = self.coverage.data.summary(fullpath=True)
@@ -667,11 +668,7 @@ def main(argv=None):
if argv is None:
argv = sys.argv[1:]
try:
- start = time.clock()
status = CoverageScript().command_line(argv)
- end = time.clock()
- if 0:
- print("time: %.3fs" % (end - start))
except ExceptionDuringRun as err:
# An exception was caught while running the product code. The
# sys.exc_info() return tuple is packed into an ExceptionDuringRun
diff --git a/coverage/control.py b/coverage/control.py
index 66979c3..4c08765 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -262,6 +262,29 @@ class Coverage(object):
self._inited = True
+ # Create the matchers we need for _should_trace
+ if self.source or self.source_pkgs:
+ self.source_match = TreeMatcher(self.source)
+ else:
+ if self.cover_dir:
+ self.cover_match = TreeMatcher([self.cover_dir])
+ if self.pylib_dirs:
+ self.pylib_match = TreeMatcher(self.pylib_dirs)
+ if self.include:
+ self.include_match = FnmatchMatcher(self.include)
+ if self.omit:
+ self.omit_match = FnmatchMatcher(self.omit)
+
+ # The user may want to debug things, show info if desired.
+ if self.debug.should('config'):
+ self.debug.write("Configuration values:")
+ config_info = sorted(self.config.__dict__.items())
+ self.debug.write_formatted_info(config_info)
+
+ if self.debug.should('sys'):
+ self.debug.write("Debugging info:")
+ self.debug.write_formatted_info(self.sysinfo())
+
def _canonical_dir(self, morf):
"""Return the canonical directory of the module or file `morf`."""
morf_filename = PythonCodeUnit(morf, self.file_locator).filename
@@ -495,29 +518,6 @@ class Coverage(object):
if self._auto_data:
self.load()
- # Create the matchers we need for _should_trace
- if self.source or self.source_pkgs:
- self.source_match = TreeMatcher(self.source)
- else:
- if self.cover_dir:
- self.cover_match = TreeMatcher([self.cover_dir])
- if self.pylib_dirs:
- self.pylib_match = TreeMatcher(self.pylib_dirs)
- if self.include:
- self.include_match = FnmatchMatcher(self.include)
- if self.omit:
- self.omit_match = FnmatchMatcher(self.omit)
-
- # The user may want to debug things, show info if desired.
- if self.debug.should('config'):
- self.debug.write("Configuration values:")
- config_info = sorted(self.config.__dict__.items())
- self.debug.write_formatted_info(config_info)
-
- if self.debug.should('sys'):
- self.debug.write("Debugging info:")
- self.debug.write_formatted_info(self.sysinfo())
-
self.collector.start()
self._started = True
self._measured = True
diff --git a/tests/test_debug.py b/tests/test_debug.py
index e8a8e95..d05316c 100644
--- a/tests/test_debug.py
+++ b/tests/test_debug.py
@@ -108,7 +108,11 @@ class DebugTraceTest(CoverageTest):
""".split()
for label in labels:
label_pat = r"^\s*%s: " % label
- self.assertEqual(len(lines_matching(out_lines, label_pat)), 1)
+ self.assertEqual(
+ len(lines_matching(out_lines, label_pat)),
+ 1,
+ msg="Incorrect lines for %r" % label,
+ )
def lines_matching(lines, pat):