Wenzel Jakob | 6d6fd09 | 2015-10-01 17:34:26 +0200 | [diff] [blame] | 1 | import sys |
| 2 | import os |
| 3 | import re |
| 4 | import subprocess |
| 5 | |
| 6 | remove_unicode_marker = re.compile(r'u(\'[^\']*\')') |
| 7 | remove_long_marker = re.compile(r'([0-9])L') |
Wenzel Jakob | 607654f | 2015-10-13 23:58:10 +0200 | [diff] [blame] | 8 | remove_hex = re.compile(r'0x[0-9a-fA-F]+') |
Wenzel Jakob | 6d6fd09 | 2015-10-01 17:34:26 +0200 | [diff] [blame] | 9 | shorten_floats = re.compile(r'([1-9][0-9]*\.[0-9]{4})[0-9]*') |
| 10 | |
| 11 | |
| 12 | def 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 Jakob | 3b806d4 | 2015-10-11 16:29:35 +0200 | [diff] [blame] | 20 | line = remove_hex.sub(r'0', line) |
Wenzel Jakob | 6d6fd09 | 2015-10-01 17:34:26 +0200 | [diff] [blame] | 21 | 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() |
Wenzel Jakob | 607654f | 2015-10-13 23:58:10 +0200 | [diff] [blame] | 26 | if sys.platform == 'win32': |
| 27 | lower = line.lower() |
Wenzel Jakob | 76269b7 | 2015-12-13 11:33:41 +0100 | [diff] [blame] | 28 | # The precise pattern of allocations and deallocations is dependent on the compiler |
| 29 | # and optimization level, so we unfortunately can't reliably check it in this kind of test case |
Wenzel Jakob | fab881c | 2015-10-18 17:04:24 +0200 | [diff] [blame] | 30 | if 'constructor' in lower or 'destructor' in lower \ |
Wenzel Jakob | 76269b7 | 2015-12-13 11:33:41 +0100 | [diff] [blame] | 31 | or 'ref' in lower or 'freeing' in lower: |
Wenzel Jakob | 607654f | 2015-10-13 23:58:10 +0200 | [diff] [blame] | 32 | line = "" |
Wenzel Jakob | 6d6fd09 | 2015-10-01 17:34:26 +0200 | [diff] [blame] | 33 | lines[i] = line |
| 34 | |
| 35 | lines = '\n'.join(sorted([l for l in lines if l != ""])) |
| 36 | |
| 37 | print('==================') |
| 38 | print(lines) |
| 39 | return lines |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 40 | |
| 41 | path = os.path.dirname(__file__) |
| 42 | if path != '': |
| 43 | os.chdir(path) |
| 44 | |
| 45 | name = sys.argv[1] |
Wenzel Jakob | fab881c | 2015-10-18 17:04:24 +0200 | [diff] [blame] | 46 | output_bytes = subprocess.check_output([sys.executable, name + ".py"], |
| 47 | stderr=subprocess.STDOUT) |
| 48 | |
Wenzel Jakob | 6d6fd09 | 2015-10-01 17:34:26 +0200 | [diff] [blame] | 49 | output = sanitize(output_bytes.decode('utf-8')) |
| 50 | reference = sanitize(open(name + '.ref', 'r').read()) |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 51 | |
Wenzel Jakob | fab881c | 2015-10-18 17:04:24 +0200 | [diff] [blame] | 52 | if 'NumPy missing' in output: |
| 53 | print('Test "%s" could not be run.' % name) |
| 54 | exit(0) |
| 55 | elif output == reference: |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 56 | print('Test "%s" succeeded.' % name) |
| 57 | exit(0) |
| 58 | else: |
| 59 | print('Test "%s" FAILED!' % name) |
| 60 | exit(-1) |