2015-10-01 15:34:26 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
2016-06-01 21:16:13 +00:00
|
|
|
import difflib
|
2015-10-01 15:34:26 +00:00
|
|
|
|
|
|
|
remove_unicode_marker = re.compile(r'u(\'[^\']*\')')
|
|
|
|
remove_long_marker = re.compile(r'([0-9])L')
|
2015-10-13 21:58:10 +00:00
|
|
|
remove_hex = re.compile(r'0x[0-9a-fA-F]+')
|
2015-10-01 15:34:26 +00:00
|
|
|
shorten_floats = re.compile(r'([1-9][0-9]*\.[0-9]{4})[0-9]*')
|
|
|
|
|
2016-02-20 19:53:10 +00:00
|
|
|
relaxed = False
|
2015-10-01 15:34:26 +00:00
|
|
|
|
|
|
|
def sanitize(lines):
|
|
|
|
lines = lines.split('\n')
|
|
|
|
for i in range(len(lines)):
|
|
|
|
line = lines[i]
|
|
|
|
if line.startswith(" |"):
|
|
|
|
line = ""
|
|
|
|
line = remove_unicode_marker.sub(r'\1', line)
|
|
|
|
line = remove_long_marker.sub(r'\1', line)
|
2015-10-11 14:29:35 +00:00
|
|
|
line = remove_hex.sub(r'0', line)
|
2015-10-01 15:34:26 +00:00
|
|
|
line = shorten_floats.sub(r'\1', line)
|
|
|
|
line = line.replace('__builtin__', 'builtins')
|
|
|
|
line = line.replace('example.', '')
|
2016-01-17 21:36:37 +00:00
|
|
|
line = line.replace('unicode', 'str')
|
2016-01-17 21:36:41 +00:00
|
|
|
line = line.replace('Example4.EMode', 'EMode')
|
|
|
|
line = line.replace('example.EMode', 'EMode')
|
2015-10-01 15:34:26 +00:00
|
|
|
line = line.replace('method of builtins.PyCapsule instance', '')
|
|
|
|
line = line.strip()
|
2016-02-20 19:53:10 +00:00
|
|
|
if relaxed:
|
2015-10-13 21:58:10 +00:00
|
|
|
lower = line.lower()
|
2015-12-13 10:33:41 +00:00
|
|
|
# The precise pattern of allocations and deallocations is dependent on the compiler
|
|
|
|
# and optimization level, so we unfortunately can't reliably check it in this kind of test case
|
2015-10-18 15:04:24 +00:00
|
|
|
if 'constructor' in lower or 'destructor' in lower \
|
2015-12-13 10:33:41 +00:00
|
|
|
or 'ref' in lower or 'freeing' in lower:
|
2015-10-13 21:58:10 +00:00
|
|
|
line = ""
|
2015-10-01 15:34:26 +00:00
|
|
|
lines[i] = line
|
|
|
|
|
2016-06-01 21:16:13 +00:00
|
|
|
return '\n'.join(sorted([l for l in lines if l != ""]))
|
2015-07-05 18:05:44 +00:00
|
|
|
|
|
|
|
path = os.path.dirname(__file__)
|
|
|
|
if path != '':
|
|
|
|
os.chdir(path)
|
|
|
|
|
2016-02-20 19:53:10 +00:00
|
|
|
if len(sys.argv) < 2:
|
2016-02-20 20:19:30 +00:00
|
|
|
print("Syntax: %s [--relaxed] <test name>" % sys.argv[0])
|
2016-02-20 19:53:10 +00:00
|
|
|
exit(0)
|
|
|
|
|
2016-02-20 20:19:30 +00:00
|
|
|
if len(sys.argv) == 3 and sys.argv[1] == '--relaxed':
|
|
|
|
del sys.argv[1]
|
2016-02-20 19:53:10 +00:00
|
|
|
relaxed = True
|
|
|
|
|
2015-07-05 18:05:44 +00:00
|
|
|
name = sys.argv[1]
|
2015-10-18 15:04:24 +00:00
|
|
|
output_bytes = subprocess.check_output([sys.executable, name + ".py"],
|
|
|
|
stderr=subprocess.STDOUT)
|
|
|
|
|
2015-10-01 15:34:26 +00:00
|
|
|
output = sanitize(output_bytes.decode('utf-8'))
|
|
|
|
reference = sanitize(open(name + '.ref', 'r').read())
|
2015-07-05 18:05:44 +00:00
|
|
|
|
2015-10-18 15:04:24 +00:00
|
|
|
if 'NumPy missing' in output:
|
|
|
|
print('Test "%s" could not be run.' % name)
|
|
|
|
exit(0)
|
|
|
|
elif output == reference:
|
2015-07-05 18:05:44 +00:00
|
|
|
print('Test "%s" succeeded.' % name)
|
|
|
|
exit(0)
|
|
|
|
else:
|
|
|
|
print('Test "%s" FAILED!' % name)
|
2016-06-01 21:16:13 +00:00
|
|
|
print('--- output')
|
|
|
|
print('+++ reference')
|
2016-07-06 03:43:52 +00:00
|
|
|
print(''.join(difflib.ndiff(output.splitlines(True),
|
|
|
|
reference.splitlines(True))))
|
2015-07-05 18:05:44 +00:00
|
|
|
exit(-1)
|