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

Side by Side Diff: appengine/findit/waterfall/test/detect_first_failure_pipeline_test.py

Issue 2203643002: [Findit] Use new mock for unittests. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@0708-pipeline-refactor
Patch Set: rebase Created 4 years, 4 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 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 datetime 5 import datetime
6 import json 6 import json
7 import mock
7 import os 8 import os
8 import urllib 9 import urllib
9 import zlib 10 import zlib
10 11
11 from common.http_client_appengine import HttpClientAppengine as HttpClient 12 from common.http_client_appengine import HttpClientAppengine as HttpClient
12 from common.pipeline_wrapper import pipeline_handlers 13 from common.pipeline_wrapper import pipeline_handlers
13 from common.waterfall import failure_type 14 from common.waterfall import failure_type
14 from model import analysis_status 15 from model import analysis_status
15 from model.wf_analysis import WfAnalysis 16 from model.wf_analysis import WfAnalysis
16 from model.wf_build import WfBuild 17 from model.wf_build import WfBuild
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 'Unittest3.Subtest2': { 318 'Unittest3.Subtest2': {
318 'current_failure': 223, 319 'current_failure': 223,
319 'first_failure': 223, 320 'first_failure': 223,
320 'base_test_name': 'Unittest3.Subtest2' 321 'base_test_name': 'Unittest3.Subtest2'
321 } 322 }
322 } 323 }
323 } 324 }
324 325
325 self.assertEqual(expected_failed_step, failed_step) 326 self.assertEqual(expected_failed_step, failed_step)
326 327
327 def testCheckFirstKnownFailureForSwarmingTestsFoundFlaky(self): 328 @mock.patch.object(detect_first_failure_pipeline, 'swarming_util')
329 def testCheckFirstKnownFailureForSwarmingTestsFoundFlaky(self, mock_module):
328 master_name = 'm' 330 master_name = 'm'
329 builder_name = 'b' 331 builder_name = 'b'
330 build_number = 221 332 build_number = 221
331 step_name = 'abc_test' 333 step_name = 'abc_test'
332 failed_steps = { 334 failed_steps = {
333 'abc_test': { 335 'abc_test': {
334 'current_failure': 221, 336 'current_failure': 221,
335 'first_failure': 221, 337 'first_failure': 221,
336 'list_isolated_data': [ 338 'list_isolated_data': [
337 { 339 {
(...skipping 16 matching lines...) Expand all
354 '223': { 356 '223': {
355 'blame_list': ['commit3', 'commit4'], 357 'blame_list': ['commit3', 'commit4'],
356 'chromium_revision': 'commit4' 358 'chromium_revision': 'commit4'
357 } 359 }
358 } 360 }
359 expected_failed_steps = failed_steps 361 expected_failed_steps = failed_steps
360 step = WfStep.Create(master_name, builder_name, build_number, step_name) 362 step = WfStep.Create(master_name, builder_name, build_number, step_name)
361 step.isolated = True 363 step.isolated = True
362 step.put() 364 step.put()
363 365
364 def MockGetIsolatedDataForFailedBuild(*_): 366 mock_module.GetIsolatedDataForFailedBuild.return_value = True
365 return True 367 mock_module.RetrieveShardedTestResultsFromIsolatedServer.return_value = (
366 self.mock( 368 json.loads(self._GetSwarmingData(
367 swarming_util, 'GetIsolatedDataForFailedBuild', 369 'isolated-plain', 'm_b_223_abc_test_flaky.json')))
368 MockGetIsolatedDataForFailedBuild)
369
370 def MockRetrieveShardedTestResultsFromIsolatedServer(*_):
371 return json.loads(
372 self._GetSwarmingData(
373 'isolated-plain', 'm_b_223_abc_test_flaky.json'))
374 self.mock(
375 swarming_util, 'RetrieveShardedTestResultsFromIsolatedServer',
376 MockRetrieveShardedTestResultsFromIsolatedServer)
377 370
378 pipeline = DetectFirstFailurePipeline() 371 pipeline = DetectFirstFailurePipeline()
379 pipeline._CheckFirstKnownFailureForSwarmingTests( 372 pipeline._CheckFirstKnownFailureForSwarmingTests(
380 master_name, builder_name, build_number, failed_steps, builds) 373 master_name, builder_name, build_number, failed_steps, builds)
381 374
382 self.assertEqual(expected_failed_steps, failed_steps) 375 self.assertEqual(expected_failed_steps, failed_steps)
383 376
384 def testUpdateFirstFailureOnTestLevelThenUpdateStepLevel(self): 377 def testUpdateFirstFailureOnTestLevelThenUpdateStepLevel(self):
385 master_name = 'm' 378 master_name = 'm'
386 builder_name = 'b' 379 builder_name = 'b'
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 'PRE_t': 'PRE_t', 736 'PRE_t': 'PRE_t',
744 'TestSuite1.Test1': 'TestSuite1.Test1', 737 'TestSuite1.Test1': 'TestSuite1.Test1',
745 'TestSuite1.PRE_Test1': 'TestSuite1.Test1', 738 'TestSuite1.PRE_Test1': 'TestSuite1.Test1',
746 'TestSuite1.PRE_PRE_Test1': 'TestSuite1.Test1', 739 'TestSuite1.PRE_PRE_Test1': 'TestSuite1.Test1',
747 'PRE_TestSuite1.Test1': 'PRE_TestSuite1.Test1' 740 'PRE_TestSuite1.Test1': 'PRE_TestSuite1.Test1'
748 } 741 }
749 742
750 for test, expected_base_test in test_smaples.iteritems(): 743 for test, expected_base_test in test_smaples.iteritems():
751 base_test = detect_first_failure_pipeline._RemoveAllPrefixes(test) 744 base_test = detect_first_failure_pipeline._RemoveAllPrefixes(test)
752 self.assertEqual(base_test, expected_base_test) 745 self.assertEqual(base_test, expected_base_test)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698