forked from leancloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmypy_test.py
More file actions
35 lines (29 loc) · 1.01 KB
/
Copy pathmypy_test.py
File metadata and controls
35 lines (29 loc) · 1.01 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
# coding: utf-8
import ast
import os
import re
import tempfile
# this script should be excuted under python_SDK/tests
def main():
file_list = [f for f in os.listdir('.') if re.search('^test_.*\.py$', f) and f !=('test_mypy.py' or 'test_engine.py')]
temp_dir = tempfile.gettempdir()
for f in file_list:
f_buf = open(f)
f_text = f_buf.read()
f_buf.close()
file_name = 'mypy_' + f
nodes = ast.walk(ast.parse(f_text))
tests = [node.name for node in nodes if type(node) == ast.FunctionDef and node.name.startswith('test')]
test_file = temp_dir + '/' + file_name
mypy_test = open(test_file, 'w')
mypy_test.write('import {}\n\n'.format(f[:-3]))
middle = '()\n' + f[:-3] + '.'
funcs = middle.join(tests)
funcs += '()'
funcs = f[:-3] + '.' + funcs
mypy_test.write(funcs)
mypy_test.close()
os.system('mypy {}'.format(test_file))
os.remove(test_file)
if __name__ == '__main__':
main()