test.py 2.7 KB

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