RunTests.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. # Contest Management System - http://cms-dev.github.io/
  3. # Copyright © 2013-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. import os
  18. import sys
  19. from cmstestsuite import TestException, sh
  20. UNITTESTS = "unittests"
  21. FUNCTIONALTESTS = "functionaltests"
  22. TESTS = set([UNITTESTS, FUNCTIONALTESTS])
  23. def get_test_suite():
  24. """Return the test suite to run based on the env variable
  25. return (string): either "functionaltests" or "unittests" or an
  26. empty string to mean "run both".
  27. """
  28. test_suite = ""
  29. if "TEST_SUITE" in os.environ:
  30. test_suite = os.environ["TEST_SUITE"]
  31. if test_suite in TESTS:
  32. return test_suite
  33. else:
  34. return ""
  35. def main():
  36. test_suite = get_test_suite()
  37. try:
  38. if test_suite == UNITTESTS or len(test_suite) == 0:
  39. sh(["./cmstestsuite/RunUnitTests.py"] + sys.argv[1:])
  40. if test_suite == FUNCTIONALTESTS or len(test_suite) == 0:
  41. sh(["./cmstestsuite/RunFunctionalTests.py"] + sys.argv[1:])
  42. except TestException:
  43. if os.path.exists("./log/cms/last.log"):
  44. print("\n\n===== START OF LOG DUMP =====\n\n")
  45. with open("./log/cms/last.log", "rt", encoding="utf-8") as f:
  46. print(f.read())
  47. print("\n\n===== END OF LOG DUMP =====\n\n")
  48. return 1
  49. return 0
  50. if __name__ == "__main__":
  51. sys.exit(main())