(self)
| 586 | |
| 587 | @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname') |
| 588 | def test_realpath_invalid_paths(self): |
| 589 | realpath = ntpath.realpath |
| 590 | ABSTFN = ntpath.abspath(os_helper.TESTFN) |
| 591 | ABSTFNb = os.fsencode(ABSTFN) |
| 592 | path = ABSTFN + '\x00' |
| 593 | # gh-106242: Embedded nulls and non-strict fallback to abspath |
| 594 | self.assertEqual(realpath(path, strict=False), path) |
| 595 | # gh-106242: Embedded nulls should raise OSError (not ValueError) |
| 596 | self.assertRaises(OSError, realpath, path, strict=ALL_BUT_LAST) |
| 597 | self.assertRaises(OSError, realpath, path, strict=True) |
| 598 | self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING) |
| 599 | path = ABSTFNb + b'\x00' |
| 600 | self.assertEqual(realpath(path, strict=False), path) |
| 601 | self.assertRaises(OSError, realpath, path, strict=ALL_BUT_LAST) |
| 602 | self.assertRaises(OSError, realpath, path, strict=True) |
| 603 | self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING) |
| 604 | path = ABSTFN + '\\nonexistent\\x\x00' |
| 605 | self.assertEqual(realpath(path, strict=False), path) |
| 606 | self.assertRaises(OSError, realpath, path, strict=ALL_BUT_LAST) |
| 607 | self.assertRaises(OSError, realpath, path, strict=True) |
| 608 | self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING) |
| 609 | path = ABSTFNb + b'\\nonexistent\\x\x00' |
| 610 | self.assertEqual(realpath(path, strict=False), path) |
| 611 | self.assertRaises(OSError, realpath, path, strict=ALL_BUT_LAST) |
| 612 | self.assertRaises(OSError, realpath, path, strict=True) |
| 613 | self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING) |
| 614 | path = ABSTFN + '\x00\\..' |
| 615 | self.assertEqual(realpath(path, strict=False), os.getcwd()) |
| 616 | self.assertEqual(realpath(path, strict=ALL_BUT_LAST), os.getcwd()) |
| 617 | self.assertEqual(realpath(path, strict=True), os.getcwd()) |
| 618 | self.assertEqual(realpath(path, strict=ALLOW_MISSING), os.getcwd()) |
| 619 | path = ABSTFNb + b'\x00\\..' |
| 620 | self.assertEqual(realpath(path, strict=False), os.getcwdb()) |
| 621 | self.assertEqual(realpath(path, strict=ALL_BUT_LAST), os.getcwdb()) |
| 622 | self.assertEqual(realpath(path, strict=True), os.getcwdb()) |
| 623 | self.assertEqual(realpath(path, strict=ALLOW_MISSING), os.getcwdb()) |
| 624 | path = ABSTFN + '\\nonexistent\\x\x00\\..' |
| 625 | self.assertEqual(realpath(path, strict=False), ABSTFN + '\\nonexistent') |
| 626 | self.assertRaises(OSError, realpath, path, strict=ALL_BUT_LAST) |
| 627 | self.assertRaises(OSError, realpath, path, strict=True) |
| 628 | self.assertEqual(realpath(path, strict=ALLOW_MISSING), ABSTFN + '\\nonexistent') |
| 629 | path = ABSTFNb + b'\\nonexistent\\x\x00\\..' |
| 630 | self.assertEqual(realpath(path, strict=False), ABSTFNb + b'\\nonexistent') |
| 631 | self.assertRaises(OSError, realpath, path, strict=ALL_BUT_LAST) |
| 632 | self.assertRaises(OSError, realpath, path, strict=True) |
| 633 | self.assertEqual(realpath(path, strict=ALLOW_MISSING), ABSTFNb + b'\\nonexistent') |
| 634 | |
| 635 | @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname') |
| 636 | @_parameterize({}, {'strict': True}, {'strict': ALL_BUT_LAST}, {'strict': ALLOW_MISSING}) |
nothing calls this directly
no test coverage detected