type check AST strings and identifiers

This is related to a21829180423 as well as #12609 and #12610.
This commit is contained in:
Benjamin Peterson 2011-07-22 10:50:23 -05:00
parent 996f606787
commit 2193d2b72b
4 changed files with 57 additions and 6 deletions

View file

@ -364,6 +364,20 @@ class AST_Tests(unittest.TestCase):
compile(m, "<test>", "exec")
self.assertIn("but got <_ast.expr", str(cm.exception))
def test_invalid_identitifer(self):
m = ast.Module([ast.Expr(ast.Name(42, ast.Load()))])
ast.fix_missing_locations(m)
with self.assertRaises(TypeError) as cm:
compile(m, "<test>", "exec")
self.assertIn("identifier must be of type str", str(cm.exception))
def test_invalid_string(self):
m = ast.Module([ast.Expr(ast.Str(42))])
ast.fix_missing_locations(m)
with self.assertRaises(TypeError) as cm:
compile(m, "<test>", "exec")
self.assertIn("string must be of type str", str(cm.exception))
class ASTHelpers_Test(unittest.TestCase):