Lines Matching refs:self
79 def assertPathEqual(self, path1, path2):
82 self.assertEqual(path1, path2)
84 def assertPathIn(self, path, pathset):
85 self.assertIn(_norm(path), _norm(pathset))
89 def test_splitext(self):
101 def test_splitdrive(self):
119 self.assertEqual(ntpath.splitdrive('//conky/MOUNTPOİNT/foo/bar'),
155 def test_split(self):
167 def test_isabs(self):
177 def test_commonprefix(self):
185 def test_join(self):
250 def test_normpath(self):
292 def test_realpath_curdir(self):
300 def test_realpath_pardir(self):
314 def test_realpath_basic(self):
317 self.addCleanup(os_helper.unlink, ABSTFN)
318 self.addCleanup(os_helper.unlink, ABSTFN + "1")
321 self.assertPathEqual(ntpath.realpath(ABSTFN + "1"), ABSTFN)
322 self.assertPathEqual(ntpath.realpath(os.fsencode(ABSTFN + "1")),
333 self.assertEqual(ntpath.realpath(d), d)
336 self.assertEqual(ABSTFN + "\0spam",
341 def test_realpath_strict(self):
346 self.addCleanup(os_helper.unlink, ABSTFN)
347 self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN, strict=True)
348 self.assertRaises(FileNotFoundError, ntpath.realpath, ABSTFN + "2", strict=True)
350 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "\0spam", strict=True)
354 def test_realpath_relative(self):
357 self.addCleanup(os_helper.unlink, ABSTFN)
358 self.addCleanup(os_helper.unlink, ABSTFN + "1")
361 self.assertPathEqual(ntpath.realpath(ABSTFN + "1"), ABSTFN)
365 def test_realpath_broken_symlinks(self):
368 self.addCleanup(os_helper.rmtree, ABSTFN)
376 os.symlink(".", "self")
379 os.symlink(r"self\self\broken", "broken2")
384 self.assertPathEqual(ntpath.realpath("broken"),
386 self.assertPathEqual(ntpath.realpath(r"broken\foo"),
390 self.assertPathEqual(ntpath.realpath(r"broken1"),
392 self.assertPathEqual(ntpath.realpath(r"broken1\baz"),
394 self.assertPathEqual(ntpath.realpath("broken2"),
395 ABSTFN + r"\self\self\missing")
396 self.assertPathEqual(ntpath.realpath("broken3"),
398 self.assertPathEqual(ntpath.realpath("broken4"),
400 self.assertPathEqual(ntpath.realpath("broken5"),
403 self.assertPathEqual(ntpath.realpath(b"broken"),
405 self.assertPathEqual(ntpath.realpath(rb"broken\foo"),
407 self.assertPathEqual(ntpath.realpath(rb"broken1"),
409 self.assertPathEqual(ntpath.realpath(rb"broken1\baz"),
411 self.assertPathEqual(ntpath.realpath(b"broken2"),
412 os.fsencode(ABSTFN + r"\self\self\missing"))
413 self.assertPathEqual(ntpath.realpath(rb"broken3"),
415 self.assertPathEqual(ntpath.realpath(b"broken4"),
417 self.assertPathEqual(ntpath.realpath(b"broken5"),
422 def test_realpath_symlink_loops(self):
427 self.addCleanup(os_helper.unlink, ABSTFN)
428 self.addCleanup(os_helper.unlink, ABSTFN + "1")
429 self.addCleanup(os_helper.unlink, ABSTFN + "2")
430 self.addCleanup(os_helper.unlink, ABSTFN + "y")
431 self.addCleanup(os_helper.unlink, ABSTFN + "c")
432 self.addCleanup(os_helper.unlink, ABSTFN + "a")
435 self.assertPathEqual(ntpath.realpath(ABSTFN), ABSTFN)
440 self.assertPathIn(ntpath.realpath(ABSTFN + "1"), expected)
441 self.assertPathIn(ntpath.realpath(ABSTFN + "2"), expected)
443 self.assertPathIn(ntpath.realpath(ABSTFN + "1\\x"),
445 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\.."),
447 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\x"),
450 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..\\"
453 self.assertPathIn(ntpath.realpath(ABSTFN + "1\\..\\"
458 self.assertPathEqual(ntpath.realpath(ABSTFN + "a"), ABSTFN + "a")
462 self.assertPathEqual(ntpath.realpath(ABSTFN + "c"), ABSTFN + "c")
465 self.assertPathEqual(ntpath.realpath(ntpath.basename(ABSTFN)), ABSTFN)
469 def test_realpath_symlink_loops_strict(self):
472 self.addCleanup(os_helper.unlink, ABSTFN)
473 self.addCleanup(os_helper.unlink, ABSTFN + "1")
474 self.addCleanup(os_helper.unlink, ABSTFN + "2")
475 self.addCleanup(os_helper.unlink, ABSTFN + "y")
476 self.addCleanup(os_helper.unlink, ABSTFN + "c")
477 self.addCleanup(os_helper.unlink, ABSTFN + "a")
480 self.assertRaises(OSError, ntpath.realpath, ABSTFN, strict=True)
484 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1", strict=True)
485 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "2", strict=True)
486 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\x", strict=True)
489 self.assertPathEqual(ntpath.realpath(ABSTFN + "1\\..", strict=True),
491 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\x", strict=True)
493 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "1\\..\\"
496 self.assertRaises(OSError, ntpath.realpath,
501 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "a", strict=True)
505 self.assertRaises(OSError, ntpath.realpath, ABSTFN + "c", strict=True)
508 self.assertRaises(OSError, ntpath.realpath, ntpath.basename(ABSTFN),
513 def test_realpath_symlink_prefix(self):
515 self.addCleanup(os_helper.unlink, ABSTFN + "3")
516 self.addCleanup(os_helper.unlink, "\\\\?\\" + ABSTFN + "3.")
517 self.addCleanup(os_helper.unlink, ABSTFN + "3link")
518 self.addCleanup(os_helper.unlink, ABSTFN + "3.link")
528 self.assertPathEqual(ntpath.realpath(ABSTFN + "3link"),
530 self.assertPathEqual(ntpath.realpath(ABSTFN + "3.link"),
535 self.assertEqual(f.read(), b'0')
537 self.assertEqual(f.read(), b'1')
540 self.assertPathEqual(ntpath.realpath("\\\\?\\" + ABSTFN + "3link"),
542 self.assertPathEqual(ntpath.realpath("\\\\?\\" + ABSTFN + "3.link"),
546 def test_realpath_nul(self):
551 def test_realpath_cwd(self):
557 self.addCleanup(os_helper.rmtree, ABSTFN)
569 self.assertPathEqual(test_file_long, ntpath.realpath(test_file_short))
572 self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
574 self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
576 self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
578 def test_expandvars(self):
605 def test_expandvars_nonascii(self):
624 def test_expanduser(self):
674 def test_abspath(self):
717 def test_relpath(self):
741 def test_commonpath(self):
746 self.assertRaises(exc, ntpath.commonpath, paths)
747 self.assertRaises(exc, ntpath.commonpath,
750 self.assertRaises(ValueError, ntpath.commonpath, [])
797 self.assertRaises(TypeError, ntpath.commonpath,
799 self.assertRaises(TypeError, ntpath.commonpath,
801 self.assertRaises(TypeError, ntpath.commonpath,
803 self.assertRaises(TypeError, ntpath.commonpath,
805 self.assertRaises(TypeError, ntpath.commonpath,
807 self.assertRaises(TypeError, ntpath.commonpath,
811 def test_sameopenfile(self):
814 self.assertTrue(ntpath.sameopenfile(tf1.fileno(), tf1.fileno()))
816 self.assertFalse(ntpath.sameopenfile(tf1.fileno(), tf2.fileno()))
819 with self.assertRaises(OSError):
824 def test_ismount(self):
825 self.assertTrue(ntpath.ismount("c:\\"))
826 self.assertTrue(ntpath.ismount("C:\\"))
827 self.assertTrue(ntpath.ismount("c:/"))
828 self.assertTrue(ntpath.ismount("C:/"))
829 self.assertTrue(ntpath.ismount("\\\\.\\c:\\"))
830 self.assertTrue(ntpath.ismount("\\\\.\\C:\\"))
832 self.assertTrue(ntpath.ismount(b"c:\\"))
833 self.assertTrue(ntpath.ismount(b"C:\\"))
834 self.assertTrue(ntpath.ismount(b"c:/"))
835 self.assertTrue(ntpath.ismount(b"C:/"))
836 self.assertTrue(ntpath.ismount(b"\\\\.\\c:\\"))
837 self.assertTrue(ntpath.ismount(b"\\\\.\\C:\\"))
840 self.assertFalse(ntpath.ismount(d))
851 self.assertFalse(ntpath.ismount(drive.lower()))
852 self.assertFalse(ntpath.ismount(drive.upper()))
854 self.assertTrue(ntpath.ismount("\\\\localhost\\c$"))
855 self.assertTrue(ntpath.ismount("\\\\localhost\\c$\\"))
857 self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$"))
858 self.assertTrue(ntpath.ismount(b"\\\\localhost\\c$\\"))
860 def assertEqualCI(self, s1, s2):
862 self.assertEqual(s1.lower(), s2.lower())
865 def test_nt_helpers(self):
875 self.assertEqualCI(path_drive, volume_path_drive)
878 self.assertGreater(cap, 0)
879 self.assertGreater(free, 0)
882 self.assertEqual(b_cap, cap)
883 self.assertGreater(b_free, 0)
887 self.assertIsInstance(final_path, str)
888 self.assertGreater(len(final_path), 0)
891 self.assertIsInstance(b_final_path, bytes)
892 self.assertGreater(len(b_final_path), 0)
903 def setUp(self):
904 self.file_name = os_helper.TESTFN
905 self.file_path = FakePath(os_helper.TESTFN)
906 self.addCleanup(os_helper.unlink, self.file_name)
907 with open(self.file_name, 'xb', 0) as file:
910 def _check_function(self, func):
911 self.assertPathEqual(func(self.file_path), func(self.file_name))
913 def test_path_normcase(self):
914 self._check_function(self.path.normcase)
916 self.assertEqual(ntpath.normcase('\u03a9\u2126'), 'ωΩ')
918 def test_path_isabs(self):
919 self._check_function(self.path.isabs)
921 def test_path_join(self):
922 self.assertEqual(self.path.join('a', FakePath('b'), 'c'),
923 self.path.join('a', 'b', 'c'))
925 def test_path_split(self):
926 self._check_function(self.path.split)
928 def test_path_splitext(self):
929 self._check_function(self.path.splitext)
931 def test_path_splitdrive(self):
932 self._check_function(self.path.splitdrive)
934 def test_path_basename(self):
935 self._check_function(self.path.basename)
937 def test_path_dirname(self):
938 self._check_function(self.path.dirname)
940 def test_path_islink(self):
941 self._check_function(self.path.islink)
943 def test_path_lexists(self):
944 self._check_function(self.path.lexists)
946 def test_path_ismount(self):
947 self._check_function(self.path.ismount)
949 def test_path_expanduser(self):
950 self._check_function(self.path.expanduser)
952 def test_path_expandvars(self):
953 self._check_function(self.path.expandvars)
955 def test_path_normpath(self):
956 self._check_function(self.path.normpath)
958 def test_path_abspath(self):
959 self._check_function(self.path.abspath)
961 def test_path_realpath(self):
962 self._check_function(self.path.realpath)
964 def test_path_relpath(self):
965 self._check_function(self.path.relpath)
967 def test_path_commonpath(self):
968 common_path = self.path.commonpath([self.file_path, self.file_name])
969 self.assertPathEqual(common_path, self.file_name)
971 def test_path_isdir(self):
972 self._check_function(self.path.isdir)