forked from PythonJS/PythonJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntests.py
More file actions
executable file
·50 lines (42 loc) · 1.47 KB
/
runtests.py
File metadata and controls
executable file
·50 lines (42 loc) · 1.47 KB
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
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import os
from difflib import Differ
from envoy import run
from pythonjs.pythonscript import main as pythonjs
ROOT = os.path.join(os.path.dirname(__file__), 'unittests')
with open('pythonjs.js') as f:
PYTHONJS = f.read()
MOCK = """
// MOCK START
window = {};
HTMLDocument = HTMLElement = function() {};
// MOCK END
"""
if __name__ == '__main__':
for test in os.listdir(ROOT):
if test.endswith('.py'):
filepath = os.path.join(ROOT, test)
with open(filepath) as f:
script = f.read()
exec_script = test + 'exec.js'
exec_script = os.path.join('/tmp', exec_script)
with open(exec_script, 'w') as f:
f.write(MOCK)
f.write(PYTHONJS)
f.write(pythonjs(script))
r = run('nodejs %s' % exec_script)
if r.status_code != 0:
print(r.std_err)
print('%s ERROR :(' % test)
else:
expected = os.path.join(ROOT, test + '.expected')
with open(expected) as f:
expected = f.read()
if expected == r.std_out:
print('%s PASS :)' % test)
else:
compare = Differ().compare
diff = compare(expected.split('\n'), r.std_out.split('\n'))
for line in diff:
print(line)
print('%s FAILED :(' % test)