Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests on Windows and add more tests.
  • Loading branch information
serhiy-storchaka committed Jun 3, 2025
commit e142390e7e8789038940616dabbaef847679892d
29 changes: 16 additions & 13 deletions Lib/test/test_genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Tests common to genericpath, ntpath and posixpath
"""

import copy
import genericpath
import os
import pickle
import sys
import unittest
import warnings
Expand Down Expand Up @@ -320,19 +322,20 @@ def test_sameopenfile(self):
fd2 = fp2.fileno()
self.assertTrue(self.pathmodule.sameopenfile(fd1, fd2))

def test_all_but_last(self):
ALL_BUT_LAST = self.pathmodule.ALL_BUT_LAST
self.assertEqual(repr(ALL_BUT_LAST), 'os.path.ALL_BUT_LAST')
self.assertTrue(ALL_BUT_LAST)
import copy
self.assertIs(copy.copy(ALL_BUT_LAST), ALL_BUT_LAST)
self.assertIs(copy.deepcopy(ALL_BUT_LAST), ALL_BUT_LAST)
import pickle
for proto in range(pickle.HIGHEST_PROTOCOL+1):
with self.subTest(protocol=proto):
pickled = pickle.dumps(ALL_BUT_LAST, proto)
unpickled = pickle.loads(pickled)
self.assertIs(unpickled, ALL_BUT_LAST)
def test_realpath_mode_values(self):
for name in 'ALL_BUT_LAST', 'ALLOW_MISSING':
with self.subTest(name):
mode = getattr(self.pathmodule, name)
self.assertEqual(repr(mode), 'os.path.' + name)
self.assertEqual(str(mode), 'os.path.' + name)
self.assertTrue(mode)
self.assertIs(copy.copy(mode), mode)
self.assertIs(copy.deepcopy(mode), mode)
for proto in range(pickle.HIGHEST_PROTOCOL+1):
with self.subTest(protocol=proto):
pickled = pickle.dumps(mode, proto)
unpickled = pickle.loads(pickled)
self.assertIs(unpickled, mode)


class TestGenericTest(GenericTest, unittest.TestCase):
Expand Down
11 changes: 6 additions & 5 deletions Lib/test/test_ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def test_realpath_invalid_unicode_paths(self, kwargs):

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
@_parameterize({}, {'strict': True}, {'strict': ALL_BUT_LAST}, {'strict': ALLOW_MISSING})
def test_realpath_relative(self, kwargs):
ABSTFN = ntpath.abspath(os_helper.TESTFN)
open(ABSTFN, "wb").close()
Expand Down Expand Up @@ -893,7 +893,7 @@ def test_realpath_symlink_loops_raise(self):

@os_helper.skip_unless_symlink
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
@_parameterize({}, {'strict': True}, {'strict': ALL_BUT_LAST}, {'strict': ALLOW_MISSING})
def test_realpath_symlink_prefix(self, kwargs):
ABSTFN = ntpath.abspath(os_helper.TESTFN)
self.addCleanup(os_helper.unlink, ABSTFN + "3")
Expand Down Expand Up @@ -931,6 +931,7 @@ def test_realpath_nul(self):
tester("ntpath.realpath('NUL')", r'\\.\NUL')
tester("ntpath.realpath('NUL', strict=False)", r'\\.\NUL')
tester("ntpath.realpath('NUL', strict=True)", r'\\.\NUL')
tester("ntpath.realpath('NUL', strict=ALL_BUT_LAST)", r'\\.\NUL')
tester("ntpath.realpath('NUL', strict=ALLOW_MISSING)", r'\\.\NUL')

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

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

for kwargs in {}, {'strict': True}, {'strict': ALLOW_MISSING}:
for kwargs in {}, {'strict': True}, {'strict': ALL_BUT_LAST}, {'strict': ALLOW_MISSING}:
with self.subTest(**kwargs):
with os_helper.change_cwd(test_dir_long):
self.assertPathEqual(
Expand Down Expand Up @@ -1059,7 +1060,7 @@ def check(path, mode, expected, errno=None):
check("file/", ALL_BUT_LAST, "/file")
check("file/", True, "/file")
check("file/file2", False, "/file/file2")
check("file/file2", ALLOW_MISSING, FileNotFoundError)
check("file/file2", ALLOW_MISSING, "/file/file2")
check("file/file2", ALL_BUT_LAST, FileNotFoundError)
check("file/file2", True, FileNotFoundError)
check("file/.", False, "/file")
Expand Down Expand Up @@ -1093,7 +1094,7 @@ def check(path, mode, expected, errno=None):
check("link/", ALL_BUT_LAST, "/file")
check("link/", True, "/file")
check("link/file2", False, "/file/file2")
check("link/file2", ALLOW_MISSING, FileNotFoundError)
check("link/file2", ALLOW_MISSING, "/file/file2")
check("link/file2", ALL_BUT_LAST, FileNotFoundError)
check("link/file2", True, FileNotFoundError)
check("link/.", False, "/file")
Expand Down
Loading