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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: appengine/findit/crash/test/findit_test.py
diff --git a/appengine/findit/crash/test/findit_test.py b/appengine/findit/crash/test/findit_test.py
index 7bce7a299bfb4dc7ad21484fbb1493c281e287a0..781965b25319ea942b3437beac11b9601a80c90e 100644
--- a/appengine/findit/crash/test/findit_test.py
+++ b/appengine/findit/crash/test/findit_test.py
@@ -5,6 +5,8 @@
import copy
import logging
+from google.appengine.api import app_identity
+
from crash.findit import Findit
from crash.type_enums import CrashClient
from crash.test.crash_pipeline_test import DummyCrashData
@@ -31,17 +33,29 @@ class UnsupportedClient(Findit): # pylint: disable=W0223
self._client_id = client_id
+class MockFindit(Findit): # pylint: disable = W
+ """Overwrite abstract method of Findit for testing."""
+
+ def __init__(self):
+ super(MockFindit, self).__init__(MOCK_REPOSITORY)
+
+ @classmethod
+ def _ClientID(cls):
+ return CrashClient.FRACAS
+
+ def ProcessResultForPublishing(self, result, key):
+ return result
+
+
class FinditTest(CrashTestCase):
- def testPlatformRename(self):
- class _MockFindit(Findit): # pylint: disable=W0223
- @classmethod
- def _ClientID(cls):
- return CrashClient.FRACAS
+ def setUp(self):
+ super(FinditTest, self).setUp()
+ self.findit = MockFindit()
+ def testPlatformRename(self):
self.assertEqual(
- _MockFindit(MOCK_REPOSITORY).RenamePlatform('linux'),
- 'unix')
+ self.findit.RenamePlatform('linux'), 'unix')
def testCheckPolicyUnsupportedClient(self):
self.assertIsNone(UnsupportedClient().CheckPolicy(DummyCrashData(
@@ -65,3 +79,51 @@ class FinditTest(CrashTestCase):
UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers),
'Unsupported client unexpectedly got analysis %s via identifiers %s'
% (analysis, crash_identifiers))
+
+ def testGetPublishableResultFoundTrue(self):
+ analysis_result = {
+ 'found': True,
+ 'suspected_cls': [
+ {'confidence': 0.21434,
+ 'reason': ['reason1', 'reason2'],
+ 'other': 'data'}
+ ],
+ 'other_data': 'data',
+ }
+
+ processed_analysis_result = copy.deepcopy(analysis_result)
+ for cl in processed_analysis_result['suspected_cls']:
+ cl['confidence'] = round(cl['confidence'], 2)
+ cl.pop('reason', None)
+
+ crash_identifiers = {'signature': 'sig'}
+ expected_processed_result = {
+ 'crash_identifiers': crash_identifiers,
+ 'client_id': self.findit.client_id,
+ 'result': processed_analysis_result,
+ }
+
+ analysis = FracasCrashAnalysis.Create(crash_identifiers)
+ analysis.result = analysis_result
+
+ self.assertDictEqual(self.findit.GetPublishableResult(crash_identifiers,
+ analysis),
+ expected_processed_result)
+
+ def testGetPublishableResultFoundFalse(self):
+ analysis_result = {
+ 'found': False,
+ }
+ crash_identifiers = {'signature': 'sig'}
+ expected_processed_result = {
+ 'crash_identifiers': crash_identifiers,
+ 'client_id': self.findit.client_id,
+ 'result': copy.deepcopy(analysis_result),
+ }
+
+ analysis = FracasCrashAnalysis.Create(crash_identifiers)
+ analysis.result = analysis_result
+
+ self.assertDictEqual(self.findit.GetPublishableResult(crash_identifiers,
+ analysis),
+ expected_processed_result)
« 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