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