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

run.py 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # Copyright (c) Alibaba, Inc. and its affiliates.
  3. import argparse
  4. import os
  5. import sys
  6. import unittest
  7. from fnmatch import fnmatch
  8. def gather_test_cases(test_dir, pattern, list_tests):
  9. case_list = []
  10. for dirpath, dirnames, filenames in os.walk(test_dir):
  11. for file in filenames:
  12. if fnmatch(file, pattern):
  13. case_list.append(file)
  14. test_suite = unittest.TestSuite()
  15. for case in case_list:
  16. test_case = unittest.defaultTestLoader.discover(
  17. start_dir=test_dir, pattern=case)
  18. test_suite.addTest(test_case)
  19. if hasattr(test_case, '__iter__'):
  20. for subcase in test_case:
  21. if list_tests:
  22. print(subcase)
  23. else:
  24. if list_tests:
  25. print(test_case)
  26. return test_suite
  27. def main(args):
  28. runner = unittest.TextTestRunner()
  29. test_suite = gather_test_cases(
  30. os.path.abspath(args.test_dir), args.pattern, args.list_tests)
  31. if not args.list_tests:
  32. result = runner.run(test_suite)
  33. if len(result.failures) > 0:
  34. sys.exit(1)
  35. if __name__ == '__main__':
  36. parser = argparse.ArgumentParser('test runner')
  37. parser.add_argument(
  38. '--list_tests', action='store_true', help='list all tests')
  39. parser.add_argument(
  40. '--pattern', default='test_*.py', help='test file pattern')
  41. parser.add_argument(
  42. '--test_dir', default='tests', help='directory to be tested')
  43. args = parser.parse_args()
  44. main(args)

致力于通过开放的社区合作,开源AI模型以及相关创新技术,推动基于模型即服务的生态繁荣发展