-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_jq_tests.py
43 lines (37 loc) · 1.34 KB
/
run_jq_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
import yaml
import json
import cli
def jq_test():
i = 0
skipped = []
lines = []
for line in open('functional_tests/jq.txt', 'r'):
line = line.strip()
if not line:
if lines:
if lines[0] == 'skip':
skipped.append('\n'.join(lines[1:]))
else:
yield (FunctionalTestCase('jq.txt', i,
{'filter': lines[0],
'input': json.loads(lines[1]),
'output_list': lines[2:]}),)
lines = []
i += 1
elif line[0] != '#':
lines.append(line)
class FunctionalTestCase(object):
def __init__(self, file, idx, case):
self.case = case
self.description = '%s case %d: %s' % (file, idx, case)
def __call__(self):
output = cli.main(self.case['filter'], yaml.dump(self.case['input']))
if 'output' in self.case:
expected_list = [self.case['output']]
else:
expected_list = self.case['output_list']
for expected in expected_list:
actual = output.next()
print 'Actual: %s\nExpected: %s' % (actual, expected)
expected = yaml.load(expected)
assert actual == expected