summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_posixpath.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2023-01-27 00:28:27 (GMT)
committerGitHub <noreply@github.com>2023-01-27 00:28:27 (GMT)
commite5b08ddddf1099f04bf65e63017de840bd4b5980 (patch)
tree598fb062a99a7d159debc1d97398b04d2a88e7df /Lib/test/test_posixpath.py
parent37f15a5efab847b8aca47981ab596e9c36445bf7 (diff)
downloadcpython-e5b08ddddf1099f04bf65e63017de840bd4b5980.zip
cpython-e5b08ddddf1099f04bf65e63017de840bd4b5980.tar.gz
cpython-e5b08ddddf1099f04bf65e63017de840bd4b5980.tar.bz2
gh-101000: Add os.path.splitroot() (#101002)
Co-authored-by: Eryk Sun <eryksun@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Lib/test/test_posixpath.py')
-rw-r--r--Lib/test/test_posixpath.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 6c1c0f5..9be4640 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -115,6 +115,32 @@ class PosixPathTest(unittest.TestCase):
self.splitextTest("........", "........", "")
self.splitextTest("", "", "")
+ def test_splitroot(self):
+ f = posixpath.splitroot
+ self.assertEqual(f(''), ('', '', ''))
+ self.assertEqual(f('a'), ('', '', 'a'))
+ self.assertEqual(f('a/b'), ('', '', 'a/b'))
+ self.assertEqual(f('a/b/'), ('', '', 'a/b/'))
+ self.assertEqual(f('/a'), ('', '/', 'a'))
+ self.assertEqual(f('/a/b'), ('', '/', 'a/b'))
+ self.assertEqual(f('/a/b/'), ('', '/', 'a/b/'))
+ # The root is collapsed when there are redundant slashes
+ # except when there are exactly two leading slashes, which
+ # is a special case in POSIX.
+ self.assertEqual(f('//a'), ('', '//', 'a'))
+ self.assertEqual(f('///a'), ('', '/', '//a'))
+ self.assertEqual(f('///a/b'), ('', '/', '//a/b'))
+ # Paths which look like NT paths aren't treated specially.
+ self.assertEqual(f('c:/a/b'), ('', '', 'c:/a/b'))
+ self.assertEqual(f('\\/a/b'), ('', '', '\\/a/b'))
+ self.assertEqual(f('\\a\\b'), ('', '', '\\a\\b'))
+ # Byte paths are supported
+ self.assertEqual(f(b''), (b'', b'', b''))
+ self.assertEqual(f(b'a'), (b'', b'', b'a'))
+ self.assertEqual(f(b'/a'), (b'', b'/', b'a'))
+ self.assertEqual(f(b'//a'), (b'', b'//', b'a'))
+ self.assertEqual(f(b'///a'), (b'', b'/', b'//a'))
+
def test_isabs(self):
self.assertIs(posixpath.isabs(""), False)
self.assertIs(posixpath.isabs("/"), True)
@@ -752,6 +778,9 @@ class PathLikeTests(unittest.TestCase):
def test_path_splitdrive(self):
self.assertPathEqual(self.path.splitdrive)
+ def test_path_splitroot(self):
+ self.assertPathEqual(self.path.splitroot)
+
def test_path_basename(self):
self.assertPathEqual(self.path.basename)