diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-06 17:14:12 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-06 17:14:12 +0200 |
commit | a993902a287a0d8ff02e2fa6e451b5277c4b4af9 (patch) | |
tree | 39af086c546f70364c2f434eecadd8c0b7df71dd /Lib/test/test_pathlib.py | |
parent | 1b8b868b84112ce6aed7e07f664b5f54a0c8f9a9 (diff) | |
download | cpython-git-a993902a287a0d8ff02e2fa6e451b5277c4b4af9.tar.gz |
Issue #19908: pathlib now joins relative Windows paths correctly when a drive
is present. Original patch by Antoine Pitrou.
Diffstat (limited to 'Lib/test/test_pathlib.py')
-rwxr-xr-x | Lib/test/test_pathlib.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 2b8b2c1a7d..4149c9ede1 100755 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -975,6 +975,48 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase): self.assertTrue(P('//a/b/c').is_absolute()) self.assertTrue(P('//a/b/c/d').is_absolute()) + def test_join(self): + P = self.cls + p = P('C:/a/b') + pp = p.joinpath('x/y') + self.assertEqual(pp, P('C:/a/b/x/y')) + pp = p.joinpath('/x/y') + self.assertEqual(pp, P('C:/x/y')) + # Joining with a different drive => the first path is ignored, even + # if the second path is relative. + pp = p.joinpath('D:x/y') + self.assertEqual(pp, P('D:x/y')) + pp = p.joinpath('D:/x/y') + self.assertEqual(pp, P('D:/x/y')) + pp = p.joinpath('//host/share/x/y') + self.assertEqual(pp, P('//host/share/x/y')) + # Joining with the same drive => the first path is appended to if + # the second path is relative. + pp = p.joinpath('c:x/y') + self.assertEqual(pp, P('C:/a/b/x/y')) + pp = p.joinpath('c:/x/y') + self.assertEqual(pp, P('C:/x/y')) + + def test_div(self): + # Basically the same as joinpath() + P = self.cls + p = P('C:/a/b') + self.assertEqual(p / 'x/y', P('C:/a/b/x/y')) + self.assertEqual(p / 'x' / 'y', P('C:/a/b/x/y')) + self.assertEqual(p / '/x/y', P('C:/x/y')) + self.assertEqual(p / '/x' / 'y', P('C:/x/y')) + # Joining with a different drive => the first path is ignored, even + # if the second path is relative. + self.assertEqual(p / 'D:x/y', P('D:x/y')) + self.assertEqual(p / 'D:' / 'x/y', P('D:x/y')) + self.assertEqual(p / 'D:/x/y', P('D:/x/y')) + self.assertEqual(p / 'D:' / '/x/y', P('D:/x/y')) + self.assertEqual(p / '//host/share/x/y', P('//host/share/x/y')) + # Joining with the same drive => the first path is appended to if + # the second path is relative. + self.assertEqual(p / 'C:x/y', P('C:/a/b/x/y')) + self.assertEqual(p / 'C:/x/y', P('C:/x/y')) + def test_is_reserved(self): P = self.cls self.assertIs(False, P('').is_reserved()) |