Chromium Code Reviews| 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 import mock | 5 import mock |
| 6 | 6 |
| 7 from dashboard.common import namespaced_stored_object | 7 from dashboard.common import namespaced_stored_object |
| 8 from dashboard.common import testing_common | 8 from dashboard.common import testing_common |
| 9 from dashboard.pinpoint.models.change import commit | 9 from dashboard.pinpoint.models.change import commit |
| 10 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 110 |
| 111 | 111 |
| 112 class MidpointTest(_CommitTest): | 112 class MidpointTest(_CommitTest): |
| 113 | 113 |
| 114 @mock.patch('dashboard.services.gitiles_service.CommitRange') | 114 @mock.patch('dashboard.services.gitiles_service.CommitRange') |
| 115 def testSuccess(self, commit_range): | 115 def testSuccess(self, commit_range): |
| 116 commit_range.return_value = [ | 116 commit_range.return_value = [ |
| 117 {'commit': 'babe852'}, | 117 {'commit': 'babe852'}, |
| 118 {'commit': 'b57345e'}, | 118 {'commit': 'b57345e'}, |
| 119 {'commit': '949b36d'}, | 119 {'commit': '949b36d'}, |
| 120 {'commit': '1ef4789'}, | 120 {'commit': '1ef4789'}, |
|
perezju
2017/09/19 15:58:05
these are a bit hard to think about, can you repla
| |
| 121 ] | 121 ] |
| 122 | 122 |
| 123 commit_a = commit.Commit('chromium', '0e57e2b') | 123 commit_a = commit.Commit('chromium', '0e57e2b') |
| 124 commit_b = commit.Commit('chromium', 'babe852') | 124 commit_b = commit.Commit('chromium', 'babe852') |
| 125 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), | 125 expected = commit.Commit('chromium', '949b36d'), (2, 2) |
| 126 commit.Commit('chromium', '949b36d')) | 126 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), expected) |
| 127 | 127 |
|
perezju
2017/09/19 15:58:05
Can you also add a success test with an even numbe
| |
| 128 def testSameCommit(self): | 128 def testSameCommit(self): |
| 129 commit_a = commit.Commit('chromium', '0e57e2b') | 129 commit_a = commit.Commit('chromium', '0e57e2b') |
| 130 commit_b = commit.Commit('chromium', '0e57e2b') | 130 commit_b = commit.Commit('chromium', '0e57e2b') |
| 131 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), commit_a) | 131 expected = commit_a, (0, 0) |
| 132 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), expected) | |
| 132 | 133 |
| 133 @mock.patch('dashboard.services.gitiles_service.CommitRange') | 134 @mock.patch('dashboard.services.gitiles_service.CommitRange') |
| 134 def testAdjacentCommits(self, commit_range): | 135 def testAdjacentCommits(self, commit_range): |
| 135 commit_range.return_value = [{'commit': 'b57345e'}] | 136 commit_range.return_value = [{'commit': 'b57345e'}] |
| 136 | 137 |
| 137 commit_a = commit.Commit('chromium', '949b36d') | 138 commit_a = commit.Commit('chromium', '949b36d') |
| 138 commit_b = commit.Commit('chromium', 'b57345e') | 139 commit_b = commit.Commit('chromium', 'b57345e') |
| 139 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), commit_a) | 140 expected = commit_a, (0, 1) |
| 141 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), expected) | |
| 140 | 142 |
| 141 def testRaisesWithDifferingRepositories(self): | 143 def testRaisesWithDifferingRepositories(self): |
| 142 commit_a = commit.Commit('chromium', '0e57e2b') | 144 commit_a = commit.Commit('chromium', '0e57e2b') |
| 143 commit_b = commit.Commit('not_chromium', 'babe852') | 145 commit_b = commit.Commit('not_chromium', 'babe852') |
| 144 with self.assertRaises(commit.NonLinearError): | 146 with self.assertRaises(commit.NonLinearError): |
| 145 commit.Commit.Midpoint(commit_a, commit_b) | 147 commit.Commit.Midpoint(commit_a, commit_b) |
| 146 | 148 |
| 147 @mock.patch('dashboard.services.gitiles_service.CommitRange') | 149 @mock.patch('dashboard.services.gitiles_service.CommitRange') |
| 148 def testRaisesWithEmptyRange(self, commit_range): | 150 def testRaisesWithEmptyRange(self, commit_range): |
| 149 commit_range.return_value = [] | 151 commit_range.return_value = [] |
| 150 | 152 |
| 151 commit_b = commit.Commit('chromium', 'b57345e') | 153 commit_b = commit.Commit('chromium', 'b57345e') |
| 152 commit_a = commit.Commit('chromium', '949b36d') | 154 commit_a = commit.Commit('chromium', '949b36d') |
| 153 with self.assertRaises(commit.NonLinearError): | 155 with self.assertRaises(commit.NonLinearError): |
| 154 commit.Commit.Midpoint(commit_a, commit_b) | 156 commit.Commit.Midpoint(commit_a, commit_b) |
| OLD | NEW |