test.py 1000 B

12345678910111213141516171819202122232425262728293031323334353637
  1. test_count = 0
  2. def test(result, expect) -> None:
  3. global test_count
  4. test_count += 1
  5. if result == expect:
  6. print("Test #" + str(test_count) + " SUCCESS.")
  7. return
  8. print("Test #" + str(test_count) + " FAIL.")
  9. print("Expected: \"" + repr(expect) + "\".")
  10. print("Result: \"" + repr(result) + "\".")
  11. print()
  12. exit(1)
  13. def test_error(error, function, *args, **kwargs) -> None:
  14. global test_count
  15. test_count += 1
  16. try:
  17. function(*args, **kwargs)
  18. print("Test #" + str(test_count) + " FAIL.")
  19. print("Function not raise any exception.")
  20. print()
  21. exit(1)
  22. except Exception as catched:
  23. if type(catched) is not error:
  24. print("Test #" + str(test_count) + " FAIL.")
  25. print("Expected: \"" + repr(error) + "\".")
  26. print("Catched: \"" + repr(catched) + "\".")
  27. print()
  28. exit(1)
  29. print("Test #" + str(test_count) + " SUCCESS.")