-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrun_tests.py
executable file
·101 lines (89 loc) · 3.29 KB
/
run_tests.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
import argparse
import subprocess
class col:
RESET = '\033[m'
RED = '\033[31m'
GREEN = '\033[32m'
BRED = '\033[1;31m'
BGREEN = '\033[1;32m'
tests = [
['all', 'https://openscad.org/cheatsheet/'],
['wifi_WPA', 'WIFI:T:WPA;S:wifi_network;P:1234;;'],
['wifi2_WPA', 'WIFI:T:WPA;S:wireless_fidelity;P:PigOtter;;'],
['wifi_WEP', 'WIFI:T:WEP;S:wifi_network;P:1234;;'],
['wifi_nopass', 'WIFI:T:nopass;S:wifi_network;P:;;'],
['wifi_hidden', 'WIFI:T:WPA;S:wifi_network;P:1234;H:true;'],
['phone', 'TEL:+33 1 23 45 67 89'],
['question_mark', 'What text could this QR code possibly contain?????'],
['text_utf8', 'lorem ipsum'],
['text_Shift_JIS', '|orem ipsum'],
['error_correction_M', 'lorem ipsum1'],
['error_correction_Q', 'lorem ipsum2'],
['error_correction_H', 'lorem ipsum3'],
['mask_pattern_1', 'lorem ipsum_1'],
['mask_pattern_2', 'lorem ipsum_2'],
['mask_pattern_3', 'lorem ipsum_3'],
['mask_pattern_4', 'lorem ipsum_4'],
['mask_pattern_5', 'lorem ipsum_5'],
['mask_pattern_6', 'lorem ipsum_6'],
['mask_pattern_7', 'lorem ipsum_7'],
['text_latin1_suppl', 'lörem ¡psüm©®×÷¶'],
]
argparser = argparse.ArgumentParser(prog='test.py',description='Run ScadQR tests')
argparser.add_argument('-s', '--openscad', default='openscad', help='OpenSCAD executable')
argparser.add_argument('-z', '--zbarimg', default='zbarimg', help='zbarimg QR code reader executable')
args = argparser.parse_args()
def exe_not_found(name, path, flag):
print(f'{name} executable at "{path}" not found.')
print(f'Please install {name} or use the "{flag}" flag to specify a custom executable.')
print('Running tests...')
tests_passed = 0
for i, test in enumerate(tests):
testname = test[0]
expect = 'QR-Code:'+test[1]
print(f' {i}/{len(tests)}', end='\r')
openscad_args=[
args.openscad,
'-q',
'--autocenter',
'--viewall',
'--camera=0,0,0,0,0,0,200',
'--projection=ortho',
'-p', 'tests.json',
'-P', testname,
'--export-format', 'png',
'-o', '-',
'demo.scad',
]
openscad_args_str = ' '.join([v for v in openscad_args])
img = ''
try:
img = subprocess.check_output(openscad_args)
except FileNotFoundError:
exe_not_found('OpenSCAD', args.openscad, '-s')
exit()
res = ''
try:
res = subprocess.check_output([
args.zbarimg,
'-q',
'-',
], input=img).decode('utf-8').removesuffix('\n')
except FileNotFoundError:
exe_not_found('zbarimg', args.zbarimg, '-z')
exit()
except subprocess.CalledProcessError as e:
print(f'{col.RED}critical failure{col.RESET} test "{testname}": {e.cmd} returned with error {e.returncode}: "{e.output}"')
print(f'command: {openscad_args_str}')
exit()
if (res == expect):
tests_passed += 1
else:
print(f'{col.RED}failed{col.RESET} test "{testname}": got "{res}", expected "{expect}"')
print(f'command: {openscad_args_str}')
if tests_passed == len(tests):
print(f'{col.BGREEN}PASS{col.RESET} {tests_passed}/{len(tests)} tests passed')
else:
print(f'{col.BRED}FAIL{col.RESET} {len(tests) - tests_passed}/{len(tests)} tests failed')
exit(1)