summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-09-09 08:31:57 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-09-09 08:31:57 -0400
commit1810d5e6e911cb3dbb3e971f2cc2a081134c6ee2 (patch)
tree66e9cccf4b719e06d25356d234307b817a441f28 /test
parenta3392d5017ae8c34ad4ac41e896e6ec860e9a405 (diff)
downloadpython-coveragepy-git-1810d5e6e911cb3dbb3e971f2cc2a081134c6ee2.tar.gz
Start using Mock to test the command-line code.
Diffstat (limited to 'test')
-rw-r--r--test/test_cmdline.py51
1 files changed, 47 insertions, 4 deletions
diff --git a/test/test_cmdline.py b/test/test_cmdline.py
index 38f2121d..abe8653d 100644
--- a/test/test_cmdline.py
+++ b/test/test_cmdline.py
@@ -1,13 +1,11 @@
"""Test cmdline.py for coverage."""
-import unittest
-
+import re, shlex, textwrap, unittest
import coverage
-
from coveragetest import CoverageTest
-class CmdLineTest(CoverageTest):
+class CmdLineParserTest(CoverageTest):
"""Tests of command-line processing for Coverage."""
def help_fn(self, error=None):
@@ -65,5 +63,50 @@ class CmdLineTest(CoverageTest):
self.command_line, ['-c', 'baz', 'quux'])
+class CmdLineActionTest(CoverageTest):
+ """Tests of execution paths through the command line interpreter."""
+
+ def model_object(self):
+ """Return a Mock suitable for use in CoverageScript."""
+ import mock
+ mk = mock.Mock()
+ mk.coverage.return_value = mk
+ return mk
+
+ def cmd_executes(self, args, code):
+ """Assert that the `args` end up executing the sequence in `code`."""
+ argv = shlex.split(args)
+ m1 = self.model_object()
+
+ coverage.CoverageScript(
+ _covpkg=m1, _run_python_file=m1.run_python_file
+ ).command_line(argv)
+
+ code = textwrap.dedent(code)
+ code = re.sub(r"(?m)^\.", "m2.", code)
+ m2 = self.model_object()
+ code_obj = compile(code, "<code>", "exec")
+ eval(code_obj, globals(), { 'm2': m2 })
+ self.assertEqual(m1.method_calls, m2.method_calls)
+
+ def testExecution(self):
+ self.cmd_executes("-x foo.py", """\
+ .coverage(cover_pylib=None, data_suffix=False, timid=None)
+ .load()
+ .start()
+ .run_python_file('foo.py', ['foo.py'])
+ .stop()
+ .save()
+ """)
+ self.cmd_executes("-e -x foo.py", """\
+ .coverage(cover_pylib=None, data_suffix=False, timid=None)
+ .erase()
+ .start()
+ .run_python_file('foo.py', ['foo.py'])
+ .stop()
+ .save()
+ """)
+
+
if __name__ == '__main__':
unittest.main()