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

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

Issue 2673733002: [Predator] Add CrashData class to process raw json crash data. (Closed)
Patch Set: Rebase and fix nits. Created 3 years, 10 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
« no previous file with comments | « appengine/findit/crash/test/findit_test.py ('k') | appengine/findit/gae_libs/testcase.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 re 6 import re
7 7
8 import gae_ts_mon 8 import gae_ts_mon
9 from google.appengine.api import users 9 from google.appengine.api import users
10 10
11 from crash.crash_data import CrashData
12 from crash.findit import Findit
11 from gae_libs.testcase import TestCase 13 from gae_libs.testcase import TestCase
12 from libs.gitiles.change_log import ChangeLog 14 from libs.gitiles.change_log import ChangeLog
15 from libs.gitiles.gitiles_repository import GitilesRepository
13 from libs.http import retry_http_client 16 from libs.http import retry_http_client
14 from model.crash.crash_config import CrashConfig 17 from model.crash.crash_config import CrashConfig
18 from model.crash.crash_analysis import CrashAnalysis
15 19
16 20
17 DEFAULT_CONFIG_DATA = { 21 DEFAULT_CONFIG_DATA = {
18 'fracas': { 22 'fracas': {
19 'analysis_result_pubsub_topic': 'projects/project-name/topics/name', 23 'analysis_result_pubsub_topic': 'projects/project-name/topics/name',
20 'supported_platform_list_by_channel': { 24 'supported_platform_list_by_channel': {
21 'canary': ['win', 'mac', 'linux'], 25 'canary': ['win', 'mac', 'linux'],
22 'supported_channel': ['supported_platform'], 26 'supported_channel': ['supported_platform'],
23 }, 27 },
24 'platform_rename': {'linux': 'unix'}, 28 'platform_rename': {'linux': 'unix'},
25 'signature_blacklist_markers': ['Blacklist marker'], 29 'signature_blacklist_markers': ['Blacklist marker'],
26 'top_n': 7 30 'top_n': 7
27 }, 31 },
32 'cracas': {
33 'analysis_result_pubsub_topic': 'projects/project-name/topics/name',
34 'supported_platform_list_by_channel': {
35 'canary': ['win', 'mac', 'linux'],
36 'supported_channel': ['supported_platform'],
37 },
38 'platform_rename': {'linux': 'unix'},
39 'signature_blacklist_markers': ['Blacklist marker'],
40 'top_n': 7
41 },
28 'component_classifier': { 42 'component_classifier': {
29 'path_function_component': [ 43 'path_function_component': [
30 [ 44 [
31 'src/comp1.*', 45 'src/comp1.*',
32 '', 46 '',
33 'Comp1>Dummy' 47 'Comp1>Dummy'
34 ], 48 ],
35 [ 49 [
36 'src/comp2.*', 50 'src/comp2.*',
37 'func2.*', 51 'func2.*',
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 ], 89 ],
76 'commit_url': 90 'commit_url':
77 'https://repo.test/+/1', 91 'https://repo.test/+/1',
78 'code_review_url': 'https://codereview.chromium.org/3281', 92 'code_review_url': 'https://codereview.chromium.org/3281',
79 'revision': '1', 93 'revision': '1',
80 'reverted_revision': None 94 'reverted_revision': None
81 }) 95 })
82 96
83 97
84 98
85 class PredatorTestCase(TestCase): # pragma: no cover. 99 class PredatorTestCase(TestCase): # pragma: no cover
86 100
87 def setUp(self): 101 def setUp(self):
88 super(PredatorTestCase, self).setUp() 102 super(PredatorTestCase, self).setUp()
89 CrashConfig.Get().Update( 103 CrashConfig.Get().Update(
90 users.User(email='admin@chromium.org'), True, **DEFAULT_CONFIG_DATA) 104 users.User(email='admin@chromium.org'), True, **DEFAULT_CONFIG_DATA)
91 gae_ts_mon.reset_for_unittest(disable=True) 105 gae_ts_mon.reset_for_unittest(disable=True)
92 106
93 def GetDummyChangeLog(self): 107 def GetDummyChangeLog(self):
94 return DUMMY_CHANGELOG 108 return DUMMY_CHANGELOG
109
110 def GetMockFindit(self, get_repository=None, config=None,
111 client_id='mock_client'):
112 """Gets Mocked ``Findit`` object."""
113 get_repository = (get_repository or
114 GitilesRepository.Factory(self.GetMockHttpClient()))
115 config = config or CrashConfig.Get()
116
117 class MockFindit(Findit): # pylint: disable=W0223
118 """Overwrite abstract method of Findit for testing."""
119 def __init__(self):
120 super(MockFindit, self).__init__(get_repository, config)
121
122 @classmethod
123 def _ClientID(cls):
124 return client_id
125
126 def ProcessResultForPublishing(self, result, key):
127 return result
128
129 def GetAnalysis(self, crash_identifiers):
130 return CrashAnalysis.Get(crash_identifiers)
131
132 def CreateAnalysis(self, crash_identifiers):
133 return CrashAnalysis.Create(crash_identifiers)
134
135 return MockFindit()
136
137 def GetDummyCrashData(self, client_id='mock_client', version='1',
138 signature='signature', platform='win',
139 stack_trace=None, regression_range=None,
140 channel='canary', historical_metadata=None,
141 crash_identifiers=True, process_type='browser'):
142 """Gets Mocked crashed_data sent by clients."""
143 if crash_identifiers is True: # pragma: no cover
144 crash_identifiers = {
145 'chrome_version': version,
146 'signature': signature,
147 'channel': channel,
148 'platform': platform,
149 'process_type': process_type,
150 }
151 crash_data = {
152 'chrome_version': version,
153 'signature': signature,
154 'platform': platform,
155 'stack_trace': stack_trace,
156 'regression_range': regression_range,
157 'crash_identifiers': crash_identifiers,
158 'customized_data': {
159 'historical_metadata': historical_metadata,
160 'channel': channel,
161 },
162 }
163 # This insertion of client_id is used for debugging ScheduleNewAnalysis.
164 if client_id is not None: # pragma: no cover
165 crash_data['client_id'] = client_id
166 return crash_data
OLDNEW
« no previous file with comments | « appengine/findit/crash/test/findit_test.py ('k') | appengine/findit/gae_libs/testcase.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698