summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2018-08-15 10:03:41 (GMT)
committerGitHub <noreply@github.com>2018-08-15 10:03:41 (GMT)
commite0b5b2096ead4cc094a129ce7602ac5c0e998086 (patch)
treeb001fbdec6156b8316a4b5e518ee5acf57b55c75 /Lib
parent7c4ab2afb17b99eb3f61f9c73cbd548b5e0ad2c0 (diff)
downloadcpython-e0b5b2096ead4cc094a129ce7602ac5c0e998086.zip
cpython-e0b5b2096ead4cc094a129ce7602ac5c0e998086.tar.gz
cpython-e0b5b2096ead4cc094a129ce7602ac5c0e998086.tar.bz2
bpo-34384: Fix os.readlink() on Windows (GH-8740)
os.readlink() now accepts path-like and bytes objects on Windows. Previously, support for path-like and bytes objects was only implemented on Unix. This commit also merges Unix and Windows implementations of os.readlink() in one function and adds basic unit tests to increase test coverage of the function.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index a140ae0..6658a61 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2039,6 +2039,53 @@ class Win32ListdirTests(unittest.TestCase):
[os.fsencode(path) for path in self.created_paths])
+@unittest.skipUnless(hasattr(os, 'readlink'), 'needs os.readlink()')
+class ReadlinkTests(unittest.TestCase):
+ filelink = 'readlinktest'
+ filelink_target = os.path.abspath(__file__)
+ filelinkb = os.fsencode(filelink)
+ filelinkb_target = os.fsencode(filelink_target)
+
+ def setUp(self):
+ self.assertTrue(os.path.exists(self.filelink_target))
+ self.assertTrue(os.path.exists(self.filelinkb_target))
+ self.assertFalse(os.path.exists(self.filelink))
+ self.assertFalse(os.path.exists(self.filelinkb))
+
+ def test_not_symlink(self):
+ filelink_target = FakePath(self.filelink_target)
+ self.assertRaises(OSError, os.readlink, self.filelink_target)
+ self.assertRaises(OSError, os.readlink, filelink_target)
+
+ def test_missing_link(self):
+ self.assertRaises(FileNotFoundError, os.readlink, 'missing-link')
+ self.assertRaises(FileNotFoundError, os.readlink,
+ FakePath('missing-link'))
+
+ @support.skip_unless_symlink
+ def test_pathlike(self):
+ os.symlink(self.filelink_target, self.filelink)
+ self.addCleanup(support.unlink, self.filelink)
+ filelink = FakePath(self.filelink)
+ self.assertEqual(os.readlink(filelink), self.filelink_target)
+
+ @support.skip_unless_symlink
+ def test_pathlike_bytes(self):
+ os.symlink(self.filelinkb_target, self.filelinkb)
+ self.addCleanup(support.unlink, self.filelinkb)
+ path = os.readlink(FakePath(self.filelinkb))
+ self.assertEqual(path, self.filelinkb_target)
+ self.assertIsInstance(path, bytes)
+
+ @support.skip_unless_symlink
+ def test_bytes(self):
+ os.symlink(self.filelinkb_target, self.filelinkb)
+ self.addCleanup(support.unlink, self.filelinkb)
+ path = os.readlink(self.filelinkb)
+ self.assertEqual(path, self.filelinkb_target)
+ self.assertIsInstance(path, bytes)
+
+
@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
@support.skip_unless_symlink
class Win32SymlinkTests(unittest.TestCase):