diff options
-rw-r--r-- | coverage/cmdline.py | 1 | ||||
-rw-r--r-- | test/coveragetest.py | 7 | ||||
-rw-r--r-- | test/test_cmdline.py | 52 |
3 files changed, 57 insertions, 3 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index e71b1d1e..c530cfb9 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -2,6 +2,7 @@ import optparse, re, sys +from coverage.backward import sorted # pylint: disable-msg=W0622 from coverage.execfile import run_python_file from coverage.misc import CoverageException diff --git a/test/coveragetest.py b/test/coveragetest.py index 603c685c..ee440f30 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -253,7 +253,7 @@ class CoverageTest(TestCase): fname = os.path.join(*fparts) return os.path.normcase(os.path.abspath(os.path.realpath(fname))) - def command_line(self, args, ret=OK): + def command_line(self, args, ret=OK, _covpkg=None): """Run `args` through the command line. Use this when you want to run the full coverage machinery, but in the @@ -265,11 +265,12 @@ class CoverageTest(TestCase): Returns None. """ - ret_actual = coverage.CoverageScript().command_line(shlex.split(args)) + script = coverage.CoverageScript(_covpkg=_covpkg) + ret_actual = script.command_line(shlex.split(args)) self.assertEqual(ret_actual, ret) def run_command(self, cmd): - """ Run the command-line `cmd` in a subprocess, and print its output. + """Run the command-line `cmd` in a subprocess, and print its output. Use this when you need to test the process behavior of coverage. diff --git a/test/test_cmdline.py b/test/test_cmdline.py index f06e8149..fda282bb 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -325,6 +325,33 @@ class ClassicCmdLineTest(CmdLineTest): self.cmd_help("-z", "no such option: -z") +class FakeCoverageForDebugData(object): + """Just enough of a fake coverage package for the 'debug data' tests.""" + def __init__(self, summary): + self._summary = summary + 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 summary(self, fullpath): # pylint: disable-msg=W0613 + """Fake coverage().data.summary()""" + return self._summary + + class NewCmdLineTest(CmdLineTest): """Tests of the coverage.py command line.""" @@ -344,6 +371,31 @@ class NewCmdLineTest(CmdLineTest): 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 testDebugData(self): + fake = FakeCoverageForDebugData({ + 'file1.py': 17, 'file2.py': 23, + }) + 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 + file2.py: 23 lines + """)) + + def testDebugDataWithNoData(self): + fake = FakeCoverageForDebugData({}) + self.command_line("debug data", _covpkg=fake) + self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\ + -- data --------------------------------------- + path: FILENAME + has_arcs: False + No data collected + """)) + def testDebugSys(self): self.command_line("debug sys") out = self.stdout() |