diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-26 08:37:21 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-11-26 08:37:21 -0500 |
commit | 484647dc3a3d649543ebb6fcd62701fc84e0ddba (patch) | |
tree | 2abccb2a3946ce39a2bfd6596a04ce09dc812633 /test/coveragetest.py | |
parent | 0ecc4917ff57918eefb7a90e163fd4bfa9b923d4 (diff) | |
download | python-coveragepy-git-484647dc3a3d649543ebb6fcd62701fc84e0ddba.tar.gz |
When reporting, don't fall over if there's no data to report on. Fixes issue #37.
Diffstat (limited to 'test/coveragetest.py')
-rw-r--r-- | test/coveragetest.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py index dffffb29..3c22a0cf 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -1,6 +1,6 @@ """Base test case class for coverage testing.""" -import difflib, imp, os, random, re, shutil, sys, tempfile, textwrap, unittest +import difflib, imp, os, random, re, shlex, shutil, sys, tempfile, textwrap, unittest import coverage from coverage.backward import set, sorted, StringIO # pylint: disable-msg=W0622 @@ -20,6 +20,9 @@ class Tee(object): f.write(data) +# Status returns for the command line. +OK, ERR = 0, 1 + class CoverageTest(unittest.TestCase): """A base class for Coverage test cases.""" @@ -253,8 +256,30 @@ class CoverageTest(unittest.TestCase): fname = os.path.join(*fparts) return os.path.normcase(os.path.abspath(os.path.realpath(fname))) + def command_line(self, args, ret=OK): + """Run `args` through the command line. + + Use this when you want to run the full coverage machinery, but in the + current process. Exceptions may be thrown from deep in the code. + Asserts that `ret` is returned by `CoverageScript.command_line`. + + Compare with `run_command`. + + Returns None. + + """ + ret_actual = coverage.CoverageScript().command_line(shlex.split(args)) + self.assertEqual(ret_actual, ret) + def run_command(self, cmd): - """ Run the command-line `cmd`, 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. + + Compare with `command_line`. + + Returns the process' stdout text. + """ # Add our test modules directory to PYTHONPATH. I'm sure there's too # much path munging here, but... |