| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b4abd1b commit 8284da8
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -256,6 +256,7 @@ def test_join(self): | |||
| 256 | 256 | tester('ntpath.join("a", "b", "c")', 'a\\b\\c') | |
| 257 | 257 | tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c') | |
| 258 | 258 | tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c') | |
| 259 | + tester('ntpath.join("a", "b", "c\\")', 'a\\b\\c\\') | ||
| 259 | 260 | tester('ntpath.join("a", "b", "\\c")', '\\c') | |
| 260 | 261 | tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep') | |
| 261 | 262 | tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b') | |
@@ -313,6 +314,16 @@ def test_join(self): | |||
| 313 | 314 | tester("ntpath.join('\\\\computer\\', 'share')", '\\\\computer\\share') | |
| 314 | 315 | tester("ntpath.join('\\\\computer\\share\\', 'a')", '\\\\computer\\share\\a') | |
| 315 | 316 | tester("ntpath.join('\\\\computer\\share\\a\\', 'b')", '\\\\computer\\share\\a\\b') | |
| 317 | + # Second part is anchored, so that the first part is ignored. | ||
| 318 | + tester("ntpath.join('a', 'Z:b', 'c')", 'Z:b\\c') | ||
| 319 | + tester("ntpath.join('a', 'Z:\\b', 'c')", 'Z:\\b\\c') | ||
| 320 | + tester("ntpath.join('a', '\\\\b\\c', 'd')", '\\\\b\\c\\d') | ||
| 321 | + # Second part has a root but not drive. | ||
| 322 | + tester("ntpath.join('a', '\\b', 'c')", '\\b\\c') | ||
| 323 | + tester("ntpath.join('Z:/a', '/b', 'c')", 'Z:\\b\\c') | ||
| 324 | + tester("ntpath.join('//?/Z:/a', '/b', 'c')", '\\\\?\\Z:\\b\\c') | ||
| 325 | + tester("ntpath.join('D:a', './c:b')", 'D:a\\.\\c:b') | ||
| 326 | + tester("ntpath.join('D:/a', './c:b')", 'D:\\a\\.\\c:b') | ||
| 316 | 327 | ||
| 317 | 328 | def test_normpath(self): | |
| 318 | 329 | tester("ntpath.normpath('A//////././//.//B')", r'A\B') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,45 +160,30 @@ def with_segments(self, *pathsegments): | |||
| 160 | 160 | for parent in p.parents: | |
| 161 | 161 | self.assertEqual(42, parent.session_id) | |
| 162 | 162 | ||
| 163 | - def _get_drive_root_parts(self, parts): | ||
| 164 | - path = self.cls(*parts) | ||
| 165 | - return path.drive, path.root, path.parts | ||
| 166 | - | ||
| 167 | - def _check_drive_root_parts(self, arg, *expected): | ||
| 163 | + def _check_parse_path(self, raw_path, *expected): | ||
| 168 | 164 | sep = self.pathmod.sep | |
| 169 | - actual = self._get_drive_root_parts([x.replace('/', sep) for x in arg]) | ||
| 165 | + actual = self.cls._parse_path(raw_path.replace('/', sep)) | ||
| 170 | 166 | self.assertEqual(actual, expected) | |
| 171 | 167 | if altsep := self.pathmod.altsep: | |
| 172 | - actual = self._get_drive_root_parts([x.replace('/', altsep) for x in arg]) | ||
| 168 | + actual = self.cls._parse_path(raw_path.replace('/', altsep)) | ||
| 173 | 169 | self.assertEqual(actual, expected) | |
| 174 | 170 | ||
| 175 | - def test_drive_root_parts_common(self): | ||
| 176 | - check = self._check_drive_root_parts | ||
| 171 | + def test_parse_path_common(self): | ||
| 172 | + check = self._check_parse_path | ||
| 177 | 173 | sep = self.pathmod.sep | |
| 178 | - # Unanchored parts. | ||
| 179 | - check((), '', '', ()) | ||
| 180 | - check(('a',), '', '', ('a',)) | ||
| 181 | - check(('a/',), '', '', ('a',)) | ||
| 182 | - check(('a', 'b'), '', '', ('a', 'b')) | ||
| 183 | - # Expansion. | ||
| 184 | - check(('a/b',), '', '', ('a', 'b')) | ||
| 185 | - check(('a/b/',), '', '', ('a', 'b')) | ||
| 186 | - check(('a', 'b/c', 'd'), '', '', ('a', 'b', 'c', 'd')) | ||
| 187 | - # Collapsing and stripping excess slashes. | ||
| 188 | - check(('a', 'b//c', 'd'), '', '', ('a', 'b', 'c', 'd')) | ||
| 189 | - check(('a', 'b/c/', 'd'), '', '', ('a', 'b', 'c', 'd')) | ||
| 190 | - # Eliminating standalone dots. | ||
| 191 | - check(('.',), '', '', ()) | ||
| 192 | - check(('.', '.', 'b'), '', '', ('b',)) | ||
| 193 | - check(('a', '.', 'b'), '', '', ('a', 'b')) | ||
| 194 | - check(('a', '.', '.'), '', '', ('a',)) | ||
| 195 | - # The first part is anchored. | ||
| 196 | - check(('/a/b',), '', sep, (sep, 'a', 'b')) | ||
| 197 | - check(('/a', 'b'), '', sep, (sep, 'a', 'b')) | ||
| 198 | - check(('/a/', 'b'), '', sep, (sep, 'a', 'b')) | ||
| 199 | - # Ignoring parts before an anchored part. | ||
| 200 | - check(('a', '/b', 'c'), '', sep, (sep, 'b', 'c')) | ||
| 201 | - check(('a', '/b', '/c'), '', sep, (sep, 'c')) | ||
| 174 | + check('', '', '', []) | ||
| 175 | + check('a', '', '', ['a']) | ||
| 176 | + check('a/', '', '', ['a']) | ||
| 177 | + check('a/b', '', '', ['a', 'b']) | ||
| 178 | + check('a/b/', '', '', ['a', 'b']) | ||
| 179 | + check('a/b/c/d', '', '', ['a', 'b', 'c', 'd']) | ||
| 180 | + check('a/b//c/d', '', '', ['a', 'b', 'c', 'd']) | ||
| 181 | + check('a/b/c/d', '', '', ['a', 'b', 'c', 'd']) | ||
| 182 | + check('.', '', '', []) | ||
| 183 | + check('././b', '', '', ['b']) | ||
| 184 | + check('a/./b', '', '', ['a', 'b']) | ||
| 185 | + check('a/./.', '', '', ['a']) | ||
| 186 | + check('/a/b', '', sep, ['a', 'b']) | ||
| 202 | 187 | ||
| 203 | 188 | def test_join_common(self): | |
| 204 | 189 | P = self.cls | |
@@ -792,17 +777,17 @@ def test_repr_roundtrips(self): | |||
| 792 | 777 | class PurePosixPathTest(PurePathTest): | |
| 793 | 778 | cls = pathlib.PurePosixPath | |
| 794 | 779 | ||
| 795 | - def test_drive_root_parts(self): | ||
| 796 | - check = self._check_drive_root_parts | ||
| 780 | + def test_parse_path(self): | ||
| 781 | + check = self._check_parse_path | ||
| 797 | 782 | # Collapsing of excess leading slashes, except for the double-slash | |
| 798 | 783 | # special case. | |
| 799 | - check(('//a', 'b'), '', '//', ('//', 'a', 'b')) | ||
| 800 | - check(('///a', 'b'), '', '/', ('/', 'a', 'b')) | ||
| 801 | - check(('////a', 'b'), '', '/', ('/', 'a', 'b')) | ||
| 784 | + check('//a/b', '', '//', ['a', 'b']) | ||
| 785 | + check('///a/b', '', '/', ['a', 'b']) | ||
| 786 | + check('////a/b', '', '/', ['a', 'b']) | ||
| 802 | 787 | # Paths which look like NT paths aren't treated specially. | |
| 803 | - check(('c:a',), '', '', ('c:a',)) | ||
| 804 | - check(('c:\\a',), '', '', ('c:\\a',)) | ||
| 805 | - check(('\\a',), '', '', ('\\a',)) | ||
| 788 | + check('c:a', '', '', ['c:a',]) | ||
| 789 | + check('c:\\a', '', '', ['c:\\a',]) | ||
| 790 | + check('\\a', '', '', ['\\a',]) | ||
| 806 | 791 | ||
| 807 | 792 | def test_root(self): | |
| 808 | 793 | P = self.cls | |
@@ -900,67 +885,53 @@ class PureWindowsPathTest(PurePathTest): | |||
| 900 | 885 | ], | |
| 901 | 886 | }) | |
| 902 | 887 | ||
| 903 | - def test_drive_root_parts(self): | ||
| 904 | - check = self._check_drive_root_parts | ||
| 888 | + def test_parse_path(self): | ||
| 889 | + check = self._check_parse_path | ||
| 905 | 890 | # First part is anchored. | |
| 906 | - check(('c:',), 'c:', '', ('c:',)) | ||
| 907 | - check(('c:/',), 'c:', '\\', ('c:\\',)) | ||
| 908 | - check(('/',), '', '\\', ('\\',)) | ||
| 909 | - check(('c:a',), 'c:', '', ('c:', 'a')) | ||
| 910 | - check(('c:/a',), 'c:', '\\', ('c:\\', 'a')) | ||
| 911 | - check(('/a',), '', '\\', ('\\', 'a')) | ||
| 912 | - # UNC paths. | ||
| 913 | - check(('//',), '\\\\', '', ('\\\\',)) | ||
| 914 | - check(('//a',), '\\\\a', '', ('\\\\a',)) | ||
| 915 | - check(('//a/',), '\\\\a\\', '', ('\\\\a\\',)) | ||
| 916 | - check(('//a/b',), '\\\\a\\b', '\\', ('\\\\a\\b\\',)) | ||
| 917 | - check(('//a/b/',), '\\\\a\\b', '\\', ('\\\\a\\b\\',)) | ||
| 918 | - check(('//a/b/c',), '\\\\a\\b', '\\', ('\\\\a\\b\\', 'c')) | ||
| 919 | - # Second part is anchored, so that the first part is ignored. | ||
| 920 | - check(('a', 'Z:b', 'c'), 'Z:', '', ('Z:', 'b', 'c')) | ||
| 921 | - check(('a', 'Z:/b', 'c'), 'Z:', '\\', ('Z:\\', 'b', 'c')) | ||
| 891 | + check('c:', 'c:', '', []) | ||
| 892 | + check('c:/', 'c:', '\\', []) | ||
| 893 | + check('/', '', '\\', []) | ||
| 894 | + check('c:a', 'c:', '', ['a']) | ||
| 895 | + check('c:/a', 'c:', '\\', ['a']) | ||
| 896 | + check('/a', '', '\\', ['a']) | ||
| 922 | 897 | # UNC paths. | |
| 923 | - check(('a', '//b/c', 'd'), '\\\\b\\c', '\\', ('\\\\b\\c\\', 'd')) | ||
| 898 | + check('//', '\\\\', '', []) | ||
| 899 | + check('//a', '\\\\a', '', []) | ||
| 900 | + check('//a/', '\\\\a\\', '', []) | ||
| 901 | + check('//a/b', '\\\\a\\b', '\\', []) | ||
| 902 | + check('//a/b/', '\\\\a\\b', '\\', []) | ||
| 903 | + check('//a/b/c', '\\\\a\\b', '\\', ['c']) | ||
| 924 | 904 | # Collapsing and stripping excess slashes. | |
| 925 | - check(('a', 'Z://b//c/', 'd/'), 'Z:', '\\', ('Z:\\', 'b', 'c', 'd')) | ||
| 905 | + check('Z://b//c/d/', 'Z:', '\\', ['b', 'c', 'd']) | ||
| 926 | 906 | # UNC paths. | |
| 927 | - check(('a', '//b/c//', 'd'), '\\\\b\\c', '\\', ('\\\\b\\c\\', 'd')) | ||
| 907 | + check('//b/c//d', '\\\\b\\c', '\\', ['d']) | ||
| 928 | 908 | # Extended paths. | |
| 929 | - check(('//./c:',), '\\\\.\\c:', '', ('\\\\.\\c:',)) | ||
| 930 | - check(('//?/c:/',), '\\\\?\\c:', '\\', ('\\\\?\\c:\\',)) | ||
| 931 | - check(('//?/c:/a',), '\\\\?\\c:', '\\', ('\\\\?\\c:\\', 'a')) | ||
| 932 | - check(('//?/c:/a', '/b'), '\\\\?\\c:', '\\', ('\\\\?\\c:\\', 'b')) | ||
| 909 | + check('//./c:', '\\\\.\\c:', '', []) | ||
| 910 | + check('//?/c:/', '\\\\?\\c:', '\\', []) | ||
| 911 | + check('//?/c:/a', '\\\\?\\c:', '\\', ['a']) | ||
| 933 | 912 | # Extended UNC paths (format is "\\?\UNC\server\share"). | |
| 934 | - check(('//?',), '\\\\?', '', ('\\\\?',)) | ||
| 935 | - check(('//?/',), '\\\\?\\', '', ('\\\\?\\',)) | ||
| 936 | - check(('//?/UNC',), '\\\\?\\UNC', '', ('\\\\?\\UNC',)) | ||
| 937 | - check(('//?/UNC/',), '\\\\?\\UNC\\', '', ('\\\\?\\UNC\\',)) | ||
| 938 | - check(('//?/UNC/b',), '\\\\?\\UNC\\b', '', ('\\\\?\\UNC\\b',)) | ||
| 939 | - check(('//?/UNC/b/',), '\\\\?\\UNC\\b\\', '', ('\\\\?\\UNC\\b\\',)) | ||
| 940 | - check(('//?/UNC/b/c',), '\\\\?\\UNC\\b\\c', '\\', ('\\\\?\\UNC\\b\\c\\',)) | ||
| 941 | - check(('//?/UNC/b/c/',), '\\\\?\\UNC\\b\\c', '\\', ('\\\\?\\UNC\\b\\c\\',)) | ||
| 942 | - check(('//?/UNC/b/c/d',), '\\\\?\\UNC\\b\\c', '\\', ('\\\\?\\UNC\\b\\c\\', 'd')) | ||
| 913 | + check('//?', '\\\\?', '', []) | ||
| 914 | + check('//?/', '\\\\?\\', '', []) | ||
| 915 | + check('//?/UNC', '\\\\?\\UNC', '', []) | ||
| 916 | + check('//?/UNC/', '\\\\?\\UNC\\', '', []) | ||
| 917 | + check('//?/UNC/b', '\\\\?\\UNC\\b', '', []) | ||
| 918 | + check('//?/UNC/b/', '\\\\?\\UNC\\b\\', '', []) | ||
| 919 | + check('//?/UNC/b/c', '\\\\?\\UNC\\b\\c', '\\', []) | ||
| 920 | + check('//?/UNC/b/c/', '\\\\?\\UNC\\b\\c', '\\', []) | ||
| 921 | + check('//?/UNC/b/c/d', '\\\\?\\UNC\\b\\c', '\\', ['d']) | ||
| 943 | 922 | # UNC device paths | |
| 944 | - check(('//./BootPartition/',), '\\\\.\\BootPartition', '\\', ('\\\\.\\BootPartition\\',)) | ||
| 945 | - check(('//?/BootPartition/',), '\\\\?\\BootPartition', '\\', ('\\\\?\\BootPartition\\',)) | ||
| 946 | - check(('//./PhysicalDrive0',), '\\\\.\\PhysicalDrive0', '', ('\\\\.\\PhysicalDrive0',)) | ||
| 947 | - check(('//?/Volume{}/',), '\\\\?\\Volume{}', '\\', ('\\\\?\\Volume{}\\',)) | ||
| 948 | - check(('//./nul',), '\\\\.\\nul', '', ('\\\\.\\nul',)) | ||
| 949 | - # Second part has a root but not drive. | ||
| 950 | - check(('a', '/b', 'c'), '', '\\', ('\\', 'b', 'c')) | ||
| 951 | - check(('Z:/a', '/b', 'c'), 'Z:', '\\', ('Z:\\', 'b', 'c')) | ||
| 952 | - check(('//?/Z:/a', '/b', 'c'), '\\\\?\\Z:', '\\', ('\\\\?\\Z:\\', 'b', 'c')) | ||
| 953 | - # Joining with the same drive => the first path is appended to if | ||
| 954 | - # the second path is relative. | ||
| 955 | - check(('c:/a/b', 'c:x/y'), 'c:', '\\', ('c:\\', 'a', 'b', 'x', 'y')) | ||
| 956 | - check(('c:/a/b', 'c:/x/y'), 'c:', '\\', ('c:\\', 'x', 'y')) | ||
| 923 | + check('//./BootPartition/', '\\\\.\\BootPartition', '\\', []) | ||
| 924 | + check('//?/BootPartition/', '\\\\?\\BootPartition', '\\', []) | ||
| 925 | + check('//./PhysicalDrive0', '\\\\.\\PhysicalDrive0', '', []) | ||
| 926 | + check('//?/Volume{}/', '\\\\?\\Volume{}', '\\', []) | ||
| 927 | + check('//./nul', '\\\\.\\nul', '', []) | ||
| 957 | 928 | # Paths to files with NTFS alternate data streams | |
| 958 | - check(('./c:s',), '', '', ('c:s',)) | ||
| 959 | - check(('cc:s',), '', '', ('cc:s',)) | ||
| 960 | - check(('C:c:s',), 'C:', '', ('C:', 'c:s')) | ||
| 961 | - check(('C:/c:s',), 'C:', '\\', ('C:\\', 'c:s')) | ||
| 962 | - check(('D:a', './c:b'), 'D:', '', ('D:', 'a', 'c:b')) | ||
| 963 | - check(('D:/a', './c:b'), 'D:', '\\', ('D:\\', 'a', 'c:b')) | ||
| 929 | + check('./c:s', '', '', ['c:s']) | ||
| 930 | + check('cc:s', '', '', ['cc:s']) | ||
| 931 | + check('C:c:s', 'C:', '', ['c:s']) | ||
| 932 | + check('C:/c:s', 'C:', '\\', ['c:s']) | ||
| 933 | + check('D:a/c:b', 'D:', '', ['a', 'c:b']) | ||
| 934 | + check('D:/a/c:b', 'D:', '\\', ['a', 'c:b']) | ||
| 964 | 935 | ||
| 965 | 936 | def test_str(self): | |
| 966 | 937 | p = self.cls('a/b/c') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,18 +47,26 @@ def tearDown(self): | |||
| 47 | 47 | safe_rmdir(os_helper.TESTFN + suffix) | |
| 48 | 48 | ||
| 49 | 49 | def test_join(self): | |
| 50 | - self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"), | ||
| 51 | - "/bar/baz") | ||
| 52 | - self.assertEqual(posixpath.join("/foo", "bar", "baz"), "/foo/bar/baz") | ||
| 53 | - self.assertEqual(posixpath.join("/foo/", "bar/", "baz/"), | ||
| 54 | - "/foo/bar/baz/") | ||
| 55 | - | ||
| 56 | - self.assertEqual(posixpath.join(b"/foo", b"bar", b"/bar", b"baz"), | ||
| 57 | - b"/bar/baz") | ||
| 58 | - self.assertEqual(posixpath.join(b"/foo", b"bar", b"baz"), | ||
| 59 | - b"/foo/bar/baz") | ||
| 60 | - self.assertEqual(posixpath.join(b"/foo/", b"bar/", b"baz/"), | ||
| 61 | - b"/foo/bar/baz/") | ||
| 50 | + fn = posixpath.join | ||
| 51 | + self.assertEqual(fn("/foo", "bar", "/bar", "baz"), "/bar/baz") | ||
| 52 | + self.assertEqual(fn("/foo", "bar", "baz"), "/foo/bar/baz") | ||
| 53 | + self.assertEqual(fn("/foo/", "bar/", "baz/"), "/foo/bar/baz/") | ||
| 54 | + | ||
| 55 | + self.assertEqual(fn(b"/foo", b"bar", b"/bar", b"baz"), b"/bar/baz") | ||
| 56 | + self.assertEqual(fn(b"/foo", b"bar", b"baz"), b"/foo/bar/baz") | ||
| 57 | + self.assertEqual(fn(b"/foo/", b"bar/", b"baz/"), b"/foo/bar/baz/") | ||
| 58 | + | ||
| 59 | + self.assertEqual(fn("a", "b"), "a/b") | ||
| 60 | + self.assertEqual(fn("a", "b/"), "a/b/") | ||
| 61 | + self.assertEqual(fn("a/", "b"), "a/b") | ||
| 62 | + self.assertEqual(fn("a/", "b/"), "a/b/") | ||
| 63 | + self.assertEqual(fn("a", "b/c", "d"), "a/b/c/d") | ||
| 64 | + self.assertEqual(fn("a", "b//c", "d"), "a/b//c/d") | ||
| 65 | + self.assertEqual(fn("a", "b/c/", "d"), "a/b/c/d") | ||
| 66 | + self.assertEqual(fn("/a", "b"), "/a/b") | ||
| 67 | + self.assertEqual(fn("/a/", "b"), "/a/b") | ||
| 68 | + self.assertEqual(fn("a", "/b", "c"), "/b/c") | ||
| 69 | + self.assertEqual(fn("a", "/b", "/c"), "/c") | ||
| 62 | 70 | ||
| 63 | 71 | def test_split(self): | |
| 64 | 72 | self.assertEqual(posixpath.split("/foo/bar"), ("/foo", "bar")) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments