@@ -29,7 +29,7 @@ def test_warning(self):
2929 def foo2 ():
3030 pass
3131
32- print ( foo2 ())
32+ foo2 () # should not raise any warnings
3333
3434 def test_warning_milestone (self ):
3535 """Test deprecated decorator with `since` and `removed` set for a milestone version"""
@@ -172,7 +172,7 @@ def test_arg_warn2(self):
172172 """Test deprecated_arg decorator with just `since` set."""
173173
174174 @deprecated_arg ("b" , since = self .prev_version , version_val = self .test_version )
175- def afoo2 (a , ** kwargs ):
175+ def afoo2 (a , ** kw ):
176176 pass
177177
178178 afoo2 (1 ) # ok when no b provided
@@ -235,6 +235,19 @@ def afoo4(a, b=None):
235235
236236 self .assertRaises (DeprecatedError , lambda : afoo4 (1 , b = 2 ))
237237
238+ def test_arg_except3_unknown (self ):
239+ """
240+ Test deprecated_arg decorator raises exception with `removed` set in the past.
241+ with unknown version and kwargs
242+ """
243+
244+ @deprecated_arg ("b" , removed = self .prev_version , version_val = "0+untagged.1.g3131155" )
245+ def afoo4 (a , b = None , ** kwargs ):
246+ pass
247+
248+ self .assertRaises (DeprecatedError , lambda : afoo4 (1 , b = 2 ))
249+ self .assertRaises (DeprecatedError , lambda : afoo4 (1 , b = 2 , c = 3 ))
250+
238251 def test_replacement_arg (self ):
239252 """
240253 Test deprecated arg being replaced.
@@ -245,10 +258,36 @@ def afoo4(a, b=None):
245258 return a
246259
247260 self .assertEqual (afoo4 (b = 2 ), 2 )
248- # self.assertRaises(DeprecatedError, lambda: afoo4(1, b=2))
249261 self .assertEqual (afoo4 (1 , b = 2 ), 1 ) # new name is in use
250262 self .assertEqual (afoo4 (a = 1 , b = 2 ), 1 ) # prefers the new arg
251263
264+ def test_replacement_arg1 (self ):
265+ """
266+ Test deprecated arg being replaced with kwargs.
267+ """
268+
269+ @deprecated_arg ("b" , new_name = "a" , since = self .prev_version , version_val = self .test_version )
270+ def afoo4 (a , * args , ** kwargs ):
271+ return a
272+
273+ self .assertEqual (afoo4 (b = 2 ), 2 )
274+ self .assertEqual (afoo4 (1 , b = 2 , c = 3 ), 1 ) # new name is in use
275+ self .assertEqual (afoo4 (a = 1 , b = 2 , c = 3 ), 1 ) # prefers the new arg
276+
277+ def test_replacement_arg2 (self ):
278+ """
279+ Test deprecated arg (with a default value) being replaced.
280+ """
281+
282+ @deprecated_arg ("b" , new_name = "a" , since = self .prev_version , version_val = self .test_version )
283+ def afoo4 (a , b = None , ** kwargs ):
284+ return a , kwargs
285+
286+ self .assertEqual (afoo4 (b = 2 , c = 3 ), (2 , {"c" : 3 }))
287+ self .assertEqual (afoo4 (1 , b = 2 , c = 3 ), (1 , {"c" : 3 })) # new name is in use
288+ self .assertEqual (afoo4 (a = 1 , b = 2 , c = 3 ), (1 , {"c" : 3 })) # prefers the new arg
289+ self .assertEqual (afoo4 (1 , 2 , c = 3 ), (1 , {"c" : 3 })) # prefers the new positional arg
290+
252291
253292if __name__ == "__main__" :
254293 unittest .main ()
0 commit comments