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.
 
 
 
 
 

60 lines
1.6 KiB

  1. # -*- coding: utf-8; -*-
  2. # test/suite.py
  3. # Part of reportbug, a Debian bug reporting tool.
  4. #
  5. # Copyright © 2008 Ben Finney <ben+python@benfinney.id.au>
  6. # This is free software; you may copy, modify and/or distribute this work
  7. # under the terms of the GNU General Public License, version 2 or later.
  8. # No warranty expressed or implied. See the file COPYING for details.
  9. """ Unit test suite for reportbug
  10. """
  11. import unittest
  12. import sys
  13. import os
  14. def get_python_modules(file_list, file_suffix = '.py'):
  15. """ Return a list of module names from a filename list """
  16. python_modules = [m[:m.rfind(file_suffix)] for m in file_list
  17. if m.endswith(file_suffix)]
  18. return python_modules
  19. def get_test_modules(module_list, module_prefix = 'test_'):
  20. """ Return the list of modules that are named as test modules """
  21. test_modules = [m for m in module_list
  22. if m.startswith(module_prefix)]
  23. return test_modules
  24. def suite():
  25. """ Create the test suite for this module """
  26. loader = unittest.TestLoader()
  27. test_dir = os.path.dirname(__file__)
  28. python_modules = get_python_modules(os.listdir(test_dir))
  29. module_list = get_test_modules(python_modules)
  30. suite = loader.loadTestsFromNames(module_list)
  31. return suite
  32. def __main__(argv=None):
  33. """ Mainline function for this module """
  34. from sys import argv as sys_argv
  35. if not argv:
  36. argv = sys_argv
  37. exitcode = None
  38. try:
  39. unittest.main(argv=argv, defaultTest='suite')
  40. except SystemExit, e:
  41. exitcode = e.code
  42. return exitcode
  43. if __name__ == '__main__':
  44. exitcode = __main__(sys.argv)
  45. sys.exit(exitcode)