Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'main' into gh-101362-exclude-anchor-from-parts
  • Loading branch information
barneygale committed Apr 9, 2023
commit 078ced9c8934d4bbb94c282c798c13a51bc13c38
110 changes: 0 additions & 110 deletions Lib/test/test_pathlib.py
Comment thread
barneygale marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -24,116 +24,6 @@
grp = pwd = None


class _BaseFlavourTest(object):

def _check_parse_parts(self, arg, expected):
def f(parts):
path = self.cls(*parts)._raw_path
return self.cls._parse_path(path)
sep = self.flavour.sep
altsep = self.flavour.altsep
actual = f([x.replace('/', sep) for x in arg])
self.assertEqual(actual, expected)
if altsep:
actual = f([x.replace('/', altsep) for x in arg])
self.assertEqual(actual, expected)

def test_parse_parts_common(self):
check = self._check_parse_parts
sep = self.flavour.sep
# Unanchored parts.
check([], ('', '', []))
check(['a'], ('', '', ['a']))
check(['a/'], ('', '', ['a']))
check(['a', 'b'], ('', '', ['a', 'b']))
# Expansion.
check(['a/b'], ('', '', ['a', 'b']))
check(['a/b/'], ('', '', ['a', 'b']))
check(['a', 'b/c', 'd'], ('', '', ['a', 'b', 'c', 'd']))
# Collapsing and stripping excess slashes.
check(['a', 'b//c', 'd'], ('', '', ['a', 'b', 'c', 'd']))
check(['a', 'b/c/', 'd'], ('', '', ['a', 'b', 'c', 'd']))
# Eliminating standalone dots.
check(['.'], ('', '', []))
check(['.', '.', 'b'], ('', '', ['b']))
check(['a', '.', 'b'], ('', '', ['a', 'b']))
check(['a', '.', '.'], ('', '', ['a']))
# The first part is anchored.
check(['/a/b'], ('', sep, ['a', 'b']))
check(['/a', 'b'], ('', sep, ['a', 'b']))
check(['/a/', 'b'], ('', sep, ['a', 'b']))
# Ignoring parts before an anchored part.
check(['a', '/b', 'c'], ('', sep, ['b', 'c']))
check(['a', '/b', '/c'], ('', sep, ['c']))


class PosixFlavourTest(_BaseFlavourTest, unittest.TestCase):
cls = pathlib.PurePosixPath
flavour = pathlib.PurePosixPath._flavour

def test_parse_parts(self):
check = self._check_parse_parts
# Collapsing of excess leading slashes, except for the double-slash
# special case.
check(['//a', 'b'], ('', '//', ['a', 'b']))
check(['///a', 'b'], ('', '/', ['a', 'b']))
check(['////a', 'b'], ('', '/', ['a', 'b']))
# Paths which look like NT paths aren't treated specially.
check(['c:a'], ('', '', ['c:a']))
check(['c:\\a'], ('', '', ['c:\\a']))
check(['\\a'], ('', '', ['\\a']))


class NTFlavourTest(_BaseFlavourTest, unittest.TestCase):
cls = pathlib.PureWindowsPath
flavour = pathlib.PureWindowsPath._flavour

def test_parse_parts(self):
check = self._check_parse_parts
# First part is anchored.
check(['c:'], ('c:', '', []))
check(['c:/'], ('c:', '\\', []))
check(['/'], ('', '\\', []))
check(['c:a'], ('c:', '', ['a']))
check(['c:/a'], ('c:', '\\', ['a']))
check(['/a'], ('', '\\', ['a']))
# UNC paths.
check(['//a/b'], ('\\\\a\\b', '\\', []))
check(['//a/b/'], ('\\\\a\\b', '\\', []))
check(['//a/b/c'], ('\\\\a\\b', '\\', ['c']))
# Second part is anchored, so that the first part is ignored.
check(['a', 'Z:b', 'c'], ('Z:', '', ['b', 'c']))
check(['a', 'Z:/b', 'c'], ('Z:', '\\', ['b', 'c']))
# UNC paths.
check(['a', '//b/c', 'd'], ('\\\\b\\c', '\\', ['d']))
# Collapsing and stripping excess slashes.
check(['a', 'Z://b//c/', 'd/'], ('Z:', '\\', ['b', 'c', 'd']))
# UNC paths.
check(['a', '//b/c//', 'd'], ('\\\\b\\c', '\\', ['d']))
# Extended paths.
check(['//?/c:/'], ('\\\\?\\c:', '\\', []))
check(['//?/c:/a'], ('\\\\?\\c:', '\\', ['a']))
check(['//?/c:/a', '/b'], ('\\\\?\\c:', '\\', ['b']))
# Extended UNC paths (format is "\\?\UNC\server\share").
check(['//?/UNC/b/c'], ('\\\\?\\UNC\\b\\c', '\\', []))
check(['//?/UNC/b/c/d'], ('\\\\?\\UNC\\b\\c', '\\', ['d']))
# Second part has a root but not drive.
check(['a', '/b', 'c'], ('', '\\', ['b', 'c']))
check(['Z:/a', '/b', 'c'], ('Z:', '\\', ['b', 'c']))
check(['//?/Z:/a', '/b', 'c'], ('\\\\?\\Z:', '\\', ['b', 'c']))
# Joining with the same drive => the first path is appended to if
# the second path is relative.
check(['c:/a/b', 'c:x/y'], ('c:', '\\', ['a', 'b', 'x', 'y']))
check(['c:/a/b', 'c:/x/y'], ('c:', '\\', ['x', 'y']))
# Paths to files with NTFS alternate data streams
check(['./c:s'], ('', '', ['c:s']))
check(['cc:s'], ('', '', ['cc:s']))
check(['C:c:s'], ('C:', '', ['c:s']))
check(['C:/c:s'], ('C:', '\\', ['c:s']))
check(['D:a', './c:b'], ('D:', '', ['a', 'c:b']))
check(['D:/a', './c:b'], ('D:', '\\', ['a', 'c:b']))


#
# Tests for the pure classes.
#
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.