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

Unified Diff: appengine/findit/crash/test/findit_for_chromecrash_test.py

Issue 2414523002: [Findit] Reorganizing findit_for_*.py (Closed)
Patch Set: linting for coverage Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: appengine/findit/crash/test/findit_for_chromecrash_test.py
diff --git a/appengine/findit/crash/test/findit_for_chromecrash_test.py b/appengine/findit/crash/test/findit_for_chromecrash_test.py
index 230d0711a311de8ac19c99ed4363d8ab5f9d536a..02e0d6760fea34d9d667062fb1bcdee73a7359a1 100644
--- a/appengine/findit/crash/test/findit_for_chromecrash_test.py
+++ b/appengine/findit/crash/test/findit_for_chromecrash_test.py
@@ -4,94 +4,82 @@
from common import chromium_deps
from common.dependency import DependencyRoll
-from crash import detect_regression_range
-from crash import findit_for_chromecrash
-from crash import chromecrash_parser
-from crash import findit_for_crash
+from crash.changelist_classifier import ChangelistClassifier
+from crash.chromecrash_parser import ChromeCrashParser
from crash.component_classifier import ComponentClassifier
+from crash.crash_pipeline import CrashWrapperPipeline
+from crash.findit_for_chromecrash import FinditForChromeCrash
from crash.project_classifier import ProjectClassifier
from crash.results import MatchResult
from crash.stacktrace import CallStack
from crash.stacktrace import Stacktrace
from crash.test.crash_testcase import CrashTestCase
+from model.crash.crash_analysis import CrashAnalysis
+def _FinditForChromeCrash():
+ return FinditForChromeCrash(CrashWrapperPipeline)
class FinditForChromeCrashTest(CrashTestCase):
def testFindCulpritForChromeCrashEmptyStacktrace(self):
- def _MockGetChromeDependency(*_):
- return {}
-
- def _MockParse(*_):
- return Stacktrace()
-
- self.mock(chromium_deps, 'GetChromeDependency', _MockGetChromeDependency)
- self.mock(chromecrash_parser.ChromeCrashParser, 'Parse', _MockParse)
+ self.mock(chromium_deps, 'GetChromeDependency', lambda *_: {})
+ self.mock(ChromeCrashParser, 'Parse', lambda *_: Stacktrace())
expected_results = {'found': False}
expected_tag = {'found_suspects': False,
'has_regression_range': False}
- results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit(
- 'signature', 'win', 'frame1\nframe2', '50.0.1234.0',
- [{'chrome_version': '50.0.1234.0', 'cpm': 0.6}]).ToDicts()
+ analysis = CrashAnalysis()
+ analysis.signature = 'signature'
+ analysis.platform = 'win'
+ analysis.stack_trace = 'frame1\nframe2'
+ analysis.crashed_version = '50.0.1234.0'
+ analysis.historical_metadata = [
+ {'chrome_version': '51.0.1234.0', 'cpm': 0.6}]
+ results, tag = _FinditForChromeCrash().FindCulprit(analysis).ToDicts()
- self.assertEqual(expected_results, results)
- self.assertEqual(expected_tag, tag)
+ self.assertDictEqual(expected_results, results)
+ self.assertDictEqual(expected_tag, tag)
def testFindCulpritForChromeCrash(self):
- def _MockGetChromeDependency(*_):
- return {}
-
- def _MockParse(*_):
- stack = Stacktrace()
- stack.append(CallStack(0))
- return stack
-
- def _MockGetDEPSRollsDict(*_):
- return {'src/': DependencyRoll('src/', 'https://repo', '1', '2'),
- 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'),
- 'src/delete': DependencyRoll('src/delete', 'https://repo2',
- '2', None)}
+ self.mock(chromium_deps, 'GetChromeDependency', lambda *_: {})
+ self.mock(ChromeCrashParser, 'Parse', lambda *_: Stacktrace([CallStack(0)]))
+ self.mock(chromium_deps, 'GetDEPSRollsDict', lambda *_: {
+ 'src/': DependencyRoll('src/', 'https://repo', '1', '2'),
+ 'src/add': DependencyRoll('src/add', 'https://repo1', None, '2'),
+ 'src/delete': DependencyRoll('src/delete', 'https://repo2', '2', None)
+ })
dummy_match_result = MatchResult(self.GetDummyChangeLog(), 'src/')
- def _MockFindItForCrash(*args):
- regression_deps_rolls = args[1]
- if regression_deps_rolls:
- return [dummy_match_result]
-
- return []
-
- def _MockComponentClassify(*_):
- return []
-
- def _MockProjectClassify(*_):
- return ''
-
- self.mock(chromium_deps, 'GetChromeDependency', _MockGetChromeDependency)
- self.mock(chromecrash_parser.ChromeCrashParser, 'Parse', _MockParse)
- self.mock(chromium_deps, 'GetDEPSRollsDict', _MockGetDEPSRollsDict)
- self.mock(findit_for_crash, 'FindItForCrash', _MockFindItForCrash)
-
- self.mock(ComponentClassifier, 'Classify', _MockComponentClassify)
- self.mock(ProjectClassifier, 'Classify', _MockProjectClassify)
-
- expected_results = {'found': False}
- expected_tag = {'found_suspects': False}
-
- results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit(
- 'signature', 'win', 'frame1\nframe2', '50.0.1234.0',
- ['50.0.1233.0', '50.0.1234.0']).ToDicts()
+ self.mock(ChangelistClassifier, '__call__',
+ lambda _self, report:
+ [dummy_match_result] if report.regression_range else [])
+
+ self.mock(ComponentClassifier, 'Classify', lambda *_: [])
+ self.mock(ProjectClassifier, 'Classify', lambda *_: '')
+
+ # TODO(wrengr): for both these tests, we should compare Culprit
+ # objects directly rather than calling ToDicts and comparing the
+ # dictionaries.
+ self._testFindCulpritForChromeCrashSucceeds(dummy_match_result)
+ self._testFindCulpritForChromeCrashFails()
+
+ def _testFindCulpritForChromeCrashSucceeds(self, dummy_match_result):
+ analysis = CrashAnalysis()
+ analysis.signature = 'signature'
+ analysis.platform = 'win'
+ analysis.stack_trace = 'frame1\nframe2'
+ analysis.crashed_version = '50.0.1234.0'
+ dummy_regression_range = ['50.0.1233.0', '50.0.1234.0']
+ analysis.regression_range = dummy_regression_range
+ results, tag = _FinditForChromeCrash().FindCulprit(analysis).ToDicts()
- # TODO(wrengr): compare the Culprit object directly to these values,
- # rather than converting to dicts first. We can make a different
- # unit test for comparing the dicts, if we actually need/want to.
expected_results = {
'found': True,
'suspected_project': '',
'suspected_components': [],
'suspected_cls': [dummy_match_result.ToDict()],
- 'regression_range': ['50.0.1233.0', '50.0.1234.0']
+ 'regression_range': dummy_regression_range
}
expected_tag = {
'found_suspects': True,
@@ -101,11 +89,18 @@ class FinditForChromeCrashTest(CrashTestCase):
'solution': 'core_algorithm',
}
- self.assertEqual(expected_results, results)
- self.assertEqual(expected_tag, tag)
+ self.assertDictEqual(expected_results, results)
+ self.assertDictEqual(expected_tag, tag)
- results, tag = findit_for_chromecrash.FinditForChromeCrash().FindCulprit(
- 'signature', 'win', 'frame1\nframe2', '50.0.1234.0', None).ToDicts()
+ def _testFindCulpritForChromeCrashFails(self):
+ analysis = CrashAnalysis()
+ analysis.signature = 'signature'
+ analysis.platform = 'win'
+ analysis.stack_trace = 'frame1\nframe2'
+ analysis.crashed_version = '50.0.1234.0'
+ #analysis.historical_metadata = []
+ #analysis.regression_range = None
+ results, tag = _FinditForChromeCrash().FindCulprit(analysis).ToDicts()
expected_results = {
'found': False,
@@ -122,5 +117,5 @@ class FinditForChromeCrashTest(CrashTestCase):
'solution': 'core_algorithm',
}
- self.assertEqual(expected_results, results)
- self.assertEqual(expected_tag, tag)
+ self.assertDictEqual(expected_results, results)
+ self.assertDictEqual(expected_tag, tag)

Powered by Google App Engine
This is Rietveld 408576698