diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-03 21:25:02 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-03 21:25:02 -0400 |
commit | f1491bdf248bc8bd073a1ae061757d7bfd787e79 (patch) | |
tree | ec00b77d21ec3030b04abb44ecc3d08b0513703e /tests/test_cmdline.py | |
parent | 17cc353d4359b2481fc9e6234c1fc5e8ba42a4ae (diff) | |
download | python-coveragepy-f1491bdf248bc8bd073a1ae061757d7bfd787e79.tar.gz |
Fix --append trying to make a new file. #392
Diffstat (limited to 'tests/test_cmdline.py')
-rw-r--r-- | tests/test_cmdline.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 3baa262..4c54088 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -63,30 +63,33 @@ class BaseCmdLineTest(CoverageTest): return mk - def mock_command_line(self, args): + def mock_command_line(self, args, path_exists=None): """Run `args` through the command line, with a Mock. Returns the Mock it used and the status code returned. """ m = self.model_object() + m.path_exists.return_value = path_exists + 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 + _run_python_module=m.run_python_module, _help_fn=m.help_fn, + _path_exists=m.path_exists, ).command_line(shlex.split(args)) + return m, ret - def cmd_executes(self, args, code, ret=OK): + def cmd_executes(self, args, code, ret=OK, path_exists=None): """Assert that the `args` end up executing the sequence in `code`.""" - m1, r1 = self.mock_command_line(args) - self.assertEqual( - r1, ret, "Wrong status: got %s, wanted %s" % (r1, ret) - ) + m1, r1 = self.mock_command_line(args, path_exists=path_exists) + self.assertEqual(r1, ret, "Wrong status: got %r, wanted %r" % (r1, ret)) # Remove all indentation, and change ".foo()" to "m2.foo()". code = re.sub(r"(?m)^\s+", "", code) code = re.sub(r"(?m)^\.", "m2.", code) m2 = self.model_object() + m2.path_exists.return_value = path_exists code_obj = compile(code, "<code>", "exec") eval(code_obj, globals(), { 'm2': m2 }) # pylint: disable=eval-used @@ -351,15 +354,25 @@ class CmdLineTest(BaseCmdLineTest): .stop() .save() """) - # run -a calls coverage.load first without erasing. + # run -a combines with an existing data file before saving. self.cmd_executes("run -a foo.py", """\ .coverage() .start() .run_python_file('foo.py', ['foo.py']) .stop() + .path_exists('.coverage') .combine(data_paths=['.coverage']) .save() - """) + """, path_exists=True) + # run -a doesn't combine anything if the data file doesn't exist. + self.cmd_executes("run -a foo.py", """\ + .coverage() + .start() + .run_python_file('foo.py', ['foo.py']) + .stop() + .path_exists('.coverage') + .save() + """, path_exists=False) # --timid sets a flag, and program arguments get passed through. self.cmd_executes("run --timid foo.py abc 123", """\ .coverage(timid=True) |