Skip to content

Commit e142390

Browse files
Fix tests on Windows and add more tests.
1 parent c03cf4b commit e142390

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Lib/test/test_genericpath.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
Tests common to genericpath, ntpath and posixpath
33
"""
44

5+
import copy
56
import genericpath
67
import os
8+
import pickle
79
import sys
810
import unittest
911
import warnings
@@ -320,19 +322,20 @@ def test_sameopenfile(self):
320322
fd2 = fp2.fileno()
321323
self.assertTrue(self.pathmodule.sameopenfile(fd1, fd2))
322324

323-
def test_all_but_last(self):
324-
ALL_BUT_LAST = self.pathmodule.ALL_BUT_LAST
325-
self.assertEqual(repr(ALL_BUT_LAST), 'os.path.ALL_BUT_LAST')
326-
self.assertTrue(ALL_BUT_LAST)
327-
import copy
328-
self.assertIs(copy.copy(ALL_BUT_LAST), ALL_BUT_LAST)
329-
self.assertIs(copy.deepcopy(ALL_BUT_LAST), ALL_BUT_LAST)
330-
import pickle
331-
for proto in range(pickle.HIGHEST_PROTOCOL+1):
332-
with self.subTest(protocol=proto):
333-
pickled = pickle.dumps(ALL_BUT_LAST, proto)
334-
unpickled = pickle.loads(pickled)
335-
self.assertIs(unpickled, ALL_BUT_LAST)
325+
def test_realpath_mode_values(self):
326+
for name in 'ALL_BUT_LAST', 'ALLOW_MISSING':
327+
with self.subTest(name):
328+
mode = getattr(self.pathmodule, name)
329+
self.assertEqual(repr(mode), 'os.path.' + name)
330+
self.assertEqual(str(mode), 'os.path.' + name)
331+
self.assertTrue(mode)
332+
self.assertIs(copy.copy(mode), mode)
333+
self.assertIs(copy.deepcopy(mode), mode)
334+
for proto in range(pickle.HIGHEST_PROTOCOL+1):
335+
with self.subTest(protocol=proto):
336+
pickled = pickle.dumps(mode, proto)
337+
unpickled = pickle.loads(pickled)
338+
self.assertIs(unpickled, mode)
336339

337340

338341
class TestGenericTest(GenericTest, unittest.TestCase):

Lib/test/test_ntpath.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def test_realpath_invalid_unicode_paths(self, kwargs):
660660

661661
@os_helper.skip_unless_symlink
662662
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
663-
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
663+
@_parameterize({}, {'strict': True}, {'strict': ALL_BUT_LAST}, {'strict': ALLOW_MISSING})
664664
def test_realpath_relative(self, kwargs):
665665
ABSTFN = ntpath.abspath(os_helper.TESTFN)
666666
open(ABSTFN, "wb").close()
@@ -893,7 +893,7 @@ def test_realpath_symlink_loops_raise(self):
893893

894894
@os_helper.skip_unless_symlink
895895
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
896-
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
896+
@_parameterize({}, {'strict': True}, {'strict': ALL_BUT_LAST}, {'strict': ALLOW_MISSING})
897897
def test_realpath_symlink_prefix(self, kwargs):
898898
ABSTFN = ntpath.abspath(os_helper.TESTFN)
899899
self.addCleanup(os_helper.unlink, ABSTFN + "3")
@@ -931,6 +931,7 @@ def test_realpath_nul(self):
931931
tester("ntpath.realpath('NUL')", r'\\.\NUL')
932932
tester("ntpath.realpath('NUL', strict=False)", r'\\.\NUL')
933933
tester("ntpath.realpath('NUL', strict=True)", r'\\.\NUL')
934+
tester("ntpath.realpath('NUL', strict=ALL_BUT_LAST)", r'\\.\NUL')
934935
tester("ntpath.realpath('NUL', strict=ALLOW_MISSING)", r'\\.\NUL')
935936

936937
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
@@ -955,7 +956,7 @@ def test_realpath_cwd(self):
955956

956957
self.assertPathEqual(test_file_long, ntpath.realpath(test_file_short))
957958

958-
for kwargs in {}, {'strict': True}, {'strict': ALLOW_MISSING}:
959+
for kwargs in {}, {'strict': True}, {'strict': ALL_BUT_LAST}, {'strict': ALLOW_MISSING}:
959960
with self.subTest(**kwargs):
960961
with os_helper.change_cwd(test_dir_long):
961962
self.assertPathEqual(
@@ -1059,7 +1060,7 @@ def check(path, mode, expected, errno=None):
10591060
check("file/", ALL_BUT_LAST, "/file")
10601061
check("file/", True, "/file")
10611062
check("file/file2", False, "/file/file2")
1062-
check("file/file2", ALLOW_MISSING, FileNotFoundError)
1063+
check("file/file2", ALLOW_MISSING, "/file/file2")
10631064
check("file/file2", ALL_BUT_LAST, FileNotFoundError)
10641065
check("file/file2", True, FileNotFoundError)
10651066
check("file/.", False, "/file")
@@ -1093,7 +1094,7 @@ def check(path, mode, expected, errno=None):
10931094
check("link/", ALL_BUT_LAST, "/file")
10941095
check("link/", True, "/file")
10951096
check("link/file2", False, "/file/file2")
1096-
check("link/file2", ALLOW_MISSING, FileNotFoundError)
1097+
check("link/file2", ALLOW_MISSING, "/file/file2")
10971098
check("link/file2", ALL_BUT_LAST, FileNotFoundError)
10981099
check("link/file2", True, FileNotFoundError)
10991100
check("link/.", False, "/file")

0 commit comments

Comments
 (0)