8000 Address review comments. · python/cpython@8b3ede1 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 8b3ede1

Browse files
Address review comments.
1 parent fe168e6 commit 8b3ede1

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

Lib/test/support/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,16 +948,20 @@ def check_sizeof(test, o, size):
948948
def subTests(arg_names, arg_values, /, *, _do_cleanups=False):
949949
"""Run multiple subtests with different parameters.
950950
"""
951+
single_param = False
951952
if isinstance(arg_names, str):
952-
arg_names = arg_names.split(',')
953+
arg_names = arg_names.replace(',',' ').split()
954+
if len(arg_names) == 1:
955+
single_param = True
956+
arg_values = tuple(arg_values)
953957
def decorator(func):
954958
if isinstance(func, type):
955959
raise TypeError('subTests() can only decorate methods, not classes')
956960
@functools.wraps(func)
957961
def wrapper(self, /, *args, **kwargs):
958962
for values in arg_values:
959-
if len(arg_names) == 1:
960-
values = values,
963+
if single_param:
964+
values = (values,)
961965
subtest_kwargs = dict(zip(arg_names, values))
962966
with self.subTest(**subtest_kwargs):
963967
func(self, *args, **kwargs, **subtest_kwargs)

Lib/test/test_ntpath.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def tester(fn, wantResult):
7878
%(str(fn), str(wantResult), repr(gotResult)))
7979

8080

81+
def _parameterize(*parameters):
82+
return support.subTests('kwargs', parameters, _do_cleanups=True)
83+
84+
8185
class NtpathTestCase(unittest.TestCase):
8286
def assertPathEqual(self, path1, path2):
8387
if path1 == path2 or _norm(path1) == _norm(path2):
@@ -536,7 +540,7 @@ def test_realpath_pardir_missing_ok(self):
536540

537541
@os_helper.skip_unless_symlink
538542
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
539-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}), _do_cleanups=True)
543+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
540544
def test_realpath_basic(self, kwargs):
541545
ABSTFN = ntpath.abspath(os_helper.TESTFN)
542546
open(ABSTFN, "wb").close()
@@ -615,7 +619,7 @@ def test_realpath_invalid_paths(self):
615619
self.assertEqual(realpath(path, strict=ALLOW_MISSING), ABSTFNb + b'\\nonexistent')
616620

617621
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
618-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
622+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
619623
def test_realpath_invalid_unicode_paths(self, kwargs):
620624
realpath = ntpath.realpath
621625
ABSTFN = ntpath.abspath(os_helper.TESTFN)
@@ -635,7 +639,7 @@ def test_realpath_invalid_unicode_paths(self, kwargs):
635639

636640
@os_helper.skip_unless_symlink
637641
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
638-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}), _do_cleanups=True)
642+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
639643
def test_realpath_relative(self, kwargs):
640644
ABSTFN = ntpath.abspath(os_helper.TESTFN)
641645
open(ABSTFN, "wb").close()
@@ -849,7 +853,7 @@ def test_realpath_symlink_loops_raise(self):
849853

850854
@os_helper.skip_unless_symlink
851855
@unittest.skipUnless(HAVE_GETFINALPATHNAME, 'need _getfinalpathname')
852-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}), _do_cleanups=True)
856+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
853857
def test_realpath_symlink_prefix(self, kwargs):
854858
ABSTFN = ntpath.abspath(os_helper.TESTFN)
855859
self.addCleanup(os_helper.unlink, ABSTFN + "3")

Lib/test/test_posixpath.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def skip_if_ABSTFN_contains_backslash(test):
3535
return [test, unittest.skip(msg)(test)][found_backslash]
3636

3737

38+
def _parameterize(*parameters):
39+
return support.subTests('kwargs', parameters)
40+
41+
3842
class PosixPathTest(unittest.TestCase):
3943

4044
def setUp(self):
@@ -444,7 +448,7 @@ def test_normpath(self):
444448
self.assertEqual(result, expected)
445449

446450
@skip_if_ABSTFN_contains_backslash
447-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
451+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
448452
def test_realpath_curdir(self, kwargs):
449453
self.assertEqual(realpath('.', **kwargs), os.getcwd())
450454
self.assertEqual(realpath('./.', **kwargs), os.getcwd())
@@ -455,7 +459,7 @@ def test_realpath_curdir(self, kwargs):
455459
self.assertEqual(realpath(b'/'.join([b'.'] * 100), **kwargs), os.getcwdb())
456460

457461
@skip_if_ABSTFN_contains_backslash
458-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
462+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
459463
def test_realpath_pardir(self, kwargs):
460464
self.assertEqual(realpath('..', **kwargs), dirname(os.getcwd()))
461465
self.assertEqual(realpath('../..', **kwargs), dirname(dirname(os.getcwd())))
@@ -467,7 +471,7 @@ def test_realpath_pardir(self, kwargs):
467471

468472
@os_helper.skip_unless_symlink
469473
@skip_if_ABSTFN_contains_backslash
470-
@support.subTests('kwargs', ({}, {'strict': ALLOW_MISSING}))
474+
@_parameterize({}, {'strict': ALLOW_MISSING})
471475
def test_realpath_basic(self, kwargs):
472476
# Basic operation.
473477
try:
@@ -585,7 +589,7 @@ def test_realpath_invalid_paths(self):
585589

586590
@os_helper.skip_unless_symlink
587591
@skip_if_ABSTFN_contains_backslash
588-
@support.subTests('kwargs', ({}, {'strict': ALLOW_MISSING}))
592+
@_parameterize({}, {'strict': ALLOW_MISSING})
589593
def test_realpath_relative(self, kwargs):
590594
try:
591595
os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN)
@@ -595,7 +599,7 @@ def test_realpath_relative(self, kwargs):
595599

596600
@os_helper.skip_unless_symlink
597601
@skip_if_ABSTFN_contains_backslash
598-
@support.subTests('kwargs', ({}, {'strict': ALLOW_MISSING}))
602+
@_parameterize({}, {'strict': ALLOW_MISSING})
599603
def test_realpath_missing_pardir(self, kwargs):
600604
try:
601605
os.symlink(TESTFN + "1", TESTFN)
@@ -647,7 +651,7 @@ def test_realpath_symlink_loops(self):
647651

648652
@os_helper.skip_unless_symlink
649653
@skip_if_ABSTFN_contains_backslash
650-
@support.subTests('kwargs', ({'strict': True}, {'strict': ALLOW_MISSING}))
654+
@_parameterize({'strict': True}, {'strict': ALLOW_MISSING})
651655
def test_realpath_symlink_loops_strict(self, kwargs):
652656
# Bug #43757, raise OSError if we get into an infinite symlink loop in
653657
# the strict modes.
@@ -689,7 +693,7 @@ def test_realpath_symlink_loops_strict(self, kwargs):
689693

690694
@os_helper.skip_unless_symlink
691695
@skip_if_ABSTFN_contains_backslash
692-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
696+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
693697
def test_realpath_repeated_indirect_symlinks(self, kwargs):
694698
# Issue #6975.
695699
try:
@@ -704,7 +708,7 @@ def test_realpath_repeated_indirect_symlinks(self, kwargs):
704708

705709
@os_helper.skip_unless_symlink
706710
@skip_if_ABSTFN_contains_backslash
707-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
711+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
708712
def test_realpath_deep_recursion(self, kwargs):
709713
depth = 10
710714
try:
@@ -724,7 +728,7 @@ def test_realpath_deep_recursion(self, kwargs):
724728

725729
@os_helper.skip_unless_symlink
726730
@skip_if_ABSTFN_contains_backslash
727-
@support.subTests('kwargs', ({}, {'strict': ALLOW_MISSING}))
731+
@_parameterize({}, {'strict': ALLOW_MISSING})
728732
def test_realpath_resolve_parents(self, kwargs):
729733
# We also need to resolve any symlinks in the parents of a relative
730734
# path passed to realpath. E.g.: current working directory is
@@ -745,7 +749,7 @@ def test_realpath_resolve_parents(self, kwargs):
745749

746750
@os_helper.skip_unless_symlink
747751
@skip_if_ABSTFN_contains_backslash
748-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
752+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
749753
def test_realpath_resolve_before_normalizing(self, kwargs):
750754
# Bug #990669: Symbolic links should be resolved before we
751755
# normalize the path. E.g.: if we have directories 'a', 'k' and 'y'
@@ -774,7 +778,7 @@ def test_realpath_resolve_before_normalizing(self, kwargs):
774778

775779
@os_helper.skip_unless_symlink
776780
@skip_if_ABSTFN_contains_backslash
777-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
781+
@_parameterize({}, {'strict': True}, {'strict': ALLOW_MISSING})
778782
def test_realpath_resolve_first(self, kwargs):
779783
# Bug #1213894: The first component of the path, if not absolute,
780784
# must be resolved too.
@@ -812,7 +816,7 @@ def test_realpath_unreadable_symlink(self):
812816
@skip_if_ABSTFN_contains_backslash
813817
@unittest.skipIf(os.chmod not in os.supports_follow_symlinks, "Can't set symlink permissions")
814818
@unittest.skipIf(sys.platform != "darwin", "only macOS requires read permission to readlink()")
815-
@support.subTests('kwargs', ({'strict': True}, {'strict': ALLOW_MISSING}))
819+
@_parameterize({'strict': True}, {'strict': ALLOW_MISSING})
816820
def test_realpath_unreadable_symlink_strict(self, kwargs):
817821
try:
818822
os.symlink(ABSTFN+"1", ABSTFN)
@@ -1148,7 +1152,7 @@ def test_path_normpath(self):
11481152
def test_path_abspath(self):
11491153
self.assertPathEqual(self.path.abspath)
11501154

1151-
@support.subTests('kwargs', ({}, {'strict': True}, {'strict': ALLOW_MISSING}))
1155+
@_parameterize({}, {'strict': 47BB True}, {'strict': ALLOW_MISSING})
11521156
def test_path_realpath(self, kwargs):
11531157
self.assertPathEqual(self.path.realpath)
11541158

0 commit comments

Comments
 (0)
0