blob: d017031e8c370e7bb411ba75522204974bc0cb15 [file] [log] [blame]
Wenzel Jakob6d6fd092015-10-01 17:34:26 +02001import sys
2import os
3import re
4import subprocess
5
6remove_unicode_marker = re.compile(r'u(\'[^\']*\')')
7remove_long_marker = re.compile(r'([0-9])L')
8remove_hex = re.compile(r'0x[0-9a-f]+')
9shorten_floats = re.compile(r'([1-9][0-9]*\.[0-9]{4})[0-9]*')
10
11
12def sanitize(lines):
13 lines = lines.split('\n')
14 for i in range(len(lines)):
15 line = lines[i]
16 if line.startswith(" |"):
17 line = ""
18 line = remove_unicode_marker.sub(r'\1', line)
19 line = remove_long_marker.sub(r'\1', line)
Wenzel Jakob3b806d42015-10-11 16:29:35 +020020 line = remove_hex.sub(r'0', line)
Wenzel Jakob6d6fd092015-10-01 17:34:26 +020021 line = shorten_floats.sub(r'\1', line)
22 line = line.replace('__builtin__', 'builtins')
23 line = line.replace('example.', '')
24 line = line.replace('method of builtins.PyCapsule instance', '')
25 line = line.strip()
26 lines[i] = line
27
28 lines = '\n'.join(sorted([l for l in lines if l != ""]))
29
30 print('==================')
31 print(lines)
32 return lines
Wenzel Jakob38bd7112015-07-05 20:05:44 +020033
34path = os.path.dirname(__file__)
35if path != '':
36 os.chdir(path)
37
38name = sys.argv[1]
Wenzel Jakob6d6fd092015-10-01 17:34:26 +020039output_bytes = subprocess.check_output([sys.executable, name + ".py"])
40output = sanitize(output_bytes.decode('utf-8'))
41reference = sanitize(open(name + '.ref', 'r').read())
Wenzel Jakob38bd7112015-07-05 20:05:44 +020042
43if output == reference:
44 print('Test "%s" succeeded.' % name)
45 exit(0)
46else:
47 print('Test "%s" FAILED!' % name)
48 exit(-1)