OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 import glob | 6 import glob |
7 import json | 7 import json |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 '=======', | 263 '=======', |
264 ' ScopedTempDir temp_dir_;', | 264 ' ScopedTempDir temp_dir_;', |
265 '>>>>>>> master'] | 265 '>>>>>>> master'] |
266 errors = PRESUBMIT._CheckForVersionControlConflictsInFile( | 266 errors = PRESUBMIT._CheckForVersionControlConflictsInFile( |
267 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) | 267 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
268 self.assertEqual(3, len(errors)) | 268 self.assertEqual(3, len(errors)) |
269 self.assertTrue('1' in errors[0]) | 269 self.assertTrue('1' in errors[0]) |
270 self.assertTrue('3' in errors[1]) | 270 self.assertTrue('3' in errors[1]) |
271 self.assertTrue('5' in errors[2]) | 271 self.assertTrue('5' in errors[2]) |
272 | 272 |
| 273 class UmaHistogramChangeMatchedOrNotTest(unittest.TestCase): |
| 274 def testTypicalCorrectlyMatchedChange(self): |
| 275 diff_cc = ['UMA_HISTOGRAM_BOOL("Bla.Foo.Dummy", true)'] |
| 276 diff_xml = ['<histogram name="Bla.Foo.Dummy"> </histogram>'] |
| 277 mock_input_api = MockInputApi() |
| 278 mock_input_api.files = [ |
| 279 MockFile('some/path/foo.cc', diff_cc), |
| 280 MockFile('tools/metrics/histograms/histograms.xml', diff_xml), |
| 281 ] |
| 282 warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api, |
| 283 MockOutputApi()) |
| 284 self.assertEqual(0, len(warnings)) |
| 285 |
| 286 def testTypicalNotMatchedChange(self): |
| 287 diff_cc = ['UMA_HISTOGRAM_BOOL("Bla.Foo.Dummy", true)'] |
| 288 mock_input_api = MockInputApi() |
| 289 mock_input_api.files = [MockFile('some/path/foo.cc', diff_cc)] |
| 290 warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api, |
| 291 MockOutputApi()) |
| 292 self.assertEqual(1, len(warnings)) |
| 293 self.assertEqual('warning', warnings[0].type) |
| 294 |
| 295 def testTypicalNotMatchedChangeViaSuffixes(self): |
| 296 diff_cc = ['UMA_HISTOGRAM_BOOL("Bla.Foo.Dummy", true)'] |
| 297 diff_xml = ['<histogram_suffixes name="SuperHistogram">', |
| 298 ' <suffix name="Dummy"/>', |
| 299 ' <affected-histogram name="Snafu.Dummy"/>', |
| 300 '</histogram>'] |
| 301 mock_input_api = MockInputApi() |
| 302 mock_input_api.files = [ |
| 303 MockFile('some/path/foo.cc', diff_cc), |
| 304 MockFile('tools/metrics/histograms/histograms.xml', diff_xml), |
| 305 ] |
| 306 warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api, |
| 307 MockOutputApi()) |
| 308 self.assertEqual(1, len(warnings)) |
| 309 self.assertEqual('warning', warnings[0].type) |
| 310 |
| 311 def testTypicalCorrectlyMatchedChangeViaSuffixes(self): |
| 312 diff_cc = ['UMA_HISTOGRAM_BOOL("Bla.Foo.Dummy", true)'] |
| 313 diff_xml = ['<histogram_suffixes name="SuperHistogram">', |
| 314 ' <suffix name="Dummy"/>', |
| 315 ' <affected-histogram name="Bla.Foo"/>', |
| 316 '</histogram>'] |
| 317 mock_input_api = MockInputApi() |
| 318 mock_input_api.files = [ |
| 319 MockFile('some/path/foo.cc', diff_cc), |
| 320 MockFile('tools/metrics/histograms/histograms.xml', diff_xml), |
| 321 ] |
| 322 warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api, |
| 323 MockOutputApi()) |
| 324 self.assertEqual(0, len(warnings)) |
| 325 |
| 326 def testTypicalCorrectlyMatchedChangeViaSuffixesWithSeparator(self): |
| 327 diff_cc = ['UMA_HISTOGRAM_BOOL("Snafu_Dummy", true)'] |
| 328 diff_xml = ['<histogram_suffixes name="SuperHistogram" separator="_">', |
| 329 ' <suffix name="Dummy"/>', |
| 330 ' <affected-histogram name="Snafu"/>', |
| 331 '</histogram>'] |
| 332 mock_input_api = MockInputApi() |
| 333 mock_input_api.files = [ |
| 334 MockFile('some/path/foo.cc', diff_cc), |
| 335 MockFile('tools/metrics/histograms/histograms.xml', diff_xml), |
| 336 ] |
| 337 warnings = PRESUBMIT._CheckUmaHistogramChanges(mock_input_api, |
| 338 MockOutputApi()) |
| 339 self.assertEqual(0, len(warnings)) |
273 | 340 |
274 class BadExtensionsTest(unittest.TestCase): | 341 class BadExtensionsTest(unittest.TestCase): |
275 def testBadRejFile(self): | 342 def testBadRejFile(self): |
276 mock_input_api = MockInputApi() | 343 mock_input_api = MockInputApi() |
277 mock_input_api.files = [ | 344 mock_input_api.files = [ |
278 MockFile('some/path/foo.cc', ''), | 345 MockFile('some/path/foo.cc', ''), |
279 MockFile('some/path/foo.cc.rej', ''), | 346 MockFile('some/path/foo.cc.rej', ''), |
280 MockFile('some/path2/bar.h.rej', ''), | 347 MockFile('some/path2/bar.h.rej', ''), |
281 ] | 348 ] |
282 | 349 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 } | 757 } |
691 for master, bots in bots.iteritems(): | 758 for master, bots in bots.iteritems(): |
692 for bot in bots: | 759 for bot in bots: |
693 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), | 760 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), |
694 'bot=%s: expected %s, computed %s' % ( | 761 'bot=%s: expected %s, computed %s' % ( |
695 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) | 762 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) |
696 | 763 |
697 | 764 |
698 if __name__ == '__main__': | 765 if __name__ == '__main__': |
699 unittest.main() | 766 unittest.main() |
OLD | NEW |