summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_api.py10
-rw-r--r--tests/test_python.py36
2 files changed, 30 insertions, 16 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
index c7fa5ca2..0ab0b75c 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -461,7 +461,15 @@ class SourceOmitIncludeTest(OmitIncludeTestsMixin, CoverageTest):
summary[k[:-3]] = v
return summary
- def test_source_package_unexecuted(self):
+ def test_source_package_as_dir(self):
+ # pkg1 is a directory, since we cd'd into tests/modules in setUp.
+ lines = self.coverage_usepkgs(source=["pkg1"])
+ self.filenames_in(lines, "p1a p1b")
+ 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)
+
+ def test_source_package_as_package(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.
diff --git a/tests/test_python.py b/tests/test_python.py
index c4e333ef..9027aa6c 100644
--- a/tests/test_python.py
+++ b/tests/test_python.py
@@ -5,8 +5,10 @@
import os
import sys
-from coverage import env
+import pytest
+
+from coverage import env
from coverage.python import get_zip_bytes, source_for_file
from tests.coveragetest import CoverageTest
@@ -30,26 +32,30 @@ class GetZipBytesTest(CoverageTest):
# 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')
+ assert source_for_file(src) == src
+ assert source_for_file(src + 'c') == src
+ assert source_for_file(src + 'o') == src
unknown = src + 'FOO'
- assert unknown == source_for_file(unknown)
- #
+ assert source_for_file(unknown) == unknown
+
+
+@pytest.mark.skipif(not env.WINDOWS, reason="not windows")
+def test_source_for_file_windows(tmpdir):
+ path = tmpdir.join("a.py")
+ src = str(path)
+
# 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")
+ assert source_for_file(src + 'c') == src
+
+
+def test_source_for_file_jython():
+ assert source_for_file("a$py.class") == "a.py"