-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtest_unparse_env.py
40 lines (29 loc) · 920 Bytes
/
test_unparse_env.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
import ast
import os
import sys
import warnings
import pytest
from python_minifier import minify, unparse
warnings.filterwarnings('ignore')
def gather_files():
print('Interpreter version: ', sys.version_info)
print('sys.path: ', sys.path)
for sys_path in sys.path:
for subdir, _dirs, files in os.walk(sys_path):
for file in filter(lambda f: f.endswith('.py'), [os.path.join(subdir, file) for file in files]):
yield file
@pytest.mark.parametrize('path', gather_files())
def test_unparse(path):
try:
with open(path, 'rb') as f:
source = f.read()
except IOError:
pytest.skip('IOError opening file')
try:
original_ast = ast.parse(source, path)
except SyntaxError:
pytest.skip('Invalid syntax in file')
# Test unparsing
unparse(original_ast)
# Test transforms
minify(source, filename=path)