Conditions | 1 |
Total Lines | 126 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # coding: utf8 |
||
114 | @patch('crash.utils.crash_sender') |
||
115 | @test.override_settings(HOST_NAME='example.com', |
||
116 | CELERY_EAGER_PROPAGATES_EXCEPTIONS=False,) |
||
117 | @is_private(False) |
||
118 | def test_send_stacktrace(self, mock_client): |
||
119 | meta = dict( |
||
120 | lang='en', |
||
121 | version='1.0.0.1', |
||
122 | ) |
||
123 | crash = Crash( |
||
124 | pk=123, |
||
125 | upload_file_minidump=SimpleUploadedFile('./dump.dat', False), |
||
126 | stacktrace=stacktrace, |
||
127 | stacktrace_json=parse_stacktrace(stacktrace), |
||
128 | appid='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', |
||
129 | userid='{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}', |
||
130 | meta=meta, |
||
131 | signature='signature', |
||
132 | ) |
||
133 | |||
134 | send_stacktrace(crash) |
||
135 | |||
136 | extra = { |
||
137 | 'crash_admin_panel_url': 'http://{}{}'.format( |
||
138 | 'example.com', |
||
139 | '/admin/crash/crash/%s/' % crash.pk), |
||
140 | 'crashdump_url': crash.upload_file_minidump.url, |
||
141 | 'lang': 'en', |
||
142 | 'version': '1.0.0.1'} |
||
143 | |||
144 | data = { |
||
145 | 'sentry.interfaces.User': { |
||
146 | 'id': '{2882CF9B-D9C2-4edb-9AAF-8ED5FCF366F7}' |
||
147 | }, |
||
148 | 'sentry.interfaces.Exception': { |
||
149 | 'values': [ |
||
150 | {'stacktrace': { |
||
151 | 'frames': [ |
||
152 | {'function': 'crashedFunc()', |
||
153 | 'abs_path': r'c:\work\breakpadtestapp\breakpadtestapp\breakpadtestapp.cpp', |
||
154 | 'short_signature': 'crashedFunc', |
||
155 | 'frame': 0, |
||
156 | 'filename': 'BreakpadTestApp.exe', |
||
157 | 'lineno': 34, |
||
158 | 'signature': 'crashedFunc()'}, |
||
159 | {'function': 'deeperFunc()', |
||
160 | 'abs_path': r'c:\work\breakpadtestapp\breakpadtestapp\breakpadtestapp.cpp', |
||
161 | 'short_signature': 'deeperFunc', |
||
162 | 'frame': 1, |
||
163 | 'filename': 'BreakpadTestApp.exe', |
||
164 | 'lineno': 39, |
||
165 | 'signature': 'deeperFunc()'}, |
||
166 | {'function': 'deepFunc()', |
||
167 | 'abs_path': r'c:\work\breakpadtestapp\breakpadtestapp\breakpadtestapp.cpp', |
||
168 | 'short_signature': 'deepFunc', |
||
169 | 'frame': 2, |
||
170 | 'filename': 'BreakpadTestApp.exe', |
||
171 | 'lineno': 44, |
||
172 | 'signature': 'deepFunc()'}, |
||
173 | {'function': 'anotherFunc()', |
||
174 | 'abs_path': r'c:\work\breakpadtestapp\breakpadtestapp\breakpadtestapp.cpp', |
||
175 | 'short_signature': 'anotherFunc', |
||
176 | 'frame': 3, |
||
177 | 'filename': 'BreakpadTestApp.exe', |
||
178 | 'lineno': 49, |
||
179 | 'signature': 'anotherFunc()'}, |
||
180 | {'function': 'someFunc()', |
||
181 | 'abs_path': r'c:\work\breakpadtestapp\breakpadtestapp\breakpadtestapp.cpp', |
||
182 | 'short_signature': 'someFunc', |
||
183 | 'frame': 4, |
||
184 | 'filename': 'BreakpadTestApp.exe', |
||
185 | 'lineno': 54, |
||
186 | 'signature': 'someFunc()'}, { |
||
187 | 'function': 'func()', |
||
188 | 'abs_path': r'c:\work\breakpadtestapp\breakpadtestapp\breakpadtestapp.cpp', |
||
189 | 'short_signature': 'func', |
||
190 | 'frame': 5, |
||
191 | 'filename': 'BreakpadTestApp.exe', |
||
192 | 'lineno': 59, |
||
193 | 'signature': 'func()'}, |
||
194 | {'function': 'wmain', |
||
195 | 'abs_path': r'c:\work\breakpadtestapp\breakpadtestapp\breakpadtestapp.cpp', |
||
196 | 'short_signature': 'wmain', |
||
197 | 'frame': 6, |
||
198 | 'filename': 'BreakpadTestApp.exe', |
||
199 | 'lineno': 84, |
||
200 | 'signature': 'wmain'}, { |
||
201 | 'function': '__tmainCRTStartup', |
||
202 | 'abs_path': r'f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c', |
||
203 | 'short_signature': '__tmainCRTStartup', |
||
204 | 'frame': 7, |
||
205 | 'filename': 'BreakpadTestApp.exe', |
||
206 | 'lineno': 579, |
||
207 | 'signature': '__tmainCRTStartup'}, |
||
208 | {'frame': 8, |
||
209 | 'module_offset': '0x13676', |
||
210 | 'signature': 'kernel32.dll@0x13676', |
||
211 | 'short_signature': 'kernel32.dll@0x13676', |
||
212 | 'filename': 'kernel32.dll'}, |
||
213 | {'frame': 9, |
||
214 | 'module_offset': '0x39d41', |
||
215 | 'signature': 'ntdll.dll@0x39d41', |
||
216 | 'short_signature': 'ntdll.dll@0x39d41', |
||
217 | 'filename': 'ntdll.dll'}], |
||
218 | 'total_frames': 11, 'threads_index': 0}, |
||
219 | 'type': 'EXCEPTION_ACCESS_VIOLATION_WRITE', |
||
220 | 'value': '0x0'} |
||
221 | ] |
||
222 | } |
||
223 | } |
||
224 | |||
225 | tags = { |
||
226 | 'cpu_arch': 'x86', |
||
227 | 'cpu_count': 4, |
||
228 | 'appid': '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', |
||
229 | 'cpu_info': 'GenuineIntel family 6 model 42 stepping 7', |
||
230 | 'os': 'Windows NT', |
||
231 | 'os_ver': '6.1.7600' |
||
232 | } |
||
233 | |||
234 | mock_client.send.assert_called_once_with( |
||
235 | 'signature', |
||
236 | extra=extra, |
||
237 | sentry_data=data, |
||
238 | tags=tags, |
||
239 | crash_obj=crash |
||
240 | ) |
||
297 | os = 'Mac OS X' |