forked from mobstac-private/tqrcg-barcode.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-blackbox-testdata.py
executable file
·50 lines (39 loc) · 1.26 KB
/
generate-blackbox-testdata.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
#!/usr/bin/python
# (c) 2013 Manuel Braun (mb@w69b.com)
# Generates .js file from zxing blackbox test data that can be included in tests.
import glob
import os
import json
data_dir = 'test_data/blackbox'
outfile = 'tests/blackbox.data.js'
def readfile(file):
with open(file) as f:
return f.read();
def get_test_items(suite_dir):
test_items = []
extensions = ['.png', '.gif', '.jpg']
txt_files = glob.glob(suite_dir + '/*.txt')
for txt in sorted(txt_files):
basename = os.path.splitext(txt)[0]
for ext in extensions:
img = basename + ext
if os.path.exists(img):
expected = readfile(txt)
item = {'image': img,
'expected': expected}
test_items.append(item)
continue
return test_items
def generate():
suites = glob.glob(data_dir + '/qrcode-*')
suite_items = {}
for suite in sorted(suites):
name = os.path.basename(suite)
suite_items[name] = get_test_items(suite)
js_code = 'define({});'.format(
json.dumps(suite_items, indent=4))
with open(outfile, 'w') as f:
f.write(js_code)
print 'DONE. {} was updated'.format(outfile)
if __name__ == '__main__':
generate()