diff options
Diffstat (limited to 'tests/test_cmdline.py')
-rw-r--r-- | tests/test_cmdline.py | 143 |
1 files changed, 76 insertions, 67 deletions
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 775e0033..a379d402 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -1,4 +1,7 @@ -"""Test cmdline.py for coverage.""" +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + +"""Test cmdline.py for coverage.py.""" import pprint import re @@ -11,6 +14,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 @@ -62,7 +66,7 @@ class BaseCmdLineTest(CoverageTest): """ m = self.model_object() - ret = coverage.CoverageScript( + ret = coverage.cmdline.CoverageScript( _covpkg=m, _run_python_file=m.run_python_file, _run_python_module=m.run_python_module, _help_fn=m.help_fn ).command_line(shlex.split(args)) @@ -139,38 +143,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, summary, plugin_data=None): - self._summary = summary - 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 summary(self, fullpath): # pylint: disable=unused-argument - """Fake coverage().data.summary()""" - return self._summary - - def plugin_data(self): - """Fake coverage().data.plugin_data()""" - return self._plugin_data - - class CmdLineTest(BaseCmdLineTest): """Tests of the coverage.py command line.""" @@ -213,11 +185,33 @@ class CmdLineTest(BaseCmdLineTest): """) def test_combine(self): - # coverage combine + # coverage combine with args + self.cmd_executes("combine datadir1", """\ + .coverage() + .load() + .combine(["datadir1"]) + .save() + """) + # coverage combine without args self.cmd_executes("combine", """\ .coverage() .load() - .combine() + .combine(None) + .save() + """) + + def test_combine_doesnt_confuse_options_with_args(self): + # https://bitbucket.org/ned/coveragepy/issues/385/coverage-combine-doesnt-work-with-rcfile + self.cmd_executes("combine --rcfile cov.ini", """\ + .coverage(config_file='cov.ini') + .load() + .combine(None) + .save() + """) + self.cmd_executes("combine --rcfile cov.ini data1 data2/more", """\ + .coverage(config_file='cov.ini') + .load() + .combine(["data1", "data2/more"]) .save() """) @@ -225,36 +219,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( - summary={ - '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(summary={}) - 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() @@ -386,10 +350,10 @@ class CmdLineTest(BaseCmdLineTest): # run -a calls coverage.load first without erasing. self.cmd_executes("run -a foo.py", """\ .coverage() - .load() .start() .run_python_file('foo.py', ['foo.py']) .stop() + .combine(data_paths=['.coverage']) .save() """) # --timid sets a flag, and program arguments get passed through. @@ -518,6 +482,14 @@ class CmdLineTest(BaseCmdLineTest): """) self.cmd_executes_same("run -m mymodule", "run --module mymodule") + def test_run_nothing(self): + self.command_line("run", ret=ERR) + self.assertIn("Nothing to do", self.stdout()) + + def test_cant_append_parallel(self): + self.command_line("run --append --parallel-mode foo.py", ret=ERR) + self.assertIn("Can't append to data files in parallel mode.", self.stdout()) + def test_xml(self): # coverage xml [-i] [--omit DIR,...] [FILE1 FILE2 ...] self.cmd_executes("xml", """\ @@ -568,6 +540,43 @@ 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.set_lines({ + "file1.py": dict.fromkeys(range(1, 18)), + "file2.py": dict.fromkeys(range(1, 24)), + }) + data.set_file_tracers({"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 + No data collected + """).replace("FILENAME", data_files.filename)) + + class CmdLineStdoutTest(BaseCmdLineTest): """Test the command line with real stdout output.""" |