You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB

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