summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_posixpath.py
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2007-03-16 22:16:08 (GMT)
committerCollin Winter <collinw@gmail.com>2007-03-16 22:16:08 (GMT)
commit6f187743ffbce522c9d686ae5393272c1eb85dcc (patch)
tree49954823525566e80d435c3f9acff30a1a54e58d /Lib/test/test_posixpath.py
parent6de691d78ce696d897e4c58c3fc8fd7d3f6f1359 (diff)
downloadcpython-6f187743ffbce522c9d686ae5393272c1eb85dcc.zip
cpython-6f187743ffbce522c9d686ae5393272c1eb85dcc.tar.gz
cpython-6f187743ffbce522c9d686ae5393272c1eb85dcc.tar.bz2
Patch 1339796: add a relpath() function to os.path.
Diffstat (limited to 'Lib/test/test_posixpath.py')
-rw-r--r--Lib/test/test_posixpath.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 5632dcc..e2adb34 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -2,7 +2,7 @@ import unittest
from test import test_support
import posixpath, os
-from posixpath import realpath, abspath, join, dirname, basename
+from posixpath import realpath, abspath, join, dirname, basename, relpath
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
# being an absolute path, so we need this.
@@ -479,6 +479,17 @@ class PosixPathTest(unittest.TestCase):
safe_rmdir(ABSTFN + "/k")
safe_rmdir(ABSTFN)
+ def test_relpath(self):
+ currentdir = os.path.split(os.getcwd())[-1]
+ self.assertRaises(ValueError, posixpath.relpath, "")
+ self.assertEqual(posixpath.relpath("a"), "a")
+ self.assertEqual(posixpath.relpath(os.path.abspath("a")), "a")
+ self.assertEqual(posixpath.relpath("a/b"), "a/b")
+ self.assertEqual(posixpath.relpath("../a/b"), "../a/b")
+ self.assertEqual(posixpath.relpath("a", "../b"), "../"+currentdir+"/a")
+ self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+currentdir+"/a/b")
+ self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
+
def test_main():
test_support.run_unittest(PosixPathTest)