@@ -1326,5 +1326,38 @@ def test_assert_not_in_with_arg_in_bytecode(self):
13261326 with self .assertRaises (AssertionError ):
13271327 self .assertNotInBytecode (code , "LOAD_CONST" , 1 )
13281328
1329+ class TestFinderMethods (unittest .TestCase ):
1330+ def test__find_imports (self ):
1331+ cases = [
1332+ ("import a.b.c" , ('a.b.c' , 0 , None )),
1333+ ("from a.b import c" , ('a.b' , 0 , ('c' ,))),
1334+ ("from a.b import c as d" , ('a.b' , 0 , ('c' ,))),
1335+ ("from a.b import *" , ('a.b' , 0 , ('*' ,))),
1336+ ("from ...a.b import c as d" , ('a.b' , 3 , ('c' ,))),
1337+ ("from ..a.b import c as d, e as f" , ('a.b' , 2 , ('c' , 'e' ))),
1338+ ("from ..a.b import *" , ('a.b' , 2 , ('*' ,))),
1339+ ]
1340+ for src , expected in cases :
1341+ with self .subTest (src = src ):
1342+ code = compile (src , "<string>" , "exec" )
1343+ res = tuple (dis ._find_imports (code ))
1344+ self .assertEqual (len (res ), 1 )
1345+ self .assertEqual (res [0 ], expected )
1346+
1347+ def test__find_store_names (self ):
1348+ cases = [
1349+ ("x+y" , ()),
1350+ ("x=y=1" , ('x' , 'y' )),
1351+ ("x+=y" , ('x' ,)),
1352+ ("global x\n x=y=1" , ('x' , 'y' )),
1353+ ("global x\n z=x" , ('z' ,)),
1354+ ]
1355+ for src , expected in cases :
1356+ with self .subTest (src = src ):
1357+ code = compile (src , "<string>" , "exec" )
1358+ res = tuple (dis ._find_store_names (code ))
1359+ self .assertEqual (res , expected )
1360+
1361+
13291362if __name__ == "__main__" :
13301363 unittest .main ()
0 commit comments