Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: scripts/slave/unittests/runtest_test.py

Issue 545803002: Update buildbots to parse new telemetry JSON format. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Added unit tests and removed debugging code Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for functions in runtest.py.""" 6 """Unit tests for functions in runtest.py."""
7 7
8 import unittest 8 import unittest
9 9
10 import test_env # pylint: disable=W0403,W0611 10 import test_env # pylint: disable=W0403,W0611
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 @mock.patch('slave.runtest._GetDataFromLogProcessor') 126 @mock.patch('slave.runtest._GetDataFromLogProcessor')
127 @mock.patch('slave.results_dashboard.MakeListOfPoints') 127 @mock.patch('slave.results_dashboard.MakeListOfPoints')
128 @mock.patch('slave.results_dashboard.SendResults') 128 @mock.patch('slave.results_dashboard.SendResults')
129 def test_SendResultsToDashboard_SimpleCase( 129 def test_SendResultsToDashboard_SimpleCase(
130 self, SendResults, MakeListOfPoints, GetDataFromLogProcessor): 130 self, SendResults, MakeListOfPoints, GetDataFromLogProcessor):
131 """Tests that the right methods get called in _SendResultsToDashboard.""" 131 """Tests that the right methods get called in _SendResultsToDashboard."""
132 # Since this method just tests that certain methods get called when 132 # Since this method just tests that certain methods get called when
133 # a call to _SendResultsDashboard is made, the data used below is arbitrary. 133 # a call to _SendResultsDashboard is made, the data used below is arbitrary.
134 fake_charts_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}} 134 fake_charts_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}}
135 fake_points_data = [{'test': 'master/bot/chart/x', 'revision': 1000}] 135 fake_points_data = [{'test': 'master/bot/chart/x', 'revision': 1000}]
136 fake_results_tracker = object() 136 fake_results_tracker = mock.Mock()
137 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=False)
137 GetDataFromLogProcessor.return_value = fake_charts_data 138 GetDataFromLogProcessor.return_value = fake_charts_data
138 MakeListOfPoints.return_value = fake_points_data 139 MakeListOfPoints.return_value = fake_points_data
139 140
140 runtest._SendResultsToDashboard( 141 runtest._SendResultsToDashboard(
141 fake_results_tracker, 'linux', 'sunspider', 'http://x.com', 'builddir', 142 fake_results_tracker, {
142 'my.master', 'Builder', 123, 'columns_file', extra_columns={}) 143 'system': 'linux',
144 'test': 'sunspider',
145 'url': 'http://x.com',
146 'build_dir': 'builddir',
147 'mastername': 'my.master',
148 'buildername': 'Builder',
149 'buildnumber': 123,
150 'supplemental_columns': {}})
143 151
144 # First a function is called to get data from the log processor. 152 # First a function is called to get data from the log processor.
145 GetDataFromLogProcessor.assert_called_with(fake_results_tracker) 153 GetDataFromLogProcessor.assert_called_with(fake_results_tracker)
146 154
147 # Then the data is re-formatted to a format that the dashboard accepts. 155 # Then the data is re-formatted to a format that the dashboard accepts.
148 MakeListOfPoints.assert_called_with( 156 MakeListOfPoints.assert_called_with(
149 fake_charts_data, 'linux', 'sunspider', 'my.master', 'Builder', 123, {}) 157 fake_charts_data, 'linux', 'sunspider', 'my.master', 'Builder', 123, {})
150 158
151 # Then a function is called to send the data (and any cached data). 159 # Then a function is called to send the data (and any cached data).
152 SendResults.assert_called_with( 160 SendResults.assert_called_with(
153 fake_points_data, 'http://x.com', 'builddir') 161 fake_points_data, 'http://x.com', 'builddir')
154 162
163 @mock.patch('slave.results_dashboard.MakeDashboardJsonV1')
164 @mock.patch('slave.results_dashboard.SendResults')
165 def test_SendResultsToDashboard_Telemetry(
166 self, SendResults, MakeDashboardJsonV1):
167 """Tests that the right methods get called in _SendResultsToDashboard."""
168 # Since this method just tests that certain methods get called when
169 # a call to _SendResultsDashboard is made, the data used below is arbitrary.
170 fake_json_data = {'chart': {'traces': {'x': [1, 0]}, 'rev': 1000}}
171 fake_ref_data = {'test': 'master/bot/chart/x', 'revision': 1000}
172 fake_results_tracker = mock.Mock()
173 fake_results_tracker.IsChartJson = mock.MagicMock(return_value=True)
174 fake_results_tracker.ChartJson = mock.MagicMock(return_value=fake_json_data)
175 fake_results_tracker.RefJson = mock.MagicMock(return_value=fake_ref_data)
176 fake_results_tracker.Cleanup = mock.MagicMock()
177 MakeDashboardJsonV1.return_value = {'doesnt': 'matter'}
178
179 runtest._SendResultsToDashboard(
180 fake_results_tracker, {
181 'system': 'linux',
182 'test': 'sunspider',
183 'url': 'http://x.com',
184 'build_dir': 'builddir',
185 'mastername': 'my.master',
186 'buildername': 'Builder',
187 'buildnumber': 123,
188 'revisions': {'rev': 343},
189 'supplemental_columns': {}})
190
191 # Then the data is re-formatted to a format that the dashboard accepts.
192 MakeDashboardJsonV1.assert_has_calls([
193 mock.call(fake_json_data, {'rev': 343}, 'linux',
194 'my.master', 'Builder', 123, {}, False),
195 mock.call(fake_ref_data, {'rev': 343}, 'linux',
196 'my.master', 'Builder', 123, {}, True)])
197
198 # Then a function is called to send the data (and any cached data).
199 SendResults.assert_has_calls([
200 mock.call({'doesnt': 'matter'}, 'http://x.com', 'builddir'),
201 mock.call({'doesnt': 'matter'}, 'http://x.com', 'builddir')])
202
155 203
156 if __name__ == '__main__': 204 if __name__ == '__main__':
157 unittest.main() 205 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698