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

Method test_realpath_invalid_paths

Lib/test/test_posixpath.py:495–588  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

493 os_helper.unlink(ABSTFN)
494
495 def test_realpath_invalid_paths(self):
496 path = '/\x00'
497 self.assertRaises(ValueError, realpath, path, strict=False)
498 self.assertRaises(ValueError, realpath, path, strict=True)
499 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
500 path = b'/\x00'
501 self.assertRaises(ValueError, realpath, path, strict=False)
502 self.assertRaises(ValueError, realpath, path, strict=True)
503 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
504 path = '/nonexistent/x\x00'
505 self.assertRaises(ValueError, realpath, path, strict=False)
506 self.assertRaises(FileNotFoundError, realpath, path, strict=True)
507 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
508 path = b'/nonexistent/x\x00'
509 self.assertRaises(ValueError, realpath, path, strict=False)
510 self.assertRaises(FileNotFoundError, realpath, path, strict=True)
511 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
512 path = '/\x00/..'
513 self.assertRaises(ValueError, realpath, path, strict=False)
514 self.assertRaises(ValueError, realpath, path, strict=True)
515 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
516 path = b'/\x00/..'
517 self.assertRaises(ValueError, realpath, path, strict=False)
518 self.assertRaises(ValueError, realpath, path, strict=True)
519 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
520
521 path = '/nonexistent/x\x00/..'
522 self.assertRaises(ValueError, realpath, path, strict=False)
523 self.assertRaises(FileNotFoundError, realpath, path, strict=True)
524 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
525 path = b'/nonexistent/x\x00/..'
526 self.assertRaises(ValueError, realpath, path, strict=False)
527 self.assertRaises(FileNotFoundError, realpath, path, strict=True)
528 self.assertRaises(ValueError, realpath, path, strict=ALLOW_MISSING)
529
530 path = '/\udfff'
531 if sys.platform == 'win32':
532 self.assertEqual(realpath(path, strict=False), path)
533 self.assertRaises(FileNotFoundError, realpath, path, strict=True)
534 self.assertEqual(realpath(path, strict=ALLOW_MISSING), path)
535 else:
536 self.assertRaises(UnicodeEncodeError, realpath, path, strict=False)
537 self.assertRaises(UnicodeEncodeError, realpath, path, strict=True)
538 self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING)
539 path = '/nonexistent/\udfff'
540 if sys.platform == 'win32':
541 self.assertEqual(realpath(path, strict=False), path)
542 self.assertEqual(realpath(path, strict=ALLOW_MISSING), path)
543 else:
544 self.assertRaises(UnicodeEncodeError, realpath, path, strict=False)
545 self.assertRaises(UnicodeEncodeError, realpath, path, strict=ALLOW_MISSING)
546 self.assertRaises(FileNotFoundError, realpath, path, strict=True)
547 path = '/\udfff/..'
548 if sys.platform == 'win32':
549 self.assertEqual(realpath(path, strict=False), '/')
550 self.assertRaises(FileNotFoundError, realpath, path, strict=True)
551 self.assertEqual(realpath(path, strict=ALLOW_MISSING), '/')
552 else:

Callers

nothing calls this directly

Calls 3

realpathFunction · 0.90
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected