diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ntpath.py | 10 | ||||
-rw-r--r-- | Lib/test/test_posixpath.py | 13 |
2 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 703e5c856f..6af9c85142 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -157,6 +157,16 @@ except ImportError: else: tester('ntpath.abspath("C:\\")', "C:\\") +currentdir = os.path.split(os.getcwd())[-1] +tester('ntpath.relpath("a")', 'a') +tester('ntpath.relpath(os.path.abspath("a"))', 'a') +tester('ntpath.relpath("a/b")', 'a\\b') +tester('ntpath.relpath("../a/b")', '..\\a\\b') +tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a') +tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b') +tester('ntpath.relpath("a", "b/c")', '..\\..\\a') +tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a') + if errors: raise TestFailed(str(errors) + " errors.") elif verbose: diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 5632dcc8cd..e2adb3422d 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) |