Commits

Victor Stinner committed 8dce810

update unit tests

Comments (0)

Files changed (1)

astoptimizer/tests.py

         if config is None:
             config = self._default_config
         optimizer = Optimizer(config)
-        tree = optimizer.optimize(tree)
+        tree = optimizer.optimize(tree, None)
         # Ensure that the tree is compilable to bytecode
         try:
             compile_ast(tree)
                     self.assertEqual(emitted, message)
                 else:
                     # regex
-                    self.assertTrue(message.match(emitted), emitted)
+                    self.assertTrue(message.search(emitted), emitted)
         elif emitted:
             raise Exception("%s: %s" % (what, emitted))
 
         # return, raise
         self.check('def f():\n return 1\n return 2',
                    self.text_ast('def f():\n return 1'),
-                   info='Remove dead code at <string>:3 (unreachable): Return(value=Num(n=2))')
+                   info='<string>:3: Remove unreachable code: Return(value=Num(n=2))')
         self.check('def f():\n raise\n return 2',
                    self.text_ast('def f():\n raise'),
-                   info='Remove dead code at <string>:3 (unreachable): Return(value=Num(n=2))')
+                   info='<string>:3: Remove unreachable code: Return(value=Num(n=2))')
         self.check('def f():\n g()\n return 1\n h()\n return 2',
                    self.text_ast('def f():\n g()\n return 1'),
-                   info=["Remove dead code at <string>:4 (unreachable): Expr(value=Call(func=Name(id='h', ctx=Load()), args=[], keywords=[], starargs=None, kwargs=None))",
-                        "Remove dead code at <string>:5 (unreachable): Return(value=Num(n=2))"])
+                   info=["<string>:4: Remove unreachable code: Expr(value=Call(func=Name(id='h', ctx=Load()), args=[], keywords=[], starargs=None, kwargs=None))",
+                        "<string>:5: Remove unreachable code: Return(value=Num(n=2))"])
         self.check('def f():\n g()\n raise ValueError("error")\n h()\n return 2',
                    self.text_ast('def f():\n g()\n raise ValueError("error")'),
-                   info=["Remove dead code at <string>:4 (unreachable): Expr(value=Call(func=Name(id='h', ctx=Load()), args=[], keywords=[], starargs=None, kwargs=None))",
-                         "Remove dead code at <string>:5 (unreachable): Return(value=Num(n=2))"])
+                   info=["<string>:4: Remove unreachable code: Expr(value=Call(func=Name(id='h', ctx=Load()), args=[], keywords=[], starargs=None, kwargs=None))",
+                         "<string>:5: Remove unreachable code: Return(value=Num(n=2))"])
 
         # global, nonlocal
         self.check_not_optimized('''
         no_docstring.remove_docstring = True
         self.check('def f():\n "docstring"\n return 1',
                    self.text_ast('def f():\n return 1'),
-                   info="Remove dead code at <string>:2: Expr(value=Str(s='docstring'))",
                    config=no_docstring)
 
     def test_remove_almost_dead_code(self):
         self.check('obj.attr',
                    self.text_ast('pass'),
                    config=config,
-                   info=re.compile('^Remove dead code'))
+                   info=re.compile('Remove dead code'))
         self.check_not_optimized('func()', config=config)
 
     def test_dont_remove_dead_code(self):
         if after == 'if a and b: print("true")':
             after = 'if a and b:\n print("true")'
         if 'return 1; return 2' in before:
-            info = 'Remove dead code at <string>:1 (unreachable): Return(value=Num(n=2))'
-        if ' 3; return s' in before:
-            info = 'Remove dead code at <string>:1: Expr(value=Num(n=3))'
+            info = re.compile('Remove unreachable code')
+        elif ' 3; return s' in before:
+            info = re.compile('Remove dead code')
 
         if 'if DEBUG:' in before:
             config = self.create_default_config()