MCPcopy Index your code
hub / github.com/python/cpython / PurePathTest

Class PurePathTest

Lib/test/test_pathlib/test_pathlib.py:91–1102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89#
90
91class PurePathTest(unittest.TestCase):
92 cls = pathlib.PurePath
93
94 # Make sure any symbolic links in the base test path are resolved.
95 base = os.path.realpath(TESTFN)
96
97 # Keys are canonical paths, values are list of tuples of arguments
98 # supposed to produce equal paths.
99 equivalences = {
100 'a/b': [
101 ('a', 'b'), ('a/', 'b'), ('a', 'b/'), ('a/', 'b/'),
102 ('a/b/',), ('a//b',), ('a//b//',),
103 # Empty components get removed.
104 ('', 'a', 'b'), ('a', '', 'b'), ('a', 'b', ''),
105 ],
106 '/b/c/d': [
107 ('a', '/b/c', 'd'), ('/a', '/b/c', 'd'),
108 # Empty components get removed.
109 ('/', 'b', '', 'c/d'), ('/', '', 'b/c/d'), ('', '/b/c/d'),
110 ],
111 }
112
113 def setUp(self):
114 name = self.id().split('.')[-1]
115 if name in _tests_needing_posix and self.cls.parser is not posixpath:
116 self.skipTest('requires POSIX-flavoured path class')
117 if name in _tests_needing_windows and self.cls.parser is posixpath:
118 self.skipTest('requires Windows-flavoured path class')
119 p = self.cls('a')
120 self.parser = p.parser
121 self.sep = self.parser.sep
122 self.altsep = self.parser.altsep
123
124 def _check_str_subclass(self, *args):
125 # Issue #21127: it should be possible to construct a PurePath object
126 # from a str subclass instance, and it then gets converted to
127 # a pure str object.
128 class StrSubclass(str):
129 pass
130 P = self.cls
131 p = P(*(StrSubclass(x) for x in args))
132 self.assertEqual(p, P(*args))
133 for part in p.parts:
134 self.assertIs(type(part), str)
135
136 def test_str_subclass_common(self):
137 self._check_str_subclass('')
138 self._check_str_subclass('.')
139 self._check_str_subclass('a')
140 self._check_str_subclass('a/b.txt')
141 self._check_str_subclass('/a/b.txt')
142
143 @needs_windows
144 def test_str_subclass_windows(self):
145 self._check_str_subclass('.\\a:b')
146 self._check_str_subclass('c:')
147 self._check_str_subclass('c:a')
148 self._check_str_subclass('c:a\\b.txt')

Callers

nothing calls this directly

Calls 1

realpathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…