diff options
| author | Ned Batchelder <nedbat@gmail.com> | 2017-01-14 17:18:56 -0500 |
|---|---|---|
| committer | Ned Batchelder <nedbat@gmail.com> | 2017-01-14 17:18:56 -0500 |
| commit | 3d8e48162df541de153ee0f23f75074e2fc13376 (patch) | |
| tree | fd22302b96422e6749f8beb5d376dff03b3a66cf /tests | |
| parent | 6d24c0864b2e18fb646ddca1cefd71819b64e83d (diff) | |
| parent | d9ca8593eba371b49402974c1c1f2bf7fd52fed9 (diff) | |
| download | python-coveragepy-3d8e48162df541de153ee0f23f75074e2fc13376.tar.gz | |
Merged in dachary/coverage.py/issue-426 (pull request #122)
make --source module do the same as --source directory #426
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modules/usepkgs.py | 2 | ||||
| -rw-r--r-- | tests/test_api.py | 7 | ||||
| -rw-r--r-- | tests/test_python.py | 27 |
3 files changed, 30 insertions, 6 deletions
diff --git a/tests/modules/usepkgs.py b/tests/modules/usepkgs.py index 4e94aca..222e68c 100644 --- a/tests/modules/usepkgs.py +++ b/tests/modules/usepkgs.py @@ -1,7 +1,7 @@ # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt -import pkg1.p1a, pkg1.p1b +import pkg1.p1a, pkg1.p1b, pkg1.sub import pkg2.p2a, pkg2.p2b import othermods.othera, othermods.otherb import othermods.sub.osa, othermods.sub.osb diff --git a/tests/test_api.py b/tests/test_api.py index 9de83fb..c7fa5ca 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -461,12 +461,11 @@ class SourceOmitIncludeTest(OmitIncludeTestsMixin, CoverageTest): summary[k[:-3]] = v return summary - def test_source_package(self): - lines = self.coverage_usepkgs(source=["pkg1"]) - self.filenames_in(lines, "p1a p1b") + def test_source_package_unexecuted(self): + lines = self.coverage_usepkgs(source=["pkg1.sub"]) self.filenames_not_in(lines, "p2a p2b othera otherb osa osb") # Because source= was specified, we do search for unexecuted files. - self.assertEqual(lines['p1c'], 0) + self.assertEqual(lines['runmod3'], 0) def test_source_package_dotted(self): lines = self.coverage_usepkgs(source=["pkg1.p1b"]) diff --git a/tests/test_python.py b/tests/test_python.py index ee1e1f9..c4e333e 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -5,8 +5,9 @@ import os import sys +from coverage import env -from coverage.python import get_zip_bytes +from coverage.python import get_zip_bytes, source_for_file from tests.coveragetest import CoverageTest @@ -28,3 +29,27 @@ class GetZipBytesTest(CoverageTest): self.assertIn('All OK', zip_text) # Run the code to see that we really got it encoded properly. __import__("encoded_"+encoding) + +def test_source_for_file(tmpdir): + path = tmpdir.join("a.py") + src = str(path) + assert src == source_for_file(src) + assert src == source_for_file(src + 'c') + assert src == source_for_file(src + 'o') + unknown = src + 'FOO' + assert unknown == source_for_file(unknown) + # + # On windows if a pyw exists, it is an acceptable source + # + windows = env.WINDOWS + env.WINDOWS = True + path_windows = tmpdir.ensure("a.pyw") + assert str(path_windows) == source_for_file(src + 'c') + # + # If both pyw and py exist, py is preferred + # + path.ensure(file=True) + assert src == source_for_file(src + 'c') + env.WINDOWS = windows + jython_src = "a" + assert jython_src + ".py" == source_for_file(jython_src + "$py.class") |
