Beispiel #1
0
 def testWriteExceptDispatcherBareExceptionNotLast(self):
     visitor = stmt.StatementVisitor(_MakeModuleBlock())
     handlers = [
         ast.ExceptHandler(type=None),
         ast.ExceptHandler(type=ast.Name(id='foo'))
     ]
     self.assertRaisesRegexp(
         util.ParseError,
         r"default 'except:' must be last",
         visitor._write_except_dispatcher,  # pylint: disable=protected-access
         'exc',
         'tb',
         handlers)
Beispiel #2
0
 def testWriteExceptDispatcherBareExcept(self):
     visitor = stmt.StatementVisitor(_MakeModuleBlock())
     handlers = [
         ast.ExceptHandler(type=ast.Name(id='foo')),
         ast.ExceptHandler(type=None)
     ]
     self.assertEqual(
         visitor._write_except_dispatcher(  # pylint: disable=protected-access
             'exc', 'tb', handlers),
         [1, 2])
     expected = re.compile(
         r'ResolveGlobal\(.*foo.*\bIsInstance\(.*'
         r'goto Label1.*goto Label2', re.DOTALL)
     self.assertRegexpMatches(visitor.writer.getvalue(), expected)
Beispiel #3
0
 def testWriteExceptDispatcherMultipleExcept(self):
     visitor = stmt.StatementVisitor(_MakeModuleBlock())
     handlers = [
         ast.ExceptHandler(type=ast.Name(id='foo')),
         ast.ExceptHandler(type=ast.Name(id='bar'))
     ]
     self.assertEqual(
         visitor._write_except_dispatcher(  # pylint: disable=protected-access
             'exc', 'tb', handlers),
         [1, 2])
     expected = re.compile(
         r'ResolveGlobal\(.*foo.*\bif .*\bIsInstance\(.*\{.*goto Label1.*'
         r'ResolveGlobal\(.*bar.*\bif .*\bIsInstance\(.*\{.*goto Label2.*'
         r'\bRaise\(exc\.ToObject\(\), nil, tb\.ToObject\(\)\)', re.DOTALL)
     self.assertRegexpMatches(visitor.writer.getvalue(), expected)