test_api_tutorial.py 4.4 KB

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