test.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 subprocess
  20. import os.path
  21. import itertools
  22. import core.log
  23. import core.cmdparser
  24. import core.api
  25. class Tool(core.api.ITool):
  26. def run(self, tool_args):
  27. return main(tool_args)
  28. def main(tool_args):
  29. exit_code = 0
  30. log_plugin = core.log.Plugin()
  31. parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog test [options] -- [testgroup-dir-path-1[/testsuite-file-path-1]] ... [...path-N]")
  32. log_plugin.declare_configuration(parser, default_value='ERROR')
  33. parser.add_option("-g", "--general.generate-golds", action="store_true", default=False,
  34. help="If the option is set (True), new gold files are generated (replacing existing) [default: %default]")
  35. (options, args) = parser.parse_args(tool_args)
  36. log_plugin.configure(options)
  37. os.environ['METRIXPLUSPLUS_TEST_GENERATE_GOLDS'] = str(options.__dict__['general.generate_golds'])
  38. tests_dir = os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'tests')
  39. process_data= ["python", "-m", "unittest", "discover", "-v", "-s"]
  40. if len(args) == 0 or tests_dir == os.path.abspath(args[0]):
  41. for fname in os.listdir(tests_dir):
  42. full_path = os.path.join(tests_dir, fname)
  43. if os.path.isdir(full_path) and fname != "sources":
  44. exit_code += subprocess.call(itertools.chain(process_data, [full_path]),
  45. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  46. else:
  47. for arg in args:
  48. if os.path.isdir(arg):
  49. exit_code += subprocess.call(itertools.chain(process_data, [arg]),
  50. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  51. else:
  52. dir_name = os.path.dirname(arg)
  53. file_name = os.path.basename(arg)
  54. exit_code += subprocess.call(itertools.chain(process_data, [dir_name, "-p", file_name]),
  55. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  56. return exit_code