-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathtest_codegen.py
More file actions
30 lines (26 loc) · 936 Bytes
/
test_codegen.py
File metadata and controls
30 lines (26 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import codegen
import ast
def to_ast_and_back_again(source):
return codegen.to_source(ast.parse(source))
def test_del():
source = "del l[0]"
assert source == to_ast_and_back_again(source)
source = "del obj.x"
assert source == to_ast_and_back_again(source)
def test_try_expect():
source = ("try:\n"
" '#'[2]\n"
"except IndexError:\n"
" print 'What did you expect?!'")
assert source == to_ast_and_back_again(source)
source = ("try:\n"
" l = []\n"
" l[1]\n"
"except IndexError, index_error:\n"
" print index_error")
assert source == to_ast_and_back_again(source)
def test_import():
source = "import intertools as iterators"
assert source == to_ast_and_back_again(source)
source = "from math import floor as fl, ceil as cl"
assert source == to_ast_and_back_again(source)