test_api_tutorial.py 4.5 KB

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