diff options
author | Tim Golden <mail@timgolden.me.uk> | 2013-10-25 19:24:06 (GMT) |
---|---|---|
committer | Tim Golden <mail@timgolden.me.uk> | 2013-10-25 19:24:06 (GMT) |
commit | 781bbebacb9d26d216abaa8b66a7ce790f91dd98 (patch) | |
tree | ffb0381334bfca971d87d48b9d3af512372880b1 /Lib/test | |
parent | 502834cf3c6add73507b709b2f65d5118ec3a735 (diff) | |
download | cpython-781bbebacb9d26d216abaa8b66a7ce790f91dd98.zip cpython-781bbebacb9d26d216abaa8b66a7ce790f91dd98.tar.gz cpython-781bbebacb9d26d216abaa8b66a7ce790f91dd98.tar.bz2 |
Issue13234 Allow listdir to handle extended paths on Windows (Patch by Santoso Wijaya)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_os.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index f1d652c..1c5fe81 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1559,6 +1559,52 @@ class Win32KillTests(unittest.TestCase): @unittest.skipUnless(sys.platform == "win32", "Win32 specific tests") +class Win32ListdirTests(unittest.TestCase): + """Test listdir on Windows.""" + + def setUp(self): + self.created_paths = [] + for i in range(2): + dir_name = 'SUB%d' % i + dir_path = os.path.join(support.TESTFN, dir_name) + file_name = 'FILE%d' % i + file_path = os.path.join(support.TESTFN, file_name) + os.makedirs(dir_path) + with open(file_path, 'w') as f: + f.write("I'm %s and proud of it. Blame test_os.\n" % file_path) + self.created_paths.extend([dir_name, file_name]) + self.created_paths.sort() + + def tearDown(self): + shutil.rmtree(support.TESTFN) + + def test_listdir_no_extended_path(self): + """Test when the path is not an "extended" path.""" + # unicode + self.assertEqual( + sorted(os.listdir(support.TESTFN)), + self.created_paths) + # bytes + self.assertEqual( + sorted(os.listdir(os.fsencode(support.TESTFN))), + [os.fsencode(path) for path in self.created_paths]) + + def test_listdir_extended_path(self): + """Test when the path starts with '\\\\?\\'.""" + # See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath + # unicode + path = '\\\\?\\' + os.path.abspath(support.TESTFN) + self.assertEqual( + sorted(os.listdir(path)), + self.created_paths) + # bytes + path = b'\\\\?\\' + os.fsencode(os.path.abspath(support.TESTFN)) + self.assertEqual( + sorted(os.listdir(path)), + [os.fsencode(path) for path in self.created_paths]) + + +@unittest.skipUnless(sys.platform == "win32", "Win32 specific tests") @support.skip_unless_symlink class Win32SymlinkTests(unittest.TestCase): filelink = 'filelinktest' @@ -2427,6 +2473,7 @@ def test_main(): PosixUidGidTests, Pep383Tests, Win32KillTests, + Win32ListdirTests, Win32SymlinkTests, NonLocalSymlinkTests, FSEncodingTests, |