mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	GH-89812: Make symlink support configurable in pathlib tests. (GH-106060)
Adjust the pathlib tests to add a new `PathTest.can_symlink` class attribute, which allows us to enable or disable symlink support in tests. A (near-)future commit will add an `AbstractPath` class; its tests will hard-code the value to `True` or `False` depending on a stub subclass's capabilities.
This commit is contained in:
		
							parent
							
								
									200f255411
								
							
						
					
					
						commit
						3fd99b5a97
					
				
					 1 changed files with 52 additions and 36 deletions
				
			
		|  | @ -1573,6 +1573,7 @@ class PathTest(unittest.TestCase): | ||||||
|     """Tests for the FS-accessing functionalities of the Path classes.""" |     """Tests for the FS-accessing functionalities of the Path classes.""" | ||||||
| 
 | 
 | ||||||
|     cls = pathlib.Path |     cls = pathlib.Path | ||||||
|  |     can_symlink = os_helper.can_symlink() | ||||||
| 
 | 
 | ||||||
|     # (BASE) |     # (BASE) | ||||||
|     #  | |     #  | | ||||||
|  | @ -1616,7 +1617,7 @@ def cleanup(): | ||||||
|         with open(join('dirC', 'dirD', 'fileD'), 'wb') as f: |         with open(join('dirC', 'dirD', 'fileD'), 'wb') as f: | ||||||
|             f.write(b"this is file D\n") |             f.write(b"this is file D\n") | ||||||
|         os.chmod(join('dirE'), 0) |         os.chmod(join('dirE'), 0) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             # Relative symlinks. |             # Relative symlinks. | ||||||
|             os.symlink('fileA', join('linkA')) |             os.symlink('fileA', join('linkA')) | ||||||
|             os.symlink('non-existing', join('brokenLink')) |             os.symlink('non-existing', join('brokenLink')) | ||||||
|  | @ -1672,7 +1673,7 @@ def test_exists(self): | ||||||
|         self.assertIs(True, (p / 'dirA').exists()) |         self.assertIs(True, (p / 'dirA').exists()) | ||||||
|         self.assertIs(True, (p / 'fileA').exists()) |         self.assertIs(True, (p / 'fileA').exists()) | ||||||
|         self.assertIs(False, (p / 'fileA' / 'bah').exists()) |         self.assertIs(False, (p / 'fileA' / 'bah').exists()) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertIs(True, (p / 'linkA').exists()) |             self.assertIs(True, (p / 'linkA').exists()) | ||||||
|             self.assertIs(True, (p / 'linkB').exists()) |             self.assertIs(True, (p / 'linkB').exists()) | ||||||
|             self.assertIs(True, (p / 'linkB' / 'fileB').exists()) |             self.assertIs(True, (p / 'linkB' / 'fileB').exists()) | ||||||
|  | @ -1739,12 +1740,13 @@ def test_iterdir(self): | ||||||
|         it = p.iterdir() |         it = p.iterdir() | ||||||
|         paths = set(it) |         paths = set(it) | ||||||
|         expected = ['dirA', 'dirB', 'dirC', 'dirE', 'fileA'] |         expected = ['dirA', 'dirB', 'dirC', 'dirE', 'fileA'] | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             expected += ['linkA', 'linkB', 'brokenLink', 'brokenLinkLoop'] |             expected += ['linkA', 'linkB', 'brokenLink', 'brokenLinkLoop'] | ||||||
|         self.assertEqual(paths, { P(BASE, q) for q in expected }) |         self.assertEqual(paths, { P(BASE, q) for q in expected }) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_iterdir_symlink(self): |     def test_iterdir_symlink(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         # __iter__ on a symlink to a directory. |         # __iter__ on a symlink to a directory. | ||||||
|         P = self.cls |         P = self.cls | ||||||
|         p = P(BASE, 'linkB') |         p = P(BASE, 'linkB') | ||||||
|  | @ -1772,23 +1774,23 @@ def _check(glob, expected): | ||||||
|         _check(it, ["fileA"]) |         _check(it, ["fileA"]) | ||||||
|         _check(p.glob("fileB"), []) |         _check(p.glob("fileB"), []) | ||||||
|         _check(p.glob("dir*/file*"), ["dirB/fileB", "dirC/fileC"]) |         _check(p.glob("dir*/file*"), ["dirB/fileB", "dirC/fileC"]) | ||||||
|         if not os_helper.can_symlink(): |         if not self.can_symlink: | ||||||
|             _check(p.glob("*A"), ['dirA', 'fileA']) |             _check(p.glob("*A"), ['dirA', 'fileA']) | ||||||
|         else: |         else: | ||||||
|             _check(p.glob("*A"), ['dirA', 'fileA', 'linkA']) |             _check(p.glob("*A"), ['dirA', 'fileA', 'linkA']) | ||||||
|         if not os_helper.can_symlink(): |         if not self.can_symlink: | ||||||
|             _check(p.glob("*B/*"), ['dirB/fileB']) |             _check(p.glob("*B/*"), ['dirB/fileB']) | ||||||
|         else: |         else: | ||||||
|             _check(p.glob("*B/*"), ['dirB/fileB', 'dirB/linkD', |             _check(p.glob("*B/*"), ['dirB/fileB', 'dirB/linkD', | ||||||
|                                     'linkB/fileB', 'linkB/linkD']) |                                     'linkB/fileB', 'linkB/linkD']) | ||||||
|         if not os_helper.can_symlink(): |         if not self.can_symlink: | ||||||
|             _check(p.glob("*/fileB"), ['dirB/fileB']) |             _check(p.glob("*/fileB"), ['dirB/fileB']) | ||||||
|         else: |         else: | ||||||
|             _check(p.glob("*/fileB"), ['dirB/fileB', 'linkB/fileB']) |             _check(p.glob("*/fileB"), ['dirB/fileB', 'linkB/fileB']) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             _check(p.glob("brokenLink"), ['brokenLink']) |             _check(p.glob("brokenLink"), ['brokenLink']) | ||||||
| 
 | 
 | ||||||
|         if not os_helper.can_symlink(): |         if not self.can_symlink: | ||||||
|             _check(p.glob("*/"), ["dirA", "dirB", "dirC", "dirE"]) |             _check(p.glob("*/"), ["dirA", "dirB", "dirC", "dirE"]) | ||||||
|         else: |         else: | ||||||
|             _check(p.glob("*/"), ["dirA", "dirB", "dirC", "dirE", "linkB"]) |             _check(p.glob("*/"), ["dirA", "dirB", "dirC", "dirE", "linkB"]) | ||||||
|  | @ -1810,8 +1812,9 @@ def _check(path, pattern, case_sensitive, expected): | ||||||
|         _check(path, "dirb/file*", True, []) |         _check(path, "dirb/file*", True, []) | ||||||
|         _check(path, "dirb/file*", False, ["dirB/fileB"]) |         _check(path, "dirb/file*", False, ["dirB/fileB"]) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_glob_follow_symlinks_common(self): |     def test_glob_follow_symlinks_common(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         def _check(path, glob, expected): |         def _check(path, glob, expected): | ||||||
|             actual = {path for path in path.glob(glob, follow_symlinks=True) |             actual = {path for path in path.glob(glob, follow_symlinks=True) | ||||||
|                       if "linkD" not in path.parent.parts}  # exclude symlink loop. |                       if "linkD" not in path.parent.parts}  # exclude symlink loop. | ||||||
|  | @ -1835,8 +1838,9 @@ def _check(path, glob, expected): | ||||||
|         _check(p, "dir*/*/../dirD/**/", ["dirC/dirD/../dirD"]) |         _check(p, "dir*/*/../dirD/**/", ["dirC/dirD/../dirD"]) | ||||||
|         _check(p, "*/dirD/**/", ["dirC/dirD"]) |         _check(p, "*/dirD/**/", ["dirC/dirD"]) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_glob_no_follow_symlinks_common(self): |     def test_glob_no_follow_symlinks_common(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         def _check(path, glob, expected): |         def _check(path, glob, expected): | ||||||
|             actual = {path for path in path.glob(glob, follow_symlinks=False)} |             actual = {path for path in path.glob(glob, follow_symlinks=False)} | ||||||
|             self.assertEqual(actual, { P(BASE, q) for q in expected }) |             self.assertEqual(actual, { P(BASE, q) for q in expected }) | ||||||
|  | @ -1868,14 +1872,14 @@ def _check(glob, expected): | ||||||
|         _check(p.rglob("fileB"), ["dirB/fileB"]) |         _check(p.rglob("fileB"), ["dirB/fileB"]) | ||||||
|         _check(p.rglob("**/fileB"), ["dirB/fileB"]) |         _check(p.rglob("**/fileB"), ["dirB/fileB"]) | ||||||
|         _check(p.rglob("*/fileA"), []) |         _check(p.rglob("*/fileA"), []) | ||||||
|         if not os_helper.can_symlink(): |         if not self.can_symlink: | ||||||
|             _check(p.rglob("*/fileB"), ["dirB/fileB"]) |             _check(p.rglob("*/fileB"), ["dirB/fileB"]) | ||||||
|         else: |         else: | ||||||
|             _check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB", |             _check(p.rglob("*/fileB"), ["dirB/fileB", "dirB/linkD/fileB", | ||||||
|                                         "linkB/fileB", "dirA/linkC/fileB"]) |                                         "linkB/fileB", "dirA/linkC/fileB"]) | ||||||
|         _check(p.rglob("file*"), ["fileA", "dirB/fileB", |         _check(p.rglob("file*"), ["fileA", "dirB/fileB", | ||||||
|                                   "dirC/fileC", "dirC/dirD/fileD"]) |                                   "dirC/fileC", "dirC/dirD/fileD"]) | ||||||
|         if not os_helper.can_symlink(): |         if not self.can_symlink: | ||||||
|             _check(p.rglob("*/"), [ |             _check(p.rglob("*/"), [ | ||||||
|                 "dirA", "dirB", "dirC", "dirC/dirD", "dirE", |                 "dirA", "dirB", "dirC", "dirC/dirD", "dirE", | ||||||
|             ]) |             ]) | ||||||
|  | @ -1900,8 +1904,9 @@ def _check(glob, expected): | ||||||
|         _check(p.rglob("*.txt"), ["dirC/novel.txt"]) |         _check(p.rglob("*.txt"), ["dirC/novel.txt"]) | ||||||
|         _check(p.rglob("*.*"), ["dirC/novel.txt"]) |         _check(p.rglob("*.*"), ["dirC/novel.txt"]) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_rglob_follow_symlinks_common(self): |     def test_rglob_follow_symlinks_common(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         def _check(path, glob, expected): |         def _check(path, glob, expected): | ||||||
|             actual = {path for path in path.rglob(glob, follow_symlinks=True) |             actual = {path for path in path.rglob(glob, follow_symlinks=True) | ||||||
|                       if 'linkD' not in path.parent.parts}  # exclude symlink loop. |                       if 'linkD' not in path.parent.parts}  # exclude symlink loop. | ||||||
|  | @ -1929,8 +1934,9 @@ def _check(path, glob, expected): | ||||||
|         _check(p, "*.txt", ["dirC/novel.txt"]) |         _check(p, "*.txt", ["dirC/novel.txt"]) | ||||||
|         _check(p, "*.*", ["dirC/novel.txt"]) |         _check(p, "*.*", ["dirC/novel.txt"]) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_rglob_no_follow_symlinks_common(self): |     def test_rglob_no_follow_symlinks_common(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         def _check(path, glob, expected): |         def _check(path, glob, expected): | ||||||
|             actual = {path for path in path.rglob(glob, follow_symlinks=False)} |             actual = {path for path in path.rglob(glob, follow_symlinks=False)} | ||||||
|             self.assertEqual(actual, { P(BASE, q) for q in expected }) |             self.assertEqual(actual, { P(BASE, q) for q in expected }) | ||||||
|  | @ -1954,9 +1960,10 @@ def _check(path, glob, expected): | ||||||
|         _check(p, "*.txt", ["dirC/novel.txt"]) |         _check(p, "*.txt", ["dirC/novel.txt"]) | ||||||
|         _check(p, "*.*", ["dirC/novel.txt"]) |         _check(p, "*.*", ["dirC/novel.txt"]) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_rglob_symlink_loop(self): |     def test_rglob_symlink_loop(self): | ||||||
|         # Don't get fooled by symlink loops (Issue #26012). |         # Don't get fooled by symlink loops (Issue #26012). | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         P = self.cls |         P = self.cls | ||||||
|         p = P(BASE) |         p = P(BASE) | ||||||
|         given = set(p.rglob('*')) |         given = set(p.rglob('*')) | ||||||
|  | @ -2003,9 +2010,10 @@ def test_glob_dotdot(self): | ||||||
|         self.assertEqual(set(p.glob("xyzzy/..")), set()) |         self.assertEqual(set(p.glob("xyzzy/..")), set()) | ||||||
|         self.assertEqual(set(p.glob("/".join([".."] * 50))), { P(BASE, *[".."] * 50)}) |         self.assertEqual(set(p.glob("/".join([".."] * 50))), { P(BASE, *[".."] * 50)}) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_glob_permissions(self): |     def test_glob_permissions(self): | ||||||
|         # See bpo-38894 |         # See bpo-38894 | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         P = self.cls |         P = self.cls | ||||||
|         base = P(BASE) / 'permissions' |         base = P(BASE) / 'permissions' | ||||||
|         base.mkdir() |         base.mkdir() | ||||||
|  | @ -2023,9 +2031,10 @@ def test_glob_permissions(self): | ||||||
|         self.assertEqual(len(set(base.glob("*/fileC"))), 50) |         self.assertEqual(len(set(base.glob("*/fileC"))), 50) | ||||||
|         self.assertEqual(len(set(base.glob("*/file*"))), 50) |         self.assertEqual(len(set(base.glob("*/file*"))), 50) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_glob_long_symlink(self): |     def test_glob_long_symlink(self): | ||||||
|         # See gh-87695 |         # See gh-87695 | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         base = self.cls(BASE) / 'long_symlink' |         base = self.cls(BASE) / 'long_symlink' | ||||||
|         base.mkdir() |         base.mkdir() | ||||||
|         bad_link = base / 'bad_link' |         bad_link = base / 'bad_link' | ||||||
|  | @ -2043,8 +2052,9 @@ def test_glob_above_recursion_limit(self): | ||||||
|         with set_recursion_limit(recursion_limit): |         with set_recursion_limit(recursion_limit): | ||||||
|             list(base.glob('**')) |             list(base.glob('**')) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_readlink(self): |     def test_readlink(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         P = self.cls(BASE) |         P = self.cls(BASE) | ||||||
|         self.assertEqual((P / 'linkA').readlink(), self.cls('fileA')) |         self.assertEqual((P / 'linkA').readlink(), self.cls('fileA')) | ||||||
|         self.assertEqual((P / 'brokenLink').readlink(), |         self.assertEqual((P / 'brokenLink').readlink(), | ||||||
|  | @ -2067,8 +2077,9 @@ def _check_resolve(self, p, expected, strict=True): | ||||||
|     # This can be used to check both relative and absolute resolutions. |     # This can be used to check both relative and absolute resolutions. | ||||||
|     _check_resolve_relative = _check_resolve_absolute = _check_resolve |     _check_resolve_relative = _check_resolve_absolute = _check_resolve | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_resolve_common(self): |     def test_resolve_common(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         P = self.cls |         P = self.cls | ||||||
|         p = P(BASE, 'foo') |         p = P(BASE, 'foo') | ||||||
|         with self.assertRaises(OSError) as cm: |         with self.assertRaises(OSError) as cm: | ||||||
|  | @ -2128,9 +2139,10 @@ def test_resolve_common(self): | ||||||
|             # resolves to 'dirB/..' first before resolving to parent of dirB. |             # resolves to 'dirB/..' first before resolving to parent of dirB. | ||||||
|             self._check_resolve_relative(p, P(BASE, 'foo', 'in', 'spam'), False) |             self._check_resolve_relative(p, P(BASE, 'foo', 'in', 'spam'), False) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_resolve_dot(self): |     def test_resolve_dot(self): | ||||||
|         # See http://web.archive.org/web/20200623062557/https://bitbucket.org/pitrou/pathlib/issues/9/ |         # See http://web.archive.org/web/20200623062557/https://bitbucket.org/pitrou/pathlib/issues/9/ | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         p = self.cls(BASE) |         p = self.cls(BASE) | ||||||
|         p.joinpath('0').symlink_to('.', target_is_directory=True) |         p.joinpath('0').symlink_to('.', target_is_directory=True) | ||||||
|         p.joinpath('1').symlink_to(os.path.join('0', '0'), target_is_directory=True) |         p.joinpath('1').symlink_to(os.path.join('0', '0'), target_is_directory=True) | ||||||
|  | @ -2152,8 +2164,9 @@ def test_stat(self): | ||||||
|         self.addCleanup(p.chmod, st.st_mode) |         self.addCleanup(p.chmod, st.st_mode) | ||||||
|         self.assertNotEqual(p.stat(), st) |         self.assertNotEqual(p.stat(), st) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_stat_no_follow_symlinks(self): |     def test_stat_no_follow_symlinks(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         p = self.cls(BASE) / 'linkA' |         p = self.cls(BASE) / 'linkA' | ||||||
|         st = p.stat() |         st = p.stat() | ||||||
|         self.assertNotEqual(st, p.stat(follow_symlinks=False)) |         self.assertNotEqual(st, p.stat(follow_symlinks=False)) | ||||||
|  | @ -2163,8 +2176,9 @@ def test_stat_no_follow_symlinks_nosymlink(self): | ||||||
|         st = p.stat() |         st = p.stat() | ||||||
|         self.assertEqual(st, p.stat(follow_symlinks=False)) |         self.assertEqual(st, p.stat(follow_symlinks=False)) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_lstat(self): |     def test_lstat(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         p = self.cls(BASE)/ 'linkA' |         p = self.cls(BASE)/ 'linkA' | ||||||
|         st = p.stat() |         st = p.stat() | ||||||
|         self.assertNotEqual(st, p.lstat()) |         self.assertNotEqual(st, p.lstat()) | ||||||
|  | @ -2180,7 +2194,7 @@ def test_is_dir(self): | ||||||
|         self.assertFalse((P / 'fileA').is_dir()) |         self.assertFalse((P / 'fileA').is_dir()) | ||||||
|         self.assertFalse((P / 'non-existing').is_dir()) |         self.assertFalse((P / 'non-existing').is_dir()) | ||||||
|         self.assertFalse((P / 'fileA' / 'bah').is_dir()) |         self.assertFalse((P / 'fileA' / 'bah').is_dir()) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertFalse((P / 'linkA').is_dir()) |             self.assertFalse((P / 'linkA').is_dir()) | ||||||
|             self.assertTrue((P / 'linkB').is_dir()) |             self.assertTrue((P / 'linkB').is_dir()) | ||||||
|             self.assertFalse((P/ 'brokenLink').is_dir()) |             self.assertFalse((P/ 'brokenLink').is_dir()) | ||||||
|  | @ -2193,7 +2207,7 @@ def test_is_dir_no_follow_symlinks(self): | ||||||
|         self.assertFalse((P / 'fileA').is_dir(follow_symlinks=False)) |         self.assertFalse((P / 'fileA').is_dir(follow_symlinks=False)) | ||||||
|         self.assertFalse((P / 'non-existing').is_dir(follow_symlinks=False)) |         self.assertFalse((P / 'non-existing').is_dir(follow_symlinks=False)) | ||||||
|         self.assertFalse((P / 'fileA' / 'bah').is_dir(follow_symlinks=False)) |         self.assertFalse((P / 'fileA' / 'bah').is_dir(follow_symlinks=False)) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertFalse((P / 'linkA').is_dir(follow_symlinks=False)) |             self.assertFalse((P / 'linkA').is_dir(follow_symlinks=False)) | ||||||
|             self.assertFalse((P / 'linkB').is_dir(follow_symlinks=False)) |             self.assertFalse((P / 'linkB').is_dir(follow_symlinks=False)) | ||||||
|             self.assertFalse((P/ 'brokenLink').is_dir(follow_symlinks=False)) |             self.assertFalse((P/ 'brokenLink').is_dir(follow_symlinks=False)) | ||||||
|  | @ -2206,7 +2220,7 @@ def test_is_file(self): | ||||||
|         self.assertFalse((P / 'dirA').is_file()) |         self.assertFalse((P / 'dirA').is_file()) | ||||||
|         self.assertFalse((P / 'non-existing').is_file()) |         self.assertFalse((P / 'non-existing').is_file()) | ||||||
|         self.assertFalse((P / 'fileA' / 'bah').is_file()) |         self.assertFalse((P / 'fileA' / 'bah').is_file()) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertTrue((P / 'linkA').is_file()) |             self.assertTrue((P / 'linkA').is_file()) | ||||||
|             self.assertFalse((P / 'linkB').is_file()) |             self.assertFalse((P / 'linkB').is_file()) | ||||||
|             self.assertFalse((P/ 'brokenLink').is_file()) |             self.assertFalse((P/ 'brokenLink').is_file()) | ||||||
|  | @ -2219,7 +2233,7 @@ def test_is_file_no_follow_symlinks(self): | ||||||
|         self.assertFalse((P / 'dirA').is_file(follow_symlinks=False)) |         self.assertFalse((P / 'dirA').is_file(follow_symlinks=False)) | ||||||
|         self.assertFalse((P / 'non-existing').is_file(follow_symlinks=False)) |         self.assertFalse((P / 'non-existing').is_file(follow_symlinks=False)) | ||||||
|         self.assertFalse((P / 'fileA' / 'bah').is_file(follow_symlinks=False)) |         self.assertFalse((P / 'fileA' / 'bah').is_file(follow_symlinks=False)) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertFalse((P / 'linkA').is_file(follow_symlinks=False)) |             self.assertFalse((P / 'linkA').is_file(follow_symlinks=False)) | ||||||
|             self.assertFalse((P / 'linkB').is_file(follow_symlinks=False)) |             self.assertFalse((P / 'linkB').is_file(follow_symlinks=False)) | ||||||
|             self.assertFalse((P/ 'brokenLink').is_file(follow_symlinks=False)) |             self.assertFalse((P/ 'brokenLink').is_file(follow_symlinks=False)) | ||||||
|  | @ -2237,7 +2251,7 @@ def test_is_mount(self): | ||||||
|         self.assertFalse((P / 'non-existing').is_mount()) |         self.assertFalse((P / 'non-existing').is_mount()) | ||||||
|         self.assertFalse((P / 'fileA' / 'bah').is_mount()) |         self.assertFalse((P / 'fileA' / 'bah').is_mount()) | ||||||
|         self.assertTrue(R.is_mount()) |         self.assertTrue(R.is_mount()) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertFalse((P / 'linkA').is_mount()) |             self.assertFalse((P / 'linkA').is_mount()) | ||||||
|         self.assertIs((R / '\udfff').is_mount(), False) |         self.assertIs((R / '\udfff').is_mount(), False) | ||||||
| 
 | 
 | ||||||
|  | @ -2247,13 +2261,13 @@ def test_is_symlink(self): | ||||||
|         self.assertFalse((P / 'dirA').is_symlink()) |         self.assertFalse((P / 'dirA').is_symlink()) | ||||||
|         self.assertFalse((P / 'non-existing').is_symlink()) |         self.assertFalse((P / 'non-existing').is_symlink()) | ||||||
|         self.assertFalse((P / 'fileA' / 'bah').is_symlink()) |         self.assertFalse((P / 'fileA' / 'bah').is_symlink()) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertTrue((P / 'linkA').is_symlink()) |             self.assertTrue((P / 'linkA').is_symlink()) | ||||||
|             self.assertTrue((P / 'linkB').is_symlink()) |             self.assertTrue((P / 'linkB').is_symlink()) | ||||||
|             self.assertTrue((P/ 'brokenLink').is_symlink()) |             self.assertTrue((P/ 'brokenLink').is_symlink()) | ||||||
|         self.assertIs((P / 'fileA\udfff').is_file(), False) |         self.assertIs((P / 'fileA\udfff').is_file(), False) | ||||||
|         self.assertIs((P / 'fileA\x00').is_file(), False) |         self.assertIs((P / 'fileA\x00').is_file(), False) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertIs((P / 'linkA\udfff').is_file(), False) |             self.assertIs((P / 'linkA\udfff').is_file(), False) | ||||||
|             self.assertIs((P / 'linkA\x00').is_file(), False) |             self.assertIs((P / 'linkA\x00').is_file(), False) | ||||||
| 
 | 
 | ||||||
|  | @ -2310,6 +2324,9 @@ def test_parts_interning(self): | ||||||
|         self.assertIs(p.parts[2], q.parts[3]) |         self.assertIs(p.parts[2], q.parts[3]) | ||||||
| 
 | 
 | ||||||
|     def _check_complex_symlinks(self, link0_target): |     def _check_complex_symlinks(self, link0_target): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|  | 
 | ||||||
|         # Test solving a non-looping chain of symlinks (issue #19887). |         # Test solving a non-looping chain of symlinks (issue #19887). | ||||||
|         P = self.cls(BASE) |         P = self.cls(BASE) | ||||||
|         P.joinpath('link1').symlink_to(os.path.join('link0', 'link0'), target_is_directory=True) |         P.joinpath('link1').symlink_to(os.path.join('link0', 'link0'), target_is_directory=True) | ||||||
|  | @ -2350,15 +2367,12 @@ def _check_complex_symlinks(self, link0_target): | ||||||
|         finally: |         finally: | ||||||
|             os.chdir(old_path) |             os.chdir(old_path) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_complex_symlinks_absolute(self): |     def test_complex_symlinks_absolute(self): | ||||||
|         self._check_complex_symlinks(BASE) |         self._check_complex_symlinks(BASE) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_complex_symlinks_relative(self): |     def test_complex_symlinks_relative(self): | ||||||
|         self._check_complex_symlinks('.') |         self._check_complex_symlinks('.') | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_complex_symlinks_relative_dot_dot(self): |     def test_complex_symlinks_relative_dot_dot(self): | ||||||
|         self._check_complex_symlinks(os.path.join('dirA', '..')) |         self._check_complex_symlinks(os.path.join('dirA', '..')) | ||||||
| 
 | 
 | ||||||
|  | @ -2462,7 +2476,7 @@ def with_segments(self, *pathsegments): | ||||||
|             self.assertEqual(42, p.with_segments('~').expanduser().session_id) |             self.assertEqual(42, p.with_segments('~').expanduser().session_id) | ||||||
|         self.assertEqual(42, (p / 'fileA').rename(p / 'fileB').session_id) |         self.assertEqual(42, (p / 'fileA').rename(p / 'fileB').session_id) | ||||||
|         self.assertEqual(42, (p / 'fileB').replace(p / 'fileA').session_id) |         self.assertEqual(42, (p / 'fileB').replace(p / 'fileA').session_id) | ||||||
|         if os_helper.can_symlink(): |         if self.can_symlink: | ||||||
|             self.assertEqual(42, (p / 'linkA').readlink().session_id) |             self.assertEqual(42, (p / 'linkA').readlink().session_id) | ||||||
|         for path in p.iterdir(): |         for path in p.iterdir(): | ||||||
|             self.assertEqual(42, path.session_id) |             self.assertEqual(42, path.session_id) | ||||||
|  | @ -2783,8 +2797,9 @@ def my_mkdir(path, mode=0o777): | ||||||
|                 self.assertNotIn(str(p12), concurrently_created) |                 self.assertNotIn(str(p12), concurrently_created) | ||||||
|             self.assertTrue(p.exists()) |             self.assertTrue(p.exists()) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_symlink_to(self): |     def test_symlink_to(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         P = self.cls(BASE) |         P = self.cls(BASE) | ||||||
|         target = P / 'fileA' |         target = P / 'fileA' | ||||||
|         # Symlinking a path target. |         # Symlinking a path target. | ||||||
|  | @ -3167,8 +3182,9 @@ def test_touch_mode(self): | ||||||
|         st = os.stat(join('masked_new_file')) |         st = os.stat(join('masked_new_file')) | ||||||
|         self.assertEqual(stat.S_IMODE(st.st_mode), 0o750) |         self.assertEqual(stat.S_IMODE(st.st_mode), 0o750) | ||||||
| 
 | 
 | ||||||
|     @os_helper.skip_unless_symlink |  | ||||||
|     def test_resolve_loop(self): |     def test_resolve_loop(self): | ||||||
|  |         if not self.can_symlink: | ||||||
|  |             self.skipTest("symlinks required") | ||||||
|         # Loops with relative symlinks. |         # Loops with relative symlinks. | ||||||
|         os.symlink('linkX/inside', join('linkX')) |         os.symlink('linkX/inside', join('linkX')) | ||||||
|         self._check_symlink_loop(BASE, 'linkX') |         self._check_symlink_loop(BASE, 'linkX') | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Barney Gale
						Barney Gale