@@ -361,14 +361,16 @@ def test_optimization_levels__debug__(self):
361361 cases = [(- 1 , '__debug__' ), (0 , '__debug__' ), (1 , False ), (2 , False )]
362362 for (optval , expected ) in cases :
363363 with self .subTest (optval = optval , expected = expected ):
364- res = ast .parse ("__debug__" , optimize = optval )
365- self .assertIsInstance (res .body [0 ], ast .Expr )
366- if isinstance (expected , bool ):
367- self .assertIsInstance (res .body [0 ].value , ast .Constant )
368- self .assertEqual (res .body [0 ].value .value , expected )
369- else :
370- self .assertIsInstance (res .body [0 ].value , ast .Name )
371- self .assertEqual (res .body [0 ].value .id , expected )
364+ res1 = ast .parse ("__debug__" , optimize = optval )
365+ res2 = ast .parse (ast .parse ("__debug__" ), optimize = optval )
366+ for res in [res1 , res2 ]:
367+ self .assertIsInstance (res .body [0 ], ast .Expr )
368+ if isinstance (expected , bool ):
369+ self .assertIsInstance (res .body [0 ].value , ast .Constant )
370+ self .assertEqual (res .body [0 ].value .value , expected )
371+ else :
372+ self .assertIsInstance (res .body [0 ].value , ast .Name )
373+ self .assertEqual (res .body [0 ].value .id , expected )
372374
373375 def test_optimization_levels_const_folding (self ):
374376 folded = ('Expr' , (1 , 0 , 1 , 5 ), ('Constant' , (1 , 0 , 1 , 5 ), 3 , None ))
@@ -381,9 +383,11 @@ def test_optimization_levels_const_folding(self):
381383 cases = [(- 1 , not_folded ), (0 , not_folded ), (1 , folded ), (2 , folded )]
382384 for (optval , expected ) in cases :
383385 with self .subTest (optval = optval ):
384- tree = ast .parse ("1 + 2" , optimize = optval )
385- res = to_tuple (tree .body [0 ])
386- self .assertEqual (res , expected )
386+ tree1 = ast .parse ("1 + 2" , optimize = optval )
387+ tree2 = ast .parse (ast .parse ("1 + 2" ), optimize = optval )
388+ for tree in [tree1 , tree2 ]:
389+ res = to_tuple (tree .body [0 ])
390+ self .assertEqual (res , expected )
387391
388392 def test_invalid_position_information (self ):
389393 invalid_linenos = [
0 commit comments