@@ -2319,14 +2319,19 @@ class ClinicFunctionalTest(unittest.TestCase):
2319
2319
locals ().update ((name , getattr (ac_tester , name ))
2320
2320
for name in dir (ac_tester ) if name .startswith ('test_' ))
2321
2321
2322
- def check_depr_star (self , fn , * , regex , ok_args , fail_args ):
2323
- for args , kwds in ok_args :
2324
- fn (* args , ** kwds )
2325
- for args , kwds in fail_args :
2326
- with self .assertWarnsRegex (DeprecationWarning , re .escape (regex )) as cm :
2327
- fn (* args , ** kwds )
2322
+ def check_depr_star (self , * , fname , pnames , good_calls , bad_calls ):
2323
+ for call in good_calls :
2324
+ call ()
2325
+ regex = (
2326
+ f"Passing.*positional argument.*to { fname } .*is deprecated. "
2327
+ f"Parameter.*{ pnames } will become.*keyword-only parameter.*in "
2328
+ "Python 3.14"
2329
+ )
2330
+ for call in bad_calls :
2331
+ with self .assertWarnsRegex (DeprecationWarning , regex ) as cm :
2332
+ call ()
2328
2333
self .assertTrue (cm .filename .endswith ("test_clinic.py" ), cm .filename )
2329
- fn ( * args , ** kwds ) # No warning raised second time
2334
+ call ( ) # No warning raised second time
2330
2335
2331
2336
def test_objects_converter (self ):
2332
2337
with self .assertRaises (TypeError ):
@@ -2794,162 +2799,118 @@ def test_cloned_func_with_converter_exception_message(self):
2794
2799
2795
2800
def test_depr_star_pos0_len1 (self ):
2796
2801
fn = ac_tester .depr_star_pos0_len1
2797
- self .check_depr_star (fn ,
2798
- regex = (
2799
- "Passing positional arguments to depr_star_pos0_len1() "
2800
- "is deprecated. Parameter 'a' will become a keyword-only "
2801
- "parameter in Python 3.14"
2802
- ),
2803
- ok_args = (
2804
- ((), {"a" : None }),
2805
- ),
2806
- fail_args = (
2807
- ((None ,), {}),
2808
- )
2809
- )
2802
+ self .check_depr_star (
2803
+ fname = "depr_star_pos0_len1" , pnames = "'a'" ,
2804
+ good_calls = [
2805
+ lambda : fn (a = None ),
2806
+ ],
2807
+ bad_calls = [
2808
+ lambda : fn (None ),
2809
+ ])
2810
2810
2811
2811
def test_depr_star_pos0_len2 (self ):
2812
2812
fn = ac_tester .depr_star_pos0_len2
2813
- self .check_depr_star (fn ,
2814
- regex = (
2815
- "Passing positional arguments to depr_star_pos0_len2() "
2816
- "is deprecated. Parameters 'a' and 'b' will become "
2817
- "keyword-only parameters in Python 3.14"
2818
- ),
2819
- ok_args = (
2820
- ((), {"a" : None , "b" : None }),
2821
- ),
2822
- fail_args = (
2823
- ((None ,), {"b" : None }),
2824
- )
2825
- )
2813
+ self .check_depr_star (
2814
+ fname = "depr_star_pos0_len2" , pnames = "'a' and 'b'" ,
2815
+ good_calls = [
2816
+ lambda : fn (a = None , b = None ),
2817
+ ],
2818
+ bad_calls = [
2819
+ lambda : fn (None , b = None ),
2820
+ lambda : fn (None , None ),
2821
+ ])
2826
2822
2827
2823
def test_depr_star_pos0_len3_with_kwd (self ):
2828
2824
fn = ac_tester .depr_star_pos0_len3_with_kwd
2829
- self .check_depr_star (fn ,
2830
- regex = (
2831
- "Passing positional arguments to depr_star_pos0_len3_with_kwd() "
2832
- "is deprecated. Parameters 'a', 'b' and 'c' will become "
2833
- "keyword-only parameters in Python 3.14"
2834
- ),
2835
- ok_args = (
2836
- ((), {"a" : None , "b" : None , "c" : None , "d" : None }),
2837
- ),
2838
- fail_args = (
2839
- ((None ,), {"b" : None , "c" : None , "d" : None }),
2840
- ((None , None ), {"c" : None , "d" : None }),
2841
- ((None , None , None ), {"d" : None }),
2842
- )
2843
- )
2825
+ self .check_depr_star (
2826
+ fname = "depr_star_pos0_len3_with_kwd" , pnames = "'a', 'b' and 'c'" ,
2827
+ good_calls = [
2828
+ lambda : fn (a = None , b = None , c = None , d = None ),
2829
+ ],
2830
+ bad_calls = [
2831
+ lambda : fn (None , b = None , c = None , d = None ),
2832
+ lambda : fn (None , None , c = None , d = None ),
2833
+ lambda : fn (None , None , None , d = None ),
2834
+ ])
2844
2835
2845
2836
def test_depr_star_pos1_len1_opt (self ):
2846
2837
fn = ac_tester .depr_star_pos1_len1_opt
2847
- self .check_depr_star (fn ,
2848
- regex = (
2849
- "Passing 2 positional arguments to depr_star_pos1_len1_opt() "
2850
- "is deprecated. Parameter 'b' will become a keyword-only "
2851
- "parameter in Python 3.14"
2852
- ),
2853
- ok_args = (
2854
- ((), {"a" : None , "b" : None }),
2855
- ((None ,), {}),
2856
- ((None ,), {"b" : None }),
2857
- ),
2858
- fail_args = (
2859
- ((None , None ), {}),
2860
- )
2861
- )
2838
+ self .check_depr_star (
2839
+ fname = "depr_star_pos1_len1_opt" , pnames = "'b'" ,
2840
+ good_calls = [
2841
+ lambda : fn (a = None , b = None ),
2842
+ lambda : fn (None , b = None ),
2843
+ lambda : fn (a = None ),
2844
+ ],
2845
+ bad_calls = [
2846
+ lambda : fn (None , None ),
2847
+ ])
2862
2848
2863
2849
def test_depr_star_pos1_len1 (self ):
2864
2850
fn = ac_tester .depr_star_pos1_len1
2865
- self .check_depr_star (fn ,
2866
- regex = (
2867
- "Passing 2 positional arguments to depr_star_pos1_len1() is "
2868
- "deprecated. Parameter 'b' will become a keyword-only "
2869
- "parameter in Python 3.14"
2870
- ),
2871
- ok_args = (
2872
- ((), {"a" : None , "b" : None }),
2873
- ((None ,), {"b" : None }),
2874
- ),
2875
- fail_args = (
2876
- ((None , None ), {}),
2877
- )
2878
- )
2851
+ self .check_depr_star (
2852
+ fname = "depr_star_pos1_len1" , pnames = "'b'" ,
2853
+ good_calls = [
2854
+ lambda : fn (a = None , b = None ),
2855
+ lambda : fn (None , b = None ),
2856
+ ],
2857
+ bad_calls = [
2858
+ lambda : fn (None , None ),
2859
+ ])
2879
2860
2880
2861
def test_depr_star_pos1_len2_with_kwd (self ):
2881
2862
fn = ac_tester .depr_star_pos1_len2_with_kwd
2882
- self .check_depr_star (fn ,
2883
- regex = (
2884
- "Passing more than 1 positional argument to "
2885
- "depr_star_pos1_len2_with_kwd() is deprecated. Parameters 'b' "
2886
- "and 'c' will become keyword-only parameters in Python 3.14"
2887
- ),
2888
- ok_args = (
2889
- ((), {"a" : None , "b" : None , "c" : None , "d" : None }),
2890
- ((None ,), {"b" : None , "c" : None , "d" : None }),
2891
- ),
2892
- fail_args = (
2893
- ((None , None ), {"c" : None , "d" : None }),
2894
- ((None , None , None ), {"d" : None }),
2895
- )
2896
- )
2863
+ self .check_depr_star (
2864
+ fname = "depr_star_pos1_len2_with_kwd" , pnames = "'b' and 'c'" ,
2865
+ good_calls = [
2866
+ lambda : fn (a = None , b = None , c = None , d = None ),
2867
+ lambda : fn (None , b = None , c = None , d = None ),
2868
+ ],
2869
+ bad_calls = [
2870
+ lambda : fn (None , None , c = None , d = None ),
2871
+ lambda : fn (None , None , None , d = None ),
2872
+ ])
2897
2873
2898
2874
def test_depr_star_pos2_len1 (self ):
2899
2875
fn = ac_tester .depr_star_pos2_len1
2900
- self .check_depr_star (fn ,
2901
- regex = (
2902
- "Passing 3 positional arguments to depr_star_pos2_len1() is "
2903
- "deprecated. Parameter 'c' will become a keyword-only "
2904
- "parameter in Python 3.14"
2905
- ),
2906
- ok_args = (
2907
- ((), {"a" : None , "b" : None , "c" : None }),
2908
- ((None ,), {"b" : None , "c" : None }),
2909
- ((None , None ), {"c" : None }),
2910
- ),
2911
- fail_args = (
2912
- ((None , None , None ), {}),
2913
- )
2914
- )
2876
+ self .check_depr_star (
2877
+ fname = "depr_star_pos2_len1" , pnames = "'c'" ,
2878
+ good_calls = [
2879
+ lambda : fn (a = None , b = None , c = None ),
2880
+ lambda : fn (None , b = None , c = None ),
2881
+ lambda : fn (None , None , c = None ),
2882
+ ],
2883
+ bad_calls = [
2884
+ lambda : fn (None , None , None ),
2885
+ ])
2915
2886
2916
2887
def test_depr_star_pos2_len2 (self ):
2917
2888
fn = ac_tester .depr_star_pos2_len2
2918
- self .check_depr_star (fn ,
2919
- regex = (
2920
- "Passing more than 2 positional arguments to "
2921
- "depr_star_pos2_len2() is deprecated. Parameters 'c' and 'd' "
2922
57AE
- "will become keyword-only parameters in Python 3.14"
2923
- ),
2924
- ok_args = (
2925
- ((), {"a" : None , "b" : None , "c" : None , "d" : None }),
2926
- ((None ,), {"b" : None , "c" : None , "d" : None }),
2927
- ((None , None ), {"c" : None , "d" : None }),
2928
- ),
2929
- fail_args = (
2930
- ((None , None , None ), {"d" : None }),
2931
- ((None , None , None , None ), {}),
2932
- )
2933
- )
2889
+ self .check_depr_star (
2890
+ fname = "depr_star_pos2_len2" , pnames = "'c' and 'd'" ,
2891
+ good_calls = [
2892
+ lambda : fn (a = None , b = None , c = None , d = None ),
2893
+ lambda : fn (None , b = None , c = None , d = None ),
2894
+ lambda : fn (None , None , c = None , d = None ),
2895
+ ],
2896
+ bad_calls = [
2897
+ lambda : fn (None , None , None , d = None ),
2898
+ lambda : fn (None , None , None , None ),
2899
+ ])
2934
2900
2935
2901
def test_depr_star_pos2_len2_with_kwd (self ):
2936
2902
fn = ac_tester .depr_star_pos2_len2_with_kwd
2937
- self .check_depr_star (fn ,
2938
- regex = (
2939
- "Passing more than 2 positional arguments to "
2940
- "depr_star_pos2_len2_with_kwd() is deprecated. Parameters 'c' "
2941
- "and 'd' will become keyword-only parameters in Python 3.14"
2942
- ),
2943
- ok_args = (
2944
- ((), {"a" : None , "b" : None , "c" : None , "d" : None , "e" : None }),
2945
- ((None ,), {"b" : None , "c" : None , "d" : None , "e" : None }),
2946
- ((None , None ), {"c" : None , "d" : None , "e" : None }),
2947
- ),
2948
- fail_args = (
2949
- ((None , None , None ), {"d" : None , "e" : None }),
2950
- ((None , None , None , None ), {"e" : None }),
2951
- )
2952
- )
2903
+ self .check_depr_star (
2904
+ fname = "depr_star_pos2_len2" , pnames = "'c' and 'd'" ,
2905
+ good_calls = [
2906
+ lambda : fn (a = None , b = None , c = None , d = None , e = None ),
2907
+ lambda : fn (None , b = None , c = None , d = None , e = None ),
2908
+ lambda : fn (None , None , c = None , d = None , e = None ),
2909
+ ],
2910
+ bad_calls = [
2911
+ lambda : fn (None , None , None , d = None , e = None ),
2912
+ lambda : fn (None , None , None , None , e = None ),
2913
+ ])
2953
2914
2954
2915
2955
2916
class PermutationTests (unittest .TestCase ):
0 commit comments