test.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://metrixplusplus.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import logging
  20. import time
  21. import subprocess
  22. import os.path
  23. import itertools
  24. import core.log
  25. import core.cmdparser
  26. def main():
  27. exit_code = 0
  28. log_plugin = core.log.Plugin()
  29. parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- [testgroup-dir-path-1[/testsuite-file-path-1]] ... [...path-N]")
  30. log_plugin.declare_configuration(parser, default_value='ERROR')
  31. (options, args) = parser.parse_args()
  32. log_plugin.configure(options)
  33. install_dir = os.path.dirname(os.path.abspath(__file__))
  34. tests_dir = os.path.join(install_dir, 'tests')
  35. os.environ['METRIXPLUSPLUS_INSTALL_DIR'] = install_dir
  36. process_data= ["python", "-m", "unittest", "discover", "-v", "-s"]
  37. if len(args) == 0 or tests_dir == os.path.abspath(args[0]):
  38. for fname in os.listdir(tests_dir):
  39. full_path = os.path.join(tests_dir, fname)
  40. if os.path.isdir(full_path):
  41. exit_code += subprocess.call(itertools.chain(process_data, [full_path]))
  42. else:
  43. for arg in args:
  44. if os.path.isdir(arg):
  45. exit_code += subprocess.call(itertools.chain(process_data, [arg]))
  46. else:
  47. dir_name = os.path.dirname(arg)
  48. file_name = os.path.basename(arg)
  49. exit_code += subprocess.call(itertools.chain(process_data, [dir_name, "-p", file_name]))
  50. return exit_code
  51. if __name__ == '__main__':
  52. ts = time.time()
  53. core.log.set_default_format()
  54. exit_code = main()
  55. logging.warning("Exit code: " + str(exit_code) + ". Time spent: " + str(round((time.time() - ts), 2)) + " seconds. Done")
  56. exit(exit_code) # number of reported messages, errors are reported as non-handled exceptions