| 416 | self.assertEqual(normcase(path), path.lower()) |
| 417 | |
| 418 | def test_normpath(self): |
| 419 | tester("ntpath.normpath('A//////././//.//B')", r'A\B') |
| 420 | tester("ntpath.normpath('A/./B')", r'A\B') |
| 421 | tester("ntpath.normpath('A/foo/../B')", r'A\B') |
| 422 | tester("ntpath.normpath('C:A//B')", r'C:A\B') |
| 423 | tester("ntpath.normpath('D:A/./B')", r'D:A\B') |
| 424 | tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B') |
| 425 | |
| 426 | tester("ntpath.normpath('C:///A//B')", r'C:\A\B') |
| 427 | tester("ntpath.normpath('D:///A/./B')", r'D:\A\B') |
| 428 | tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B') |
| 429 | |
| 430 | tester("ntpath.normpath('..')", r'..') |
| 431 | tester("ntpath.normpath('.')", r'.') |
| 432 | tester("ntpath.normpath('c:.')", 'c:') |
| 433 | tester("ntpath.normpath('')", r'.') |
| 434 | tester("ntpath.normpath('/')", '\\') |
| 435 | tester("ntpath.normpath('c:/')", 'c:\\') |
| 436 | tester("ntpath.normpath('/../.././..')", '\\') |
| 437 | tester("ntpath.normpath('c:/../../..')", 'c:\\') |
| 438 | tester("ntpath.normpath('/./a/b')", r'\a\b') |
| 439 | tester("ntpath.normpath('c:/./a/b')", r'c:\a\b') |
| 440 | tester("ntpath.normpath('../.././..')", r'..\..\..') |
| 441 | tester("ntpath.normpath('K:../.././..')", r'K:..\..\..') |
| 442 | tester("ntpath.normpath('./a/b')", r'a\b') |
| 443 | tester("ntpath.normpath('c:./a/b')", r'c:a\b') |
| 444 | tester("ntpath.normpath('C:////a/b')", r'C:\a\b') |
| 445 | tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b') |
| 446 | |
| 447 | tester("ntpath.normpath('\\\\.\\NUL')", r'\\.\NUL') |
| 448 | tester("ntpath.normpath('\\\\?\\D:/XY\\Z')", r'\\?\D:/XY\Z') |
| 449 | tester("ntpath.normpath('handbook/../../Tests/image.png')", r'..\Tests\image.png') |
| 450 | tester("ntpath.normpath('handbook/../../../Tests/image.png')", r'..\..\Tests\image.png') |
| 451 | tester("ntpath.normpath('handbook///../a/.././../b/c')", r'..\b\c') |
| 452 | tester("ntpath.normpath('handbook/a/../..///../../b/c')", r'..\..\b\c') |
| 453 | |
| 454 | tester("ntpath.normpath('//server/share/..')" , '\\\\server\\share\\') |
| 455 | tester("ntpath.normpath('//server/share/../')" , '\\\\server\\share\\') |
| 456 | tester("ntpath.normpath('//server/share/../..')", '\\\\server\\share\\') |
| 457 | tester("ntpath.normpath('//server/share/../../')", '\\\\server\\share\\') |
| 458 | |
| 459 | # gh-96290: don't normalize partial/invalid UNC drives as rooted paths. |
| 460 | tester("ntpath.normpath('\\\\foo\\\\')", '\\\\foo\\\\') |
| 461 | tester("ntpath.normpath('\\\\foo\\')", '\\\\foo\\') |
| 462 | tester("ntpath.normpath('\\\\foo')", '\\\\foo') |
| 463 | tester("ntpath.normpath('\\\\')", '\\\\') |
| 464 | tester("ntpath.normpath('//?/UNC/server/share/..')", '\\\\?\\UNC\\server\\share\\') |
| 465 | |
| 466 | def test_normpath_invalid_paths(self): |
| 467 | normpath = ntpath.normpath |