diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-12-01 16:57:15 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-12-01 16:57:15 -0500 |
commit | b9c082a8e8f1661c2a152c1db85e658bf98412cc (patch) | |
tree | a2daffbc54471685414dab1e2ad28349db3d0943 | |
parent | b6c24ae9d590c387419c8bc192f92db983b7a29e (diff) | |
download | python-coveragepy-b9c082a8e8f1661c2a152c1db85e658bf98412cc.tar.gz |
A bunch of tweaks to improve coverage
-rw-r--r-- | metacov.ini | 3 | ||||
-rw-r--r-- | test/farm/run/run_timid.py | 27 | ||||
-rw-r--r-- | test/test_api.py | 12 | ||||
-rw-r--r-- | test/test_cmdline.py | 8 | ||||
-rw-r--r-- | test/test_farm.py | 17 | ||||
-rw-r--r-- | test/test_html.py | 4 | ||||
-rw-r--r-- | test/test_process.py | 7 | ||||
-rw-r--r-- | test/test_summary.py | 12 |
8 files changed, 61 insertions, 29 deletions
diff --git a/metacov.ini b/metacov.ini index 701a2a0..0d9eca1 100644 --- a/metacov.ini +++ b/metacov.ini @@ -15,6 +15,9 @@ exclude_lines = if __name__ == .__main__.: raise AssertionError +partial_branches = + # pragma: part covered + omit = mock.py ignore_errors = true precision = 1 diff --git a/test/farm/run/run_timid.py b/test/farm/run/run_timid.py index f63ef63..64be581 100644 --- a/test/farm/run/run_timid.py +++ b/test/farm/run/run_timid.py @@ -2,21 +2,31 @@ # function for a simpler one. # # This is complicated by the fact that the tests are run twice for each -# version: once with a compiled C-based trace function, and once without it, to -# also test the Python trace function. So this test has to examine an -# environment variable set in igor.py to know whether to expect to see the C -# trace function or not. +# version: once with a compiled C-based trace function, and once without +# it, to also test the Python trace function. So this test has to examine +# an environment variable set in igor.py to know whether to expect to see +# the C trace function or not. import os +# When meta-coverage testing, this test doesn't work, because it finds +# coverage.py's own trace function. +if os.environ.get('COVERAGE_COVERAGE', ''): + skip("Can't test timid during coverage measurement.") + copy("src", "out") run(""" + python showtrace.py none coverage -e -x showtrace.py regular coverage -e -x --timid showtrace.py timid """, rundir="out", outfile="showtraceout.txt") +# When running without coverage, no trace function # When running timidly, the trace function is always Python. -contains("out/showtraceout.txt", "timid PyTracer") +contains("out/showtraceout.txt", + "none None", + "timid PyTracer", + ) if os.environ.get('COVERAGE_TEST_TRACER', 'c') == 'c': # If the C trace function is being tested, then regular running should have @@ -37,9 +47,10 @@ run(""" """, rundir="out", outfile="showtraceout.txt") contains("out/showtraceout.txt", - "timid PyTracer", - "regular PyTracer" - ) + "none None", + "timid PyTracer", + "regular PyTracer", + ) if old_opts: os.environ['COVERAGE_OPTIONS'] = old_opts diff --git a/test/test_api.py b/test/test_api.py index 6a394f0..dcd046b 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -403,8 +403,8 @@ class SourceOmitIncludeTest(OmitIncludeTestsMixin, CoverageTest): """ cov = coverage.coverage(**kwargs) cov.start() - import usepkgs # pylint: disable=F0401,W0612 - cov.stop() + import usepkgs # pragma: not covered # pylint: disable=F0401,W0612 + cov.stop() # pragma: not covered cov._harvest_data() # private! sshhh... summary = cov.data.summary() for k, v in list(summary.items()): @@ -432,8 +432,8 @@ class ReportIncludeOmitTest(OmitIncludeTestsMixin, CoverageTest): """Try coverage.report().""" cov = coverage.coverage() cov.start() - import usepkgs # pylint: disable=F0401,W0612 - cov.stop() + import usepkgs # pragma: not covered # pylint: disable=F0401,W0612 + cov.stop() # pragma: not covered report = StringIO() cov.report(file=report, **kwargs) return report.getvalue() @@ -451,8 +451,8 @@ class XmlIncludeOmitTest(OmitIncludeTestsMixin, CoverageTest): """Try coverage.xml_report().""" cov = coverage.coverage() cov.start() - import usepkgs # pylint: disable=F0401,W0612 - cov.stop() + import usepkgs # pragma: not covered # pylint: disable=F0401,W0612 + cov.stop() # pragma: not covered cov.xml_report(outfile="-", **kwargs) return self.stdout() diff --git a/test/test_cmdline.py b/test/test_cmdline.py index eb7fe0f..0fd92de 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -91,6 +91,14 @@ class CmdLineTest(CoverageTest): ) +class CmdLineTestTest(CmdLineTest): + """Tests that our CmdLineTest helpers work.""" + def test_assert_same_method_calls(self): + # All the other tests here use self.cmd_executes_same in successful + # ways, so here we just check that it fails. + self.assertRaises(AssertionError, self.cmd_executes_same, "-e", "-c") + + class ClassicCmdLineTest(CmdLineTest): """Tests of the classic coverage.py command line.""" diff --git a/test/test_farm.py b/test/test_farm.py index 0903a76..1576dfe 100644 --- a/test/test_farm.py +++ b/test/test_farm.py @@ -1,6 +1,7 @@ """Run tests in the farm subdirectory. Designed for nose.""" import difflib, filecmp, fnmatch, glob, os, re, shutil, sys +from nose.plugins.skip import SkipTest sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k from backtest import run_command, execfile # pylint: disable=W0622 @@ -67,13 +68,15 @@ class FarmTestCase(object): cwd = self.cd(self.dir) # Prepare a dictionary of globals for the run.py files to use. - fns = "copy run runfunc compare contains doesnt_contain clean".split() + fns = """ + copy run runfunc compare contains doesnt_contain clean skip + """.split() if self.clean_only: glo = dict([(fn, self.noop) for fn in fns]) glo['clean'] = self.clean else: glo = dict([(fn, getattr(self, fn)) for fn in fns]) - if self.dont_clean: + if self.dont_clean: # pragma: not covered glo['clean'] = self.noop old_mods = dict(sys.modules) @@ -116,7 +119,7 @@ class FarmTestCase(object): def tearDown(self): """Test tear down, run by nose after __call__.""" # Make sure no matter what, the test is cleaned up. - if not self.dont_clean: + if not self.dont_clean: # pragma: part covered self.clean_only = True self() @@ -303,11 +306,11 @@ class FarmTestCase(object): # I've seen it take over 100 tries, so, 1000! This is probably the # most unpleasant hack I've written in a long time... tries = 1000 - while tries: + while tries: # pragma: part covered if os.path.exists(cleandir): try: shutil.rmtree(cleandir) - except OSError: + except OSError: # pragma: not covered if tries == 1: raise else: @@ -315,6 +318,10 @@ class FarmTestCase(object): continue break + def skip(self, msg=None): + """Skip the current test.""" + raise SkipTest(msg) + def main(): # pragma: not covered """Command-line access to test_farm. diff --git a/test/test_html.py b/test/test_html.py index fd6ebc4..13399e8 100644 --- a/test/test_html.py +++ b/test/test_html.py @@ -123,11 +123,11 @@ class HtmlDeltaTest(HtmlTestHelpers, CoverageTest): # In this case, everything changes because the coverage settings have # changed. self.create_initial_files() - self.run_coverage(covargs=dict(timid=False)) + self.run_coverage(covargs=dict(omit=[])) index1 = open("htmlcov/index.html").read() self.remove_html_files() - self.run_coverage(covargs=dict(timid=True)) + self.run_coverage(covargs=dict(omit=['xyzzy*'])) # All the files have been reported again. self.assert_exists("htmlcov/index.html") diff --git a/test/test_process.py b/test/test_process.py index 2d92603..27f2cf2 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -369,8 +369,11 @@ class ProcessTest(CoverageTest): self.assertNotIn("Exception", out) if sys.version_info >= (3, 0): # This only works on 3.x for now. - # It only works with the C tracer. - if os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c': + # It only works with the C tracer, + c_tracer = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' + # and if we aren't measuring ourselves. + metacov = os.getenv('COVERAGE_COVERAGE', '') != '' + if c_tracer and not metacov: # pragma: not covered def test_fullcoverage(self): # fullcoverage is a trick to get stdlib modules measured from # the very beginning of the process. Here we import os and diff --git a/test/test_summary.py b/test/test_summary.py index e4d5e54..f3651ed 100644 --- a/test/test_summary.py +++ b/test/test_summary.py @@ -201,8 +201,8 @@ class SummaryTest(CoverageTest): """) cov = coverage.coverage(branch=True, source=["."]) cov.start() - import main # pylint: disable=F0401,W0612 - cov.stop() + import main # pragma: not covered # pylint: disable=F0401,W0612 + cov.stop() # pragma: not covered report = self.get_report(cov).splitlines() self.assertIn("mybranch 5 5 2 2 0%", report) @@ -210,8 +210,8 @@ class SummaryTest(CoverageTest): """A helper for the next few tests.""" cov = coverage.coverage() cov.start() - import TheCode # pylint: disable=F0401,W0612 - cov.stop() + import TheCode # pragma: not covered # pylint: disable=F0401,W0612 + cov.stop() # pragma: not covered return self.get_report(cov) def test_bug_203_mixed_case_listed_twice_with_rc(self): @@ -252,8 +252,8 @@ class SummaryTest2(CoverageTest): # statements, not one statement. cov = coverage.coverage() cov.start() - import usepkgs # pylint: disable=F0401,W0612 - cov.stop() + import usepkgs # pragma: not covered # pylint: disable=F0401,W0612 + cov.stop() # pragma: not covered repout = StringIO() cov.report(file=repout, show_missing=False) |