diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2011-08-03 21:17:42 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2011-08-03 21:17:42 -0400 |
commit | 06e4538fca309d796d6e8f899bcad74146a96ff3 (patch) | |
tree | bdfdecfd0366b24cddf8ae0fe51c62f3cc6186fe | |
parent | 574d041fbbbbfda3fc4fcaff65629dd04c8eaa70 (diff) | |
download | python-coveragepy-git-06e4538fca309d796d6e8f899bcad74146a96ff3.tar.gz |
You can include files in the Python installation, and they will be measured.
-rw-r--r-- | CHANGES.txt | 6 | ||||
-rw-r--r-- | coverage/control.py | 14 | ||||
-rw-r--r-- | test/test_api.py | 27 |
3 files changed, 36 insertions, 11 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index c105a071..1c08ef69 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,7 +12,13 @@ Version 3.5.1 different than the number reported on the individual file pages. This is now fixed. +- An explicit include directive to measure files in the Python installation + wouldn't work because of the standard library exclusion. Now the include + directive takes precendence, and the files will be measured. Fixes + `issue 138`_. + .. _issue 122: http://bitbucket.org/ned/coveragepy/issue/122/for-else-always-reports-missing-branch +.. _issue 138: https://bitbucket.org/ned/coveragepy/issue/138/include-should-take-precedence-over-is Version 3.5 --- 29 June 2011 diff --git a/coverage/control.py b/coverage/control.py index 5ca1ef95..4ba3a034 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -248,12 +248,16 @@ class coverage(object): canonical = self.file_locator.canonical_filename(filename) - # If the user specified source, then that's authoritative about what to - # measure. If they didn't, then we have to exclude the stdlib and - # coverage.py directories. + # If the user specified source or include, then that's authoritative + # about the outer bound of what to measure and we don't have to apply + # any canned exclusions. If they didn't, then we have to exclude the + # stdlib and coverage.py directories. if self.source_match: if not self.source_match.match(canonical): return False + elif self.include_match: + if not self.include_match.match(canonical): + return False else: # If we aren't supposed to trace installed code, then check if this # is near the Python standard library and skip it if so. @@ -265,9 +269,7 @@ class coverage(object): if self.cover_match and self.cover_match.match(canonical): return False - # Check the file against the include and omit patterns. - if self.include_match and not self.include_match.match(canonical): - return False + # Check the file against the omit pattern. if self.omit_match and self.omit_match.match(canonical): return False diff --git a/test/test_api.py b/test/test_api.py index 868a5441..48f10829 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -176,15 +176,11 @@ class ApiTest(CoverageTest): def test_ignore_stdlib(self): self.make_file("mymain.py", """\ - import mymod, colorsys + import colorsys a = 1 hls = colorsys.rgb_to_hls(1.0, 0.5, 0.0) """) - self.make_file("mymod.py", """\ - fooey = 17 - """) - # Measure without the stdlib. cov1 = coverage.coverage() self.assertEqual(cov1.config.cover_pylib, False) @@ -212,6 +208,27 @@ class ApiTest(CoverageTest): _, statements, missing, _ = cov2.analysis("colorsys.py") self.assertNotEqual(statements, missing) + def test_include_can_measure_stdlib(self): + self.make_file("mymain.py", """\ + import colorsys, random + a = 1 + r, g, b = [random.random() for _ in range(3)] + hls = colorsys.rgb_to_hls(r, g, b) + """) + + # Measure without the stdlib, but include colorsys. + cov1 = coverage.coverage(cover_pylib=False, include=["*/colorsys.py"]) + cov1.start() + self.import_local_file("mymain") # pragma: recursive coverage + cov1.stop() # pragma: recursive coverage + + # some statements were marked executed in colorsys.py + _, statements, missing, _ = cov1.analysis("colorsys.py") + self.assertNotEqual(statements, missing) + # but none were in random.py + _, statements, missing, _ = cov1.analysis("random.py") + self.assertEqual(statements, missing) + def test_exclude_list(self): cov = coverage.coverage() cov.clear_exclude() |