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

Side by Side Diff: appengine/findit/crash/test/findit_test.py

Issue 2523343002: [Predator] Refactor ToPublishResult and fix keyerror 'found' (Closed)
Patch Set: Rebase. Created 4 years 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 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 copy 5 import copy
6 import logging 6 import logging
7 7
8 from google.appengine.api import app_identity
9
8 from crash.findit import Findit 10 from crash.findit import Findit
9 from crash.type_enums import CrashClient 11 from crash.type_enums import CrashClient
10 from crash.test.crash_pipeline_test import DummyCrashData 12 from crash.test.crash_pipeline_test import DummyCrashData
11 from crash.test.crash_testcase import CrashTestCase 13 from crash.test.crash_testcase import CrashTestCase
12 from model.crash.fracas_crash_analysis import FracasCrashAnalysis 14 from model.crash.fracas_crash_analysis import FracasCrashAnalysis
13 15
14 MOCK_REPOSITORY = None 16 MOCK_REPOSITORY = None
15 17
16 class UnsupportedClient(Findit): # pylint: disable=W0223 18 class UnsupportedClient(Findit): # pylint: disable=W0223
17 # TODO(http://crbug.com/659346): this isn't being called for some reason. 19 # TODO(http://crbug.com/659346): this isn't being called for some reason.
18 @property 20 @property
19 def client_id(self): # pragma: no cover 21 def client_id(self): # pragma: no cover
20 return self._client_id 22 return self._client_id
21 23
22 @property 24 @property
23 def config(self): # pragma: no cover 25 def config(self): # pragma: no cover
24 """Don't return None, so that PlatformRename doesn't crash.""" 26 """Don't return None, so that PlatformRename doesn't crash."""
25 return {} 27 return {}
26 28
27 def __init__(self, client_id=None): 29 def __init__(self, client_id=None):
28 super(UnsupportedClient, self).__init__(MOCK_REPOSITORY) 30 super(UnsupportedClient, self).__init__(MOCK_REPOSITORY)
29 if client_id is None: 31 if client_id is None:
30 client_id = 'unsupported_client' 32 client_id = 'unsupported_client'
31 self._client_id = client_id 33 self._client_id = client_id
32 34
33 35
36 class MockFindit(Findit): # pylint: disable = W
37 """Overwrite abstract method of Findit for testing."""
38
39 def __init__(self):
40 super(MockFindit, self).__init__(MOCK_REPOSITORY)
41
42 @classmethod
43 def _ClientID(cls):
44 return CrashClient.FRACAS
45
46 def ProcessResultForPublishing(self, result, key):
47 return result
48
49
34 class FinditTest(CrashTestCase): 50 class FinditTest(CrashTestCase):
35 51
52 def setUp(self):
53 super(FinditTest, self).setUp()
54 self.findit = MockFindit()
55
36 def testPlatformRename(self): 56 def testPlatformRename(self):
37 class _MockFindit(Findit): # pylint: disable=W0223
38 @classmethod
39 def _ClientID(cls):
40 return CrashClient.FRACAS
41
42 self.assertEqual( 57 self.assertEqual(
43 _MockFindit(MOCK_REPOSITORY).RenamePlatform('linux'), 58 self.findit.RenamePlatform('linux'), 'unix')
44 'unix')
45 59
46 def testCheckPolicyUnsupportedClient(self): 60 def testCheckPolicyUnsupportedClient(self):
47 self.assertIsNone(UnsupportedClient().CheckPolicy(DummyCrashData( 61 self.assertIsNone(UnsupportedClient().CheckPolicy(DummyCrashData(
48 platform = 'canary', 62 platform = 'canary',
49 signature = 'sig', 63 signature = 'sig',
50 ))) 64 )))
51 65
52 def testCreateAnalysisForUnsupportedClientId(self): 66 def testCreateAnalysisForUnsupportedClientId(self):
53 self.assertIsNone(UnsupportedClient('unsupported_id').CreateAnalysis( 67 self.assertIsNone(UnsupportedClient('unsupported_id').CreateAnalysis(
54 {'signature': 'sig'})) 68 {'signature': 'sig'}))
55 69
56 def testGetAnalysisForUnsuportedClient(self): 70 def testGetAnalysisForUnsuportedClient(self):
57 crash_identifiers = {'signature': 'sig'} 71 crash_identifiers = {'signature': 'sig'}
58 # TODO(wrengr): it'd be less fragile to call FinditForFracas.CreateAnalysis 72 # TODO(wrengr): it'd be less fragile to call FinditForFracas.CreateAnalysis
59 # instead. But then we'd need to make UnsupportedClient inherit that 73 # instead. But then we'd need to make UnsupportedClient inherit that
60 # implementation, rather than inheriting the one from the Findit 74 # implementation, rather than inheriting the one from the Findit
61 # base class. 75 # base class.
62 analysis = FracasCrashAnalysis.Create(crash_identifiers) 76 analysis = FracasCrashAnalysis.Create(crash_identifiers)
63 analysis.put() 77 analysis.put()
64 self.assertIsNone( 78 self.assertIsNone(
65 UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers), 79 UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers),
66 'Unsupported client unexpectedly got analysis %s via identifiers %s' 80 'Unsupported client unexpectedly got analysis %s via identifiers %s'
67 % (analysis, crash_identifiers)) 81 % (analysis, crash_identifiers))
82
83 def testGetPublishableResultFoundTrue(self):
84 analysis_result = {
85 'found': True,
86 'suspected_cls': [
87 {'confidence': 0.21434,
88 'reason': ['reason1', 'reason2'],
89 'other': 'data'}
90 ],
91 'other_data': 'data',
92 }
93
94 processed_analysis_result = copy.deepcopy(analysis_result)
95 for cl in processed_analysis_result['suspected_cls']:
96 cl['confidence'] = round(cl['confidence'], 2)
97 cl.pop('reason', None)
98
99 crash_identifiers = {'signature': 'sig'}
100 expected_processed_result = {
101 'crash_identifiers': crash_identifiers,
102 'client_id': self.findit.client_id,
103 'result': processed_analysis_result,
104 }
105
106 analysis = FracasCrashAnalysis.Create(crash_identifiers)
107 analysis.result = analysis_result
108
109 self.assertDictEqual(self.findit.GetPublishableResult(crash_identifiers,
110 analysis),
111 expected_processed_result)
112
113 def testGetPublishableResultFoundFalse(self):
114 analysis_result = {
115 'found': False,
116 }
117 crash_identifiers = {'signature': 'sig'}
118 expected_processed_result = {
119 'crash_identifiers': crash_identifiers,
120 'client_id': self.findit.client_id,
121 'result': copy.deepcopy(analysis_result),
122 }
123
124 analysis = FracasCrashAnalysis.Create(crash_identifiers)
125 analysis.result = analysis_result
126
127 self.assertDictEqual(self.findit.GetPublishableResult(crash_identifiers,
128 analysis),
129 expected_processed_result)
OLDNEW
« no previous file with comments | « appengine/findit/crash/test/findit_for_chromecrash_test.py ('k') | appengine/findit/model/crash/crash_analysis.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698