| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from datetime import datetime | 5 from datetime import datetime |
| 6 import mock |
| 7 import unittest |
| 6 | 8 |
| 7 import unittest | 9 from gae_libs.gitiles.cached_gitiles_repository import CachedGitilesRepository |
| 10 from libs.gitiles.change_log import ChangeLog |
| 8 | 11 |
| 9 from model import analysis_status | 12 from model import analysis_status |
| 10 from model import result_status | 13 from model import result_status |
| 11 from model import triage_status | 14 from model import triage_status |
| 12 from model.flake.master_flake_analysis import DataPoint | 15 from model.flake.master_flake_analysis import DataPoint |
| 13 from model.flake.master_flake_analysis import MasterFlakeAnalysis | 16 from model.flake.master_flake_analysis import MasterFlakeAnalysis |
| 14 | 17 |
| 15 | 18 |
| 16 class MasterFlakeAnalysisTest(unittest.TestCase): | 19 class MasterFlakeAnalysisTest(unittest.TestCase): |
| 17 | 20 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 150 |
| 148 key = MasterFlakeAnalysis.Create( | 151 key = MasterFlakeAnalysis.Create( |
| 149 master_name, builder_name, build_number, step_name, test_name).key | 152 master_name, builder_name, build_number, step_name, test_name).key |
| 150 | 153 |
| 151 self.assertEqual( | 154 self.assertEqual( |
| 152 (None, None), | 155 (None, None), |
| 153 MasterFlakeAnalysis.GetBuildConfigurationFromKey(None)) | 156 MasterFlakeAnalysis.GetBuildConfigurationFromKey(None)) |
| 154 self.assertEqual( | 157 self.assertEqual( |
| 155 (master_name, builder_name), | 158 (master_name, builder_name), |
| 156 MasterFlakeAnalysis.GetBuildConfigurationFromKey(key)) | 159 MasterFlakeAnalysis.GetBuildConfigurationFromKey(key)) |
| 160 |
| 161 def testGetSuspectedFlakeDataPointNoSuspectedFlakeBuildNumber(self): |
| 162 analysis = MasterFlakeAnalysis.Create('m', 'b', 123, 's', 't') |
| 163 self.assertIsNone(analysis.GetSuspectedFlakeDataPoint()) |
| 164 |
| 165 def testGetSuspectedFlakeDataPoint(self): |
| 166 expected_build_number = 123 |
| 167 data_point = DataPoint() |
| 168 data_point.build_number = expected_build_number |
| 169 |
| 170 analysis = MasterFlakeAnalysis.Create('m', 'b', 125, 's', 't') |
| 171 analysis.suspected_flake_build_number = expected_build_number |
| 172 analysis.data_points.append(data_point) |
| 173 |
| 174 suspected_data_point = analysis.GetSuspectedFlakeDataPoint() |
| 175 self.assertEqual(expected_build_number, suspected_data_point.build_number) |
| 176 |
| 177 def testGetSuspectedFlakeDataPointNoDatapoint(self): |
| 178 # This scenario should not happen. |
| 179 expected_build_number = 123 |
| 180 unexpected_build_number = 124 |
| 181 data_point = DataPoint() |
| 182 data_point.build_number = expected_build_number |
| 183 |
| 184 analysis = MasterFlakeAnalysis.Create('m', 'b', 125, 's', 't') |
| 185 analysis.suspected_flake_build_number = unexpected_build_number |
| 186 analysis.data_points.append(data_point) |
| 187 |
| 188 self.assertIsNone(analysis.GetSuspectedFlakeDataPoint()) |
| 189 |
| 190 @mock.patch.object(CachedGitilesRepository, 'GetChangeLog') |
| 191 def testUpdateSuspectedCL(self, mocked_module): |
| 192 revision = 'a1b2c3d4' |
| 193 commit_position = 12345 |
| 194 code_review_url = 'url' |
| 195 repo_name = 'repo_name' |
| 196 change_log = ChangeLog(None, None, None, None, None, None, revision, |
| 197 commit_position, None, None, code_review_url, None) |
| 198 mocked_module.return_value = change_log |
| 199 |
| 200 analysis = MasterFlakeAnalysis.Create('m', 'b', 123, 's', 't') |
| 201 analysis.UpdateSuspectedCL(repo_name, revision) |
| 202 |
| 203 self.assertEqual(commit_position, analysis.suspected_cl.commit_position) |
| 204 self.assertEqual(revision, analysis.suspected_cl.revision) |
| 205 self.assertEqual(code_review_url, analysis.suspected_cl.code_review_url) |
| OLD | NEW |