unittest.py

changeset 126
16dae12ac0f0
parent 123
0557709c25ec
child 127
97de6058109e
equal deleted inserted replaced
125:43d6ed8515ab 126:16dae12ac0f0
23 23
24 def load_unit_test(unit_test_path, *, name, ldraw_directories): 24 def load_unit_test(unit_test_path, *, name, ldraw_directories):
25 with open(unit_test_path, 'rb') as device: 25 with open(unit_test_path, 'rb') as device:
26 import re 26 import re
27 problem_types = set() 27 problem_types = set()
28 expecting = set() 28 expecting = None
29 while True: 29 while True:
30 pos = device.tell() 30 pos = device.tell()
31 line = bytes.decode(device.readline()) 31 line = bytes.decode(device.readline())
32 if not line: 32 if not line:
33 raise ValueError('unit test ended unexpectedly') 33 raise ValueError('unit test ended unexpectedly')
34 match = re.match('^0 Testing: (.+)', line) 34 match = re.match('^0 Testing: (.+)', line)
35 if match: 35 if match:
36 set.update(problem_types, match.group(1).split()) 36 set.update(problem_types, match.group(1).split())
37 elif str.strip(line) == '0 Expecting: none':
38 expecting = set()
37 else: 39 else:
38 match = re.match('^0 Expecting: (.+)', line) 40 match = re.match('^0 Expecting: (.+)', line)
39 if match: 41 if match:
42 if not expecting:
43 expecting = set()
40 set.update(expecting, map(parse_expectation, match.group(1).split())) 44 set.update(expecting, map(parse_expectation, match.group(1).split()))
41 else: 45 else:
42 device.seek(pos) 46 device.seek(pos)
43 break 47 break
44 if not problem_types or not expecting: 48 if not problem_types or expecting is None:
45 raise ValueError(str.format( 49 raise ValueError(str.format(
46 'Unit test {name} does not have a proper manifest', 50 'Unit test {name} does not have a proper manifest',
47 name = name, 51 name = name,
48 )) 52 ))
49 return { 53 return {

mercurial