mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-101000: Add os.path.splitroot() (#101002)
Co-authored-by: Eryk Sun <eryksun@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
37f15a5efa
commit
e5b08ddddf
9 changed files with 279 additions and 165 deletions
|
@ -80,26 +80,6 @@ class PosixFlavourTest(_BaseFlavourTest, unittest.TestCase):
|
|||
check(['c:\\a'], ('', '', ['c:\\a']))
|
||||
check(['\\a'], ('', '', ['\\a']))
|
||||
|
||||
def test_splitroot(self):
|
||||
f = self.cls._split_root
|
||||
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'))
|
||||
|
||||
|
||||
class NTFlavourTest(_BaseFlavourTest, unittest.TestCase):
|
||||
cls = pathlib.PureWindowsPath
|
||||
|
@ -143,23 +123,6 @@ class NTFlavourTest(_BaseFlavourTest, unittest.TestCase):
|
|||
check(['c:/a/b', 'c:x/y'], ('c:', '\\', ['c:\\', 'a', 'b', 'x', 'y']))
|
||||
check(['c:/a/b', 'c:/x/y'], ('c:', '\\', ['c:\\', 'x', 'y']))
|
||||
|
||||
def test_splitroot(self):
|
||||
f = self.cls._split_root
|
||||
self.assertEqual(f(''), ('', '', ''))
|
||||
self.assertEqual(f('a'), ('', '', 'a'))
|
||||
self.assertEqual(f('a\\b'), ('', '', 'a\\b'))
|
||||
self.assertEqual(f('\\a'), ('', '\\', 'a'))
|
||||
self.assertEqual(f('\\a\\b'), ('', '\\', 'a\\b'))
|
||||
self.assertEqual(f('c:a\\b'), ('c:', '', 'a\\b'))
|
||||
self.assertEqual(f('c:\\a\\b'), ('c:', '\\', 'a\\b'))
|
||||
# Redundant slashes in the root are collapsed.
|
||||
self.assertEqual(f('c:\\\\a'), ('c:', '\\', 'a'))
|
||||
self.assertEqual(f('c:\\\\\\a/b'), ('c:', '\\', 'a/b'))
|
||||
# Valid UNC paths.
|
||||
self.assertEqual(f('\\\\a\\b'), ('\\\\a\\b', '\\', ''))
|
||||
self.assertEqual(f('\\\\a\\b\\'), ('\\\\a\\b', '\\', ''))
|
||||
self.assertEqual(f('\\\\a\\b\\c\\d'), ('\\\\a\\b', '\\', 'c\\d'))
|
||||
|
||||
|
||||
#
|
||||
# Tests for the pure classes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue