summaryrefslogtreecommitdiff
path: root/test/test_files.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-03-21 18:51:40 -0400
committerNed Batchelder <ned@nedbatchelder.com>2010-03-21 18:51:40 -0400
commit489872c0d84aeff03d164eda5201b495a73e129d (patch)
tree69e7d5b8609c38f1381f7ef67e79911b741ffca6 /test/test_files.py
parent506acd0e2c542032a6ff2017b7074296d2f65214 (diff)
downloadpython-coveragepy-git-489872c0d84aeff03d164eda5201b495a73e129d.tar.gz
Undo Ben Finney's patch to use the os.path methods. os.path.commonprefix is both useless (beacause it's based on characters, not path components) and wrong (because to compute a relative path name, we need relative to a particular directory, or absolute, not some middle case).
Diffstat (limited to 'test/test_files.py')
-rw-r--r--test/test_files.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/test_files.py b/test/test_files.py
new file mode 100644
index 00000000..4852d692
--- /dev/null
+++ b/test/test_files.py
@@ -0,0 +1,34 @@
+"""Tests for files.py"""
+
+import os, sys
+
+from coverage.files import FileLocator
+
+sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
+from coveragetest import CoverageTest
+
+
+class FileLocatorTest(CoverageTest):
+ """Tests of `FileLocator`."""
+
+ def abs_path(self, p):
+ return os.path.join(os.getcwd(), os.path.normpath(p))
+
+ def test_simple(self):
+ self.make_file("hello.py", "#hello")
+ fl = FileLocator()
+ self.assertEqual(fl.relative_filename("hello.py"), "hello.py")
+ abs = self.abs_path("hello.py")
+ self.assertNotEqual(abs, "hello.py")
+ self.assertEqual(fl.relative_filename(abs), "hello.py")
+
+ def test_peer_directories(self):
+ self.make_file("sub/proj1/file1.py", "file1")
+ self.make_file("sub/proj2/file2.py", "file2")
+ abs1 = self.abs_path("sub/proj1/file1.py")
+ abs2 = self.abs_path("sub/proj2/file2.py")
+ d = os.path.normpath("sub/proj1")
+ os.chdir(d)
+ fl = FileLocator()
+ self.assertEqual(fl.relative_filename(abs1), "file1.py")
+ self.assertEqual(fl.relative_filename(abs2), abs2)