resulttooltests.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import os
  2. import sys
  3. basepath = os.path.abspath(os.path.dirname(__file__) + '/../../../../../')
  4. lib_path = basepath + '/scripts/lib'
  5. sys.path = sys.path + [lib_path]
  6. from resulttool.report import ResultsTextReport
  7. from resulttool.regression import ResultsRegressionSelector, ResultsRegression
  8. from resulttool.merge import ResultsMerge
  9. from resulttool.store import ResultsGitStore
  10. from resulttool.resultsutils import checkout_git_dir
  11. from oeqa.selftest.case import OESelftestTestCase
  12. class ResultToolTests(OESelftestTestCase):
  13. def test_report_can_aggregate_test_result(self):
  14. result_data = {'result': {'test1': {'status': 'PASSED'},
  15. 'test2': {'status': 'PASSED'},
  16. 'test3': {'status': 'FAILED'},
  17. 'test4': {'status': 'ERROR'},
  18. 'test5': {'status': 'SKIPPED'}}}
  19. report = ResultsTextReport()
  20. result_report = report.get_aggregated_test_result(None, result_data)
  21. self.assertTrue(result_report['passed'] == 2, msg="Passed count not correct:%s" % result_report['passed'])
  22. self.assertTrue(result_report['failed'] == 2, msg="Failed count not correct:%s" % result_report['failed'])
  23. self.assertTrue(result_report['skipped'] == 1, msg="Skipped count not correct:%s" % result_report['skipped'])
  24. def test_regression_can_get_regression_base_target_pair(self):
  25. base_results_data = {'base_result1': {'configuration': {"TEST_TYPE": "oeselftest",
  26. "HOST": "centos-7"}},
  27. 'base_result2': {'configuration': {"TEST_TYPE": "oeselftest",
  28. "HOST": "centos-7",
  29. "MACHINE": "qemux86-64"}}}
  30. target_results_data = {'target_result1': {'configuration': {"TEST_TYPE": "oeselftest",
  31. "HOST": "centos-7"}},
  32. 'target_result2': {'configuration': {"TEST_TYPE": "oeselftest",
  33. "HOST": "centos-7",
  34. "MACHINE": "qemux86"}},
  35. 'target_result3': {'configuration': {"TEST_TYPE": "oeselftest",
  36. "HOST": "centos-7",
  37. "MACHINE": "qemux86-64"}}}
  38. regression = ResultsRegressionSelector()
  39. pair = regression.get_regression_base_target_pair(self.logger, base_results_data, target_results_data)
  40. self.assertTrue('target_result1' in pair['base_result1'], msg="Pair not correct:%s" % pair['base_result1'])
  41. self.assertTrue('target_result3' in pair['base_result2'], msg="Pair not correct:%s" % pair['base_result2'])
  42. def test_regrresion_can_get_regression_result(self):
  43. base_result_data = {'result': {'test1': {'status': 'PASSED'},
  44. 'test2': {'status': 'PASSED'},
  45. 'test3': {'status': 'FAILED'},
  46. 'test4': {'status': 'ERROR'},
  47. 'test5': {'status': 'SKIPPED'}}}
  48. target_result_data = {'result': {'test1': {'status': 'PASSED'},
  49. 'test2': {'status': 'FAILED'},
  50. 'test3': {'status': 'PASSED'},
  51. 'test4': {'status': 'ERROR'},
  52. 'test5': {'status': 'SKIPPED'}}}
  53. regression = ResultsRegression()
  54. result = regression.get_regression_result(self.logger, base_result_data, target_result_data)
  55. self.assertTrue(result['test2']['base'] == 'PASSED',
  56. msg="regression not correct:%s" % result['test2']['base'])
  57. self.assertTrue(result['test2']['target'] == 'FAILED',
  58. msg="regression not correct:%s" % result['test2']['target'])
  59. self.assertTrue(result['test3']['base'] == 'FAILED',
  60. msg="regression not correct:%s" % result['test3']['base'])
  61. self.assertTrue(result['test3']['target'] == 'PASSED',
  62. msg="regression not correct:%s" % result['test3']['target'])
  63. def test_merge_can_merged_results(self):
  64. base_results_data = {'base_result1': {},
  65. 'base_result2': {}}
  66. target_results_data = {'target_result1': {},
  67. 'target_result2': {},
  68. 'target_result3': {}}
  69. merge = ResultsMerge()
  70. results = merge.merge_results(base_results_data, target_results_data)
  71. self.assertTrue(len(results.keys()) == 5, msg="merge not correct:%s" % len(results.keys()))
  72. def test_store_can_store_to_new_git_repository(self):
  73. basepath = os.path.abspath(os.path.dirname(__file__) + '/../../')
  74. source_dir = basepath + '/files/testresults'
  75. git_branch = 'qa-cycle-2.7'
  76. store = ResultsGitStore()
  77. output_dir = store.store_to_new(self.logger, source_dir, git_branch)
  78. self.assertTrue(checkout_git_dir(output_dir, git_branch), msg="store to new git repository failed:%s" %
  79. output_dir)
  80. store._remove_temporary_workspace_dir(output_dir)
  81. def test_store_can_store_to_existing(self):
  82. basepath = os.path.abspath(os.path.dirname(__file__) + '/../../')
  83. source_dir = basepath + '/files/testresults'
  84. git_branch = 'qa-cycle-2.6'
  85. store = ResultsGitStore()
  86. output_dir = store.store_to_new(self.logger, source_dir, git_branch)
  87. self.assertTrue(checkout_git_dir(output_dir, git_branch), msg="store to new git repository failed:%s" %
  88. output_dir)
  89. git_branch = 'qa-cycle-2.7'
  90. output_dir = store.store_to_existing_with_new_branch(self.logger, source_dir, output_dir, git_branch)
  91. self.assertTrue(checkout_git_dir(output_dir, git_branch), msg="store to existing git repository failed:%s" %
  92. output_dir)
  93. output_dir = store.store_to_existing(self.logger, source_dir, output_dir, git_branch)
  94. self.assertTrue(checkout_git_dir(output_dir, git_branch), msg="store to existing git repository failed:%s" %
  95. output_dir)
  96. store._remove_temporary_workspace_dir(output_dir)