summaryrefslogtreecommitdiff
path: root/tests/test_python.py
diff options
context:
space:
mode:
authorloic@dachary.org <loic@dachary.org>2017-01-10 17:31:34 +0100
committerloic@dachary.org <loic@dachary.org>2017-01-10 17:31:34 +0100
commit6da69c9cfcf8874cc423177a9376e90e27218d1d (patch)
tree323fff9ae975451516cfa8757e26b8527271cc0c /tests/test_python.py
parentd93a997913baa51989e33c94588d31bd07707b22 (diff)
downloadpython-coveragepy-git-6da69c9cfcf8874cc423177a9376e90e27218d1d.tar.gz
source_for_file helper with unit tests
--HG-- branch : issue-426
Diffstat (limited to 'tests/test_python.py')
-rw-r--r--tests/test_python.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/test_python.py b/tests/test_python.py
index ee1e1f95..c4e333ef 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")