test.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.IRunable):
  12. def declare_configuration(self, parser):
  13. parser.add_option("-g", "--generate-golds", "--gg", action="store_true", default=False,
  14. help="If the option is set (True), new gold files are generated (replacing existing) [default: %default]")
  15. def configure(self, options):
  16. self.generate_golds = options.__dict__['generate_golds']
  17. def run(self, args):
  18. exit_code = 0
  19. os.environ['METRIXPLUSPLUS_TEST_GENERATE_GOLDS'] = str(self.generate_golds)
  20. os.environ['METRIXPLUSPLUS_TEST_MODE'] = str("True")
  21. tests_dir = os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'tests')
  22. process_data= ["python", "-m", "unittest", "discover", "-v", "-s"]
  23. if len(args) == 0 or tests_dir == os.path.abspath(args[0]):
  24. for fname in os.listdir(tests_dir):
  25. full_path = os.path.join(tests_dir, fname)
  26. if os.path.isdir(full_path) and fname != "sources":
  27. exit_code += subprocess.call(itertools.chain(process_data, [full_path]),
  28. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  29. else:
  30. for arg in args:
  31. if os.path.isdir(arg):
  32. exit_code += subprocess.call(itertools.chain(process_data, [arg]),
  33. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  34. else:
  35. dir_name = os.path.dirname(arg)
  36. file_name = os.path.basename(arg)
  37. exit_code += subprocess.call(itertools.chain(process_data, [dir_name, "-p", file_name]),
  38. cwd=os.environ['METRIXPLUSPLUS_INSTALL_DIR'])
  39. return exit_code