22Test the API of the symtable module.
33"""
44
5+ import re
56import textwrap
67import symtable
78import unittest
@@ -359,25 +360,32 @@ def test_name(self):
359360 self .assertEqual (self .Mine .get_name (), "Mine" )
360361
361362 def test_class_get_methods (self ):
362- self .assertEqual (self .Mine .get_methods (), ('a_method' ,))
363+ deprecation_mess = (
364+ re .escape ('symtable.Class.get_methods() is deprecated '
365+ 'and will be removed in Python 3.16.' )
366+ )
367+
368+ with self .assertWarnsRegex (DeprecationWarning , deprecation_mess ):
369+ self .assertEqual (self .Mine .get_methods (), ('a_method' ,))
363370
364371 top = symtable .symtable (TEST_COMPLEX_CLASS_CODE , "?" , "exec" )
365372 this = find_block (top , "ComplexClass" )
366373
367- self .assertEqual (this .get_methods (), (
368- 'a_method' , 'a_method_pep_695' ,
369- 'an_async_method' , 'an_async_method_pep_695' ,
370- 'a_classmethod' , 'a_classmethod_pep_695' ,
371- 'an_async_classmethod' , 'an_async_classmethod_pep_695' ,
372- 'a_staticmethod' , 'a_staticmethod_pep_695' ,
373- 'an_async_staticmethod' , 'an_async_staticmethod_pep_695' ,
374- 'a_fakemethod' , 'a_fakemethod_pep_695' ,
375- 'an_async_fakemethod' , 'an_async_fakemethod_pep_695' ,
376- 'glob_unassigned_meth' , 'glob_unassigned_meth_pep_695' ,
377- 'glob_unassigned_async_meth' , 'glob_unassigned_async_meth_pep_695' ,
378- 'glob_assigned_meth' , 'glob_assigned_meth_pep_695' ,
379- 'glob_assigned_async_meth' , 'glob_assigned_async_meth_pep_695' ,
380- ))
374+ with self .assertWarnsRegex (DeprecationWarning , deprecation_mess ):
375+ self .assertEqual (this .get_methods (), (
376+ 'a_method' , 'a_method_pep_695' ,
377+ 'an_async_method' , 'an_async_method_pep_695' ,
378+ 'a_classmethod' , 'a_classmethod_pep_695' ,
379+ 'an_async_classmethod' , 'an_async_classmethod_pep_695' ,
380+ 'a_staticmethod' , 'a_staticmethod_pep_695' ,
381+ 'an_async_staticmethod' , 'an_async_staticmethod_pep_695' ,
382+ 'a_fakemethod' , 'a_fakemethod_pep_695' ,
383+ 'an_async_fakemethod' , 'an_async_fakemethod_pep_695' ,
384+ 'glob_unassigned_meth' , 'glob_unassigned_meth_pep_695' ,
385+ 'glob_unassigned_async_meth' , 'glob_unassigned_async_meth_pep_695' ,
386+ 'glob_assigned_meth' , 'glob_assigned_meth_pep_695' ,
387+ 'glob_assigned_async_meth' , 'glob_assigned_async_meth_pep_695' ,
388+ ))
381389
382390 # Test generator expressions that are of type TYPE_FUNCTION
383391 # but will not be reported by get_methods() since they are
@@ -390,7 +398,8 @@ def check_body(body, expected_methods):
390398 indented = textwrap .indent (body , ' ' * 4 )
391399 top = symtable .symtable (f"class A:\n { indented } " , "?" , "exec" )
392400 this = find_block (top , "A" )
393- self .assertEqual (this .get_methods (), expected_methods )
401+ with self .assertWarnsRegex (DeprecationWarning , deprecation_mess ):
402+ self .assertEqual (this .get_methods (), expected_methods )
394403
395404 # statements with 'genexpr' inside it
396405 GENEXPRS = (
0 commit comments