run_tests.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import os
  2. import sys
  3. import time
  4. def test_file(filepath, cpython=False):
  5. if cpython:
  6. return os.system("python3 " + filepath) == 0
  7. if sys.platform == 'win32':
  8. return os.system("pocketpy.exe " + filepath) == 0
  9. else:
  10. return os.system("./pocketpy " + filepath) == 0
  11. def test_dir(path):
  12. print("Testing directory:", path)
  13. for filename in sorted(os.listdir(path)):
  14. if not filename.endswith('.py'):
  15. continue
  16. filepath = os.path.join(path, filename)
  17. print("> " + filepath, flush=True)
  18. if path == 'benchmarks/':
  19. _0 = time.time()
  20. if not test_file(filepath, cpython=True): exit(1)
  21. _1 = time.time()
  22. if not test_file(filepath): exit(1)
  23. _2 = time.time()
  24. print(f' cpython: {_1 - _0:.6f}s (100%)')
  25. print(f' pocketpy: {_2 - _1:.6f}s ({(_2 - _1) / (_1 - _0) * 100:.2f}%)')
  26. else:
  27. if not test_file(filepath): exit(1)
  28. if len(sys.argv) == 2:
  29. assert 'benchmark' in sys.argv[1]
  30. d = 'benchmarks/'
  31. else:
  32. d = 'tests/'
  33. test_dir(d)
  34. print("ALL TESTS PASSED")