2
2
3
3
import unittest
4
4
import warnings
5
+ from typing import Optional
5
6
6
7
import pytest
7
8
20
21
class RenameKwargsTest (unittest .TestCase ):
21
22
expected_kwargs = dict (a = 1 , b = 2 , c = 3 , d = 4 )
22
23
23
- def _test (self , start : str , end : str , kwargs , aliases ):
24
+ def _test (
25
+ self , start : str , end : Optional [str ], note : Optional [str ], kwargs , aliases
26
+ ):
24
27
# Test that we do get the DeprecationWarning when called with deprecated kwargs
25
28
with self .assertWarnsRegex (
26
29
DeprecationWarning , "is deprecated.*?" + start + ".*?" + end
27
30
):
28
- _rename_kwargs ("unit_test" , start , end , kwargs , aliases )
31
+ _rename_kwargs ("unit_test" , start , end , note , kwargs , aliases )
29
32
30
33
# Test that the aliases contains the deprecated values and
31
34
# the obsolete kwargs have been removed
@@ -37,30 +40,30 @@ def _test(self, start: str, end: str, kwargs, aliases):
37
40
# Cause all warnings to always be triggered.
38
41
warnings .simplefilter ("error" , DeprecationWarning )
39
42
try :
40
- _rename_kwargs ("unit_test" , start , end , kwargs , aliases )
43
+ _rename_kwargs ("unit_test" , start , end , note , kwargs , aliases )
41
44
finally :
42
45
warnings .resetwarnings ()
43
46
44
47
def test_rename (self ):
45
48
kwargs = dict (old_a = 1 , old_b = 2 , c = 3 , d = 4 )
46
49
aliases = {"old_a" : "a" , "old_b" : "b" }
47
- self ._test ("1.0" , "2.0" , kwargs , aliases )
50
+ self ._test ("1.0" , "2.0" , None , kwargs , aliases )
48
51
49
52
def test_obsolete (self ):
50
53
kwargs = dict (a = 1 , b = 2 , c = 3 , d = 4 , z = 10 )
51
54
aliases = {"z" : None }
52
- self ._test ("1.0" , "2.0" , kwargs , aliases )
55
+ self ._test ("1.0" , "2.0" , None , kwargs , aliases )
53
56
54
57
def test_rename_and_obsolete (self ):
55
58
kwargs = dict (old_a = 1 , old_b = 2 , c = 3 , d = 4 , z = 10 )
56
59
aliases = {"old_a" : "a" , "old_b" : "b" , "z" : None }
57
- self ._test ("1.0" , "2.0" , kwargs , aliases )
60
+ self ._test ("1.0" , "2.0" , None , kwargs , aliases )
58
61
59
62
def test_with_new_and_alias_present (self ):
60
63
kwargs = dict (old_a = 1 , a = 1 , b = 2 , c = 3 , d = 4 , z = 10 )
61
64
aliases = {"old_a" : "a" , "old_b" : "b" , "z" : None }
62
65
with self .assertRaises (TypeError ):
63
- self ._test ("1.0" , "2.0" , kwargs , aliases )
66
+ self ._test ("1.0" , "2.0" , "Random note." , kwargs , aliases )
64
67
65
68
66
69
class DeprecatedArgsAliasTest (unittest .TestCase ):
@@ -130,6 +133,20 @@ def _test_func3(a):
130
133
warnings .simplefilter ("error" )
131
134
_test_func3 (a = 1 )
132
135
136
+ @deprecated_args_alias (
137
+ "1.0.0" , deprecation_info = "Because why not?" , old_a = "a"
138
+ )
139
+ def _test_func4 (a ):
140
+ pass
141
+
142
+ with pytest .warns (DeprecationWarning ) as record :
143
+ _test_func4 (old_a = 1 )
144
+ assert len (record ) == 1
145
+ assert (
146
+ record [0 ].message .args [0 ]
147
+ == "The 'old_a' argument is deprecated since python-can v1.0.0. Use 'a' instead. Because why not?"
148
+ )
149
+
133
150
134
151
class TestBusConfig (unittest .TestCase ):
135
152
base_config = dict (interface = "socketcan" , bitrate = 500_000 )
0 commit comments