diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-28 03:21:28 (GMT) |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-28 03:21:28 (GMT) |
commit | 3a09286790c58522195eadc3eaa4a21e8da89ea1 (patch) | |
tree | 493319a3666f3ed24f52759ab425e31da6b832f8 /Lib/test/test_os.py | |
parent | db4e5c53c9a68cbb19a8daca0c454360d1045c6f (diff) | |
download | cpython-3a09286790c58522195eadc3eaa4a21e8da89ea1.zip cpython-3a09286790c58522195eadc3eaa4a21e8da89ea1.tar.gz cpython-3a09286790c58522195eadc3eaa4a21e8da89ea1.tar.bz2 |
Issue #13772: Restored directory detection of targets in `os.symlink` on Windows, which was temporarily removed in Python 3.2.3 due to an incomplete implementation. The implementation now works even if the symlink is created in a location other than the current directory.
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r-- | Lib/test/test_os.py | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 33b9e5b..9d65277 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -686,13 +686,8 @@ class WalkTests(unittest.TestCase): f.write("I'm " + path + " and proud of it. Blame test_os.\n") f.close() if support.can_symlink(): - if os.name == 'nt': - def symlink_to_dir(src, dest): - os.symlink(src, dest, True) - else: - symlink_to_dir = os.symlink - symlink_to_dir(os.path.abspath(t2_path), link_path) - symlink_to_dir('broken', broken_link_path) + os.symlink(os.path.abspath(t2_path), link_path) + symlink_to_dir('broken', broken_link_path, True) sub2_tree = (sub2_path, ["link"], ["broken_link", "tmp3"]) else: sub2_tree = (sub2_path, [], ["tmp3"]) @@ -1516,7 +1511,7 @@ class Win32SymlinkTests(unittest.TestCase): os.remove(self.missing_link) def test_directory_link(self): - os.symlink(self.dirlink_target, self.dirlink, True) + os.symlink(self.dirlink_target, self.dirlink) self.assertTrue(os.path.exists(self.dirlink)) self.assertTrue(os.path.isdir(self.dirlink)) self.assertTrue(os.path.islink(self.dirlink)) @@ -1610,6 +1605,38 @@ class Win32SymlinkTests(unittest.TestCase): shutil.rmtree(level1) +@support.skip_unless_symlink +class NonLocalSymlinkTests(unittest.TestCase): + + def setUp(self): + """ + Create this structure: + + base + \___ some_dir + """ + os.makedirs('base/some_dir') + + def tearDown(self): + shutil.rmtree('base') + + def test_directory_link_nonlocal(self): + """ + The symlink target should resolve relative to the link, not relative + to the current directory. + + Then, link base/some_link -> base/some_dir and ensure that some_link + is resolved as a directory. + + In issue13772, it was discovered that directory detection failed if + the symlink target was not specified relative to the current + directory, which was a defect in the implementation. + """ + src = os.path.join('base', 'some_link') + os.symlink('some_dir', src) + assert os.path.isdir(src) + + class FSEncodingTests(unittest.TestCase): def test_nop(self): self.assertEqual(os.fsencode(b'abc\xff'), b'abc\xff') @@ -2137,6 +2164,7 @@ def test_main(): Pep383Tests, Win32KillTests, Win32SymlinkTests, + NonLocalSymlinkTests, FSEncodingTests, DeviceEncodingTests, PidTests, |