test.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #
  2. # Metrix++, Copyright 2009-2019, Metrix++ Project
  3. # Link: https://github.com/metrixplusplus/metrixplusplus
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. import mpp.api
  8. import subprocess
  9. import os.path
  10. import itertools
  11. import sys
  12. class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.IRunable):
  13. def declare_configuration(self, parser):
  14. parser.add_option("-g", "--generate-golds", "--gg", action="store_true", default=False,
  15. help="If the option is set (True), new gold files are generated (replacing existing) [default: %default]")
  16. def configure(self, options):
  17. self.generate_golds = options.__dict__['generate_golds']
  18. def run(self, args):
  19. exit_code = 0
  20. os.environ['METRIXPLUSPLUS_TEST_GENERATE_GOLDS'] = str(self.generate_golds)
  21. os.environ['METRIXPLUSPLUS_TEST_MODE'] = str("True")
  22. tests_dir = os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'tests')
  23. process_data= [sys.executable, "-m", "unittest", "discover", "-v", "-s"]
  24. if len(args) == 0 or tests_dir == os.path.abspath(args[0]):
  25. for fname in sorted(os.listdir(tests_dir)):
  26. full_path = os.path.join(tests_dir, fname)
  27. if os.path.isdir(full_path) and fname != "sources":
  28. exit_code += subprocess.call(itertools.chain(process_data, [full_path]),
  29. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  30. else:
  31. for arg in args:
  32. if os.path.isdir(arg):
  33. exit_code += subprocess.call(itertools.chain(process_data, [arg]),
  34. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  35. else:
  36. dir_name = os.path.dirname(arg)
  37. file_name = os.path.basename(arg)
  38. exit_code += subprocess.call(itertools.chain(process_data, [dir_name, "-p", file_name]),
  39. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  40. return exit_code