test_api_tutorial.py 4.3 KB

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