-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
compiler_test.py
executable file
·40 lines (38 loc) · 1.15 KB
/
compiler_test.py
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
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
try:
from kast import ast_export
except:
print("What gives")
from parser_test_helper import *
@SkippingTest
class CompilerPythonEquivalenceTest: # (ParserBaseTest):
def test_compiler_output_equivalence(self):
skip()
source = '../kast/tests/hi.py'
# source='../core/english_parser.py'
contents = open(source).readlines() # all()
contents = "\n".join(contents)
contents = "print('hi')"
inline = "(string)" # compile from inline string source:
source = inline
parse(contents)
file_ast = compile(contents, source, 'exec', ast.PyCF_ONLY_AST)
# x=ast.dump(file_ast, annotate_fields=True, include_attributes=True)
angle_ast = parse_tree(contents)
print((ast.dump(file_ast, annotate_fields=False, include_attributes=False)))
print((ast.dump(angle_ast, annotate_fields=False, include_attributes=False)))
assert_equals(file_ast, angle_ast)
code = compile(angle_ast, 'file', 'exec')
if source == inline:
ast_export.emit_pyc(code)
else:
ast_export.emit_pyc(code, source + ".pyc")
try:
exec(code)
except:
pass
#
# try:
# CompilerPythonEquivalenceTest().test_compiler_output_equivalence()
# except:
# pass