summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_clinic.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_clinic.py')
-rw-r--r--Lib/test/test_clinic.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index 3921523..a649b5f 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -2,6 +2,7 @@
# Copyright 2012-2013 by Larry Hastings.
# Licensed to the PSF under a contributor agreement.
+from functools import partial
from test import support, test_tools
from test.support import os_helper
from test.support.os_helper import TESTFN, unlink
@@ -2431,6 +2432,19 @@ class ClinicFunctionalTest(unittest.TestCase):
locals().update((name, getattr(ac_tester, name))
for name in dir(ac_tester) if name.startswith('test_'))
+ def check_depr_star(self, pnames, fn, *args, **kwds):
+ regex = (
+ fr"Passing( more than)?( [0-9]+)? positional argument(s)? to "
+ fr"{fn.__name__}\(\) is deprecated. Parameter(s)? {pnames} will "
+ fr"become( a)? keyword-only parameter(s)? in Python 3\.14"
+ )
+ with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
+ # Record the line number, so we're sure we've got the correct stack
+ # level on the deprecation warning.
+ _, lineno = fn(*args, **kwds), sys._getframe().f_lineno
+ self.assertEqual(cm.filename, __file__)
+ self.assertEqual(cm.lineno, lineno)
+
def test_objects_converter(self):
with self.assertRaises(TypeError):
ac_tester.objects_converter()
@@ -2895,6 +2909,95 @@ class ClinicFunctionalTest(unittest.TestCase):
func = getattr(ac_tester, name)
self.assertEqual(func(), name)
+ def test_depr_star_new(self):
+ regex = re.escape(
+ "Passing positional arguments to _testclinic.DeprStarNew() is "
+ "deprecated. Parameter 'a' will become a keyword-only parameter "
+ "in Python 3.14."
+ )
+ with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
+ ac_tester.DeprStarNew(None)
+ self.assertEqual(cm.filename, __file__)
+
+ def test_depr_star_init(self):
+ regex = re.escape(
+ "Passing positional arguments to _testclinic.DeprStarInit() is "
+ "deprecated. Parameter 'a' will become a keyword-only parameter "
+ "in Python 3.14."
+ )
+ with self.assertWarnsRegex(DeprecationWarning, regex) as cm:
+ ac_tester.DeprStarInit(None)
+ self.assertEqual(cm.filename, __file__)
+
+ def test_depr_star_pos0_len1(self):
+ fn = ac_tester.depr_star_pos0_len1
+ fn(a=None)
+ self.check_depr_star("'a'", fn, "a")
+
+ def test_depr_star_pos0_len2(self):
+ fn = ac_tester.depr_star_pos0_len2
+ fn(a=0, b=0)
+ check = partial(self.check_depr_star, "'a' and 'b'", fn)
+ check("a", b=0)
+ check("a", "b")
+
+ def test_depr_star_pos0_len3_with_kwd(self):
+ fn = ac_tester.depr_star_pos0_len3_with_kwd
+ fn(a=0, b=0, c=0, d=0)
+ check = partial(self.check_depr_star, "'a', 'b' and 'c'", fn)
+ check("a", b=0, c=0, d=0)
+ check("a", "b", c=0, d=0)
+ check("a", "b", "c", d=0)
+
+ def test_depr_star_pos1_len1_opt(self):
+ fn = ac_tester.depr_star_pos1_len1_opt
+ fn(a=0, b=0)
+ fn("a", b=0)
+ fn(a=0) # b is optional
+ check = partial(self.check_depr_star, "'b'", fn)
+ check("a", "b")
+
+ def test_depr_star_pos1_len1(self):
+ fn = ac_tester.depr_star_pos1_len1
+ fn(a=0, b=0)
+ fn("a", b=0)
+ check = partial(self.check_depr_star, "'b'", fn)
+ check("a", "b")
+
+ def test_depr_star_pos1_len2_with_kwd(self):
+ fn = ac_tester.depr_star_pos1_len2_with_kwd
+ fn(a=0, b=0, c=0, d=0),
+ fn("a", b=0, c=0, d=0),
+ check = partial(self.check_depr_star, "'b' and 'c'", fn)
+ check("a", "b", c=0, d=0),
+ check("a", "b", "c", d=0),
+
+ def test_depr_star_pos2_len1(self):
+ fn = ac_tester.depr_star_pos2_len1
+ fn(a=0, b=0, c=0)
+ fn("a", b=0, c=0)
+ fn("a", "b", c=0)
+ check = partial(self.check_depr_star, "'c'", fn)
+ check("a", "b", "c")
+
+ def test_depr_star_pos2_len2(self):
+ fn = ac_tester.depr_star_pos2_len2
+ fn(a=0, b=0, c=0, d=0)
+ fn("a", b=0, c=0, d=0)
+ fn("a", "b", c=0, d=0)
+ check = partial(self.check_depr_star, "'c' and 'd'", fn)
+ check("a", "b", "c", d=0)
+ check("a", "b", "c", "d")
+
+ def test_depr_star_pos2_len2_with_kwd(self):
+ fn = ac_tester.depr_star_pos2_len2_with_kwd
+ fn(a=0, b=0, c=0, d=0, e=0)
+ fn("a", b=0, c=0, d=0, e=0)
+ fn("a", "b", c=0, d=0, e=0)
+ check = partial(self.check_depr_star, "'c' and 'd'", fn)
+ check("a", "b", "c", d=0, e=0)
+ check("a", "b", "c", "d", e=0)
+
class PermutationTests(unittest.TestCase):
"""Test permutation support functions."""