test_api_tutorial.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 unittest
  8. import os
  9. import tests.common
  10. class Test(tests.common.TestCase):
  11. def setUp(self):
  12. tests.common.TestCase.setUp(self)
  13. self.METRIXPLUSPLUS_PATH = None
  14. if 'METRIXPLUSPLUS_PATH' in list(os.environ.keys()):
  15. self.METRIXPLUSPLUS_PATH = os.environ['METRIXPLUSPLUS_PATH']
  16. def tearDown(self):
  17. if self.METRIXPLUSPLUS_PATH != None:
  18. os.environ['METRIXPLUSPLUS_PATH'] = self.METRIXPLUSPLUS_PATH
  19. else:
  20. del os.environ['METRIXPLUSPLUS_PATH']
  21. tests.common.TestCase.tearDown(self)
  22. def test_metric_plugin_api(self):
  23. #
  24. # WARNING:
  25. # files generated by this test are used by project documents page
  26. # so, if the test is changed, html docs should be updated accordingly
  27. #
  28. for step in range(9):
  29. opts = ['--log-level=INFO']
  30. if step > 1:
  31. opts.append('--myext.magic.numbers')
  32. if step > 7:
  33. opts.append('--myext.magic.numbers.simplier')
  34. os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
  35. 'test_api_tutorial', 'ext', 'step' + str(step))
  36. runner = tests.common.ToolRunner('collect',
  37. opts,
  38. prefix='step' + str(step),
  39. check_stderr=[(0, -1)])
  40. self.assertExec(runner.run())
  41. if step < 4:
  42. continue
  43. runner = tests.common.ToolRunner('view',
  44. ['--log-level=INFO'],
  45. prefix='step' + str(step),
  46. check_stderr=[(0, -1)])
  47. self.assertExec(runner.run())
  48. def test_runable_plugin_api(self):
  49. #
  50. # WARNING:
  51. # files generated by this test are used by project documents page
  52. # so, if the test is changed, html docs should be updated accordingly
  53. #
  54. runner = tests.common.ToolRunner('collect',
  55. ['--std.code.lines.total',
  56. '--log-level=INFO'],
  57. check_stderr=[(0, -1)],
  58. save_prev=True)
  59. self.assertExec(runner.run())
  60. runner = tests.common.ToolRunner('collect',
  61. ['--std.code.lines.total',
  62. '--log-level=INFO'],
  63. check_stderr=[(0, -1)],
  64. prefix='second',
  65. cwd="sources_changed",
  66. use_prev=True)
  67. self.assertExec(runner.run())
  68. for step in range(3):
  69. step = step + 1
  70. os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
  71. 'test_api_tutorial', 'ext', 'compare_step' + str(step))
  72. runner = tests.common.ToolRunner('compare',
  73. ['--log-level=INFO'],
  74. prefix='step' + str(step),
  75. check_stderr=[(0, -1)],
  76. use_prev=True)
  77. self.assertExec(runner.run())
  78. if __name__ == '__main__':
  79. unittest.main()