summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/cmdline.py10
-rw-r--r--coverage/data.py2
-rw-r--r--tests/test_cmdline.py101
3 files changed, 44 insertions, 69 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 1a8a0268..7d014902 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -586,17 +586,17 @@ class CoverageScript(object):
print(" %s" % line)
elif info == 'data':
self.coverage.load()
+ data = self.coverage.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.line_counts(fullpath=True)
+ print("path: %s" % self.coverage.data_files.filename)
+ print("has_arcs: %r" % data.has_arcs())
+ summary = data.line_counts(fullpath=True)
if summary:
- plugins = self.coverage.data.plugin_data()
filenames = sorted(summary.keys())
print("\n%d files:" % len(filenames))
for f in filenames:
line = "%s: %d lines" % (f, summary[f])
- plugin = plugins.get(f)
+ plugin = data.plugin_name(f)
if plugin:
line += " [%s]" % plugin
print(line)
diff --git a/coverage/data.py b/coverage/data.py
index be34da1b..be9ceba6 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -229,8 +229,6 @@ class CoverageData(object):
lines. If `fullpath` is true, then the keys are the full pathnames of
the files, otherwise they are the basenames of the files.
- This is used for testing, not for actual use in the product.
-
Returns:
dict mapping filenames to counts of lines.
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index d73e413e..36a16fb6 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -11,6 +11,7 @@ import mock
import coverage
import coverage.cmdline
from coverage.config import CoverageConfig
+from coverage.data import CoverageData, CoverageDataFiles
from coverage.misc import ExceptionDuringRun
from tests.coveragetest import CoverageTest, OK, ERR
@@ -139,38 +140,6 @@ class BaseCmdLineTestTest(BaseCmdLineTest):
self.cmd_executes_same("run", "debug")
-class FakeCoverageForDebugData(object):
- """Just enough of a fake coverage package for the 'debug data' tests."""
- def __init__(self, line_counts, plugin_data=None):
- self._line_counts = line_counts
- self._plugin_data = plugin_data or {}
- self.filename = "FILENAME"
- self.data = self
-
- # package members
- def coverage(self, *unused_args, **unused_kwargs):
- """The coverage class in the package."""
- return self
-
- # coverage methods
- def load(self):
- """Fake coverage().load()"""
- pass
-
- # data methods
- def has_arcs(self):
- """Fake coverage().data.has_arcs()"""
- return False
-
- def line_counts(self, fullpath): # pylint: disable=unused-argument
- """Fake coverage().data.line_counts()"""
- return self._line_counts
-
- def plugin_data(self):
- """Fake coverage().data.plugin_data()"""
- return self._plugin_data
-
-
class CmdLineTest(BaseCmdLineTest):
"""Tests of the coverage.py command line."""
@@ -232,36 +201,6 @@ class CmdLineTest(BaseCmdLineTest):
self.cmd_help("debug", "What information would you like: data, sys?")
self.cmd_help("debug foo", "Don't know what you mean by 'foo'")
- def test_debug_data(self):
- fake = FakeCoverageForDebugData(
- line_counts={
- 'file1.py': 17, 'file2.py': 23,
- },
- plugin_data={
- 'file1.py': 'a_plugin',
- },
- )
- self.command_line("debug data", _covpkg=fake)
- self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
- -- data ------------------------------------------------------
- path: FILENAME
- has_arcs: False
-
- 2 files:
- file1.py: 17 lines [a_plugin]
- file2.py: 23 lines
- """))
-
- def test_debug_data_with_no_data(self):
- fake = FakeCoverageForDebugData(line_counts={})
- self.command_line("debug data", _covpkg=fake)
- self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
- -- data ------------------------------------------------------
- path: FILENAME
- has_arcs: False
- No data collected
- """))
-
def test_debug_sys(self):
self.command_line("debug sys")
out = self.stdout()
@@ -575,6 +514,44 @@ class CmdLineTest(BaseCmdLineTest):
self.cmd_help("xyzzy", "Unknown command: 'xyzzy'")
+class CmdLineWithFilesTest(BaseCmdLineTest):
+ """Test the command line in ways that need temp files."""
+
+ run_in_temp_dir = True
+ no_files_in_temp_dir = True
+
+ def test_debug_data(self):
+ data = CoverageData()
+ data.add_lines({
+ "file1.py": dict.fromkeys(range(1, 18)),
+ "file2.py": dict.fromkeys(range(1, 24)),
+ })
+ data.add_plugins({"file1.py": "a_plugin"})
+ data_files = CoverageDataFiles()
+ data_files.write(data)
+
+ self.command_line("debug data")
+ self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
+ -- data ------------------------------------------------------
+ path: FILENAME
+ has_arcs: False
+
+ 2 files:
+ file1.py: 17 lines [a_plugin]
+ file2.py: 23 lines
+ """).replace("FILENAME", data_files.filename))
+
+ def test_debug_data_with_no_data(self):
+ data_files = CoverageDataFiles()
+ self.command_line("debug data")
+ self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
+ -- data ------------------------------------------------------
+ path: FILENAME
+ has_arcs: False
+ No data collected
+ """).replace("FILENAME", data_files.filename))
+
+
class CmdLineStdoutTest(BaseCmdLineTest):
"""Test the command line with real stdout output."""