MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_realpath_invalid_paths

Method test_realpath_invalid_paths

Lib/test/test_ntpath.py:582–619  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

580
581 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
582 def test_realpath_invalid_paths(self):
583 realpath = ntpath.realpath
584 ABSTFN = ntpath.abspath(os_helper.TESTFN)
585 ABSTFNb = os.fsencode(ABSTFN)
586 path = ABSTFN + '\x00'
587 # gh-106242: Embedded nulls and non-strict fallback to abspath
588 self.assertEqual(realpath(path, strict=False), path)
589 # gh-106242: Embedded nulls should raise OSError (not ValueError)
590 self.assertRaises(OSError, realpath, path, strict=True)
591 self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
592 path = ABSTFNb + b'\x00'
593 self.assertEqual(realpath(path, strict=False), path)
594 self.assertRaises(OSError, realpath, path, strict=True)
595 self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
596 path = ABSTFN + '\\nonexistent\\x\x00'
597 self.assertEqual(realpath(path, strict=False), path)
598 self.assertRaises(OSError, realpath, path, strict=True)
599 self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
600 path = ABSTFNb + b'\\nonexistent\\x\x00'
601 self.assertEqual(realpath(path, strict=False), path)
602 self.assertRaises(OSError, realpath, path, strict=True)
603 self.assertRaises(OSError, realpath, path, strict=ALLOW_MISSING)
604 path = ABSTFN + '\x00\\..'
605 self.assertEqual(realpath(path, strict=False), os.getcwd())
606 self.assertEqual(realpath(path, strict=True), os.getcwd())
607 self.assertEqual(realpath(path, strict=ALLOW_MISSING), os.getcwd())
608 path = ABSTFNb + b'\x00\\..'
609 self.assertEqual(realpath(path, strict=False), os.getcwdb())
610 self.assertEqual(realpath(path, strict=True), os.getcwdb())
611 self.assertEqual(realpath(path, strict=ALLOW_MISSING), os.getcwdb())
612 path = ABSTFN + '\\nonexistent\\x\x00\\..'
613 self.assertEqual(realpath(path, strict=False), ABSTFN + '\\nonexistent')
614 self.assertRaises(OSError, realpath, path, strict=True)
615 self.assertEqual(realpath(path, strict=ALLOW_MISSING), ABSTFN + '\\nonexistent')
616 path = ABSTFNb + b'\\nonexistent\\x\x00\\..'
617 self.assertEqual(realpath(path, strict=False), ABSTFNb + b'\\nonexistent')
618 self.assertRaises(OSError, realpath, path, strict=True)
619 self.assertEqual(realpath(path, strict=ALLOW_MISSING), ABSTFNb + b'\\nonexistent')
620
621 @unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
622 @_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})

Callers

nothing calls this directly

Calls 4

fsencodeMethod · 0.80
realpathFunction · 0.50
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected