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

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

Issue 2338273006: [Findit] Factoring out the components, so they can classify themselves (Closed)
Patch Set: rebasing to remove dependency on crrev.com/2344443005 Created 4 years, 3 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
« no previous file with comments | « appengine/findit/crash/findit_for_chromecrash.py ('k') | appengine/findit/model/crash/crash_config.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/crash/test/component_classifier_test.py
diff --git a/appengine/findit/crash/test/component_classifier_test.py b/appengine/findit/crash/test/component_classifier_test.py
index 3578931ed5183ed9807ad2fb908aca1a643c07ed..b84cdd835e22aaa588d636af6edb790ce01ed18e 100644
--- a/appengine/findit/crash/test/component_classifier_test.py
+++ b/appengine/findit/crash/test/component_classifier_test.py
@@ -4,47 +4,67 @@
from common.pipeline_wrapper import pipeline_handlers
from crash.callstack import StackFrame, CallStack
+from crash.component import Component
from crash.component_classifier import ComponentClassifier
from crash.results import Result
from crash.test.crash_testcase import CrashTestCase
from model.crash.crash_config import CrashConfig
+# N.B., the call to Get() in CrashConfigComponentClassifier.__init__
+# must only be executed from within the testFoo methods of
+# ComponentClassifierTest. That is, we can't just do this once and for all
+# when doing ComponentClassifierTest.__init__, because that'll cause some
+# strange issues in mocking. But factoring it out like this so it gets
+# (re)called ever time a testFoo is run, that works.
+class CrashConfigComponentClassifier(ComponentClassifier):
+ """A ComponentClassifier which gets its components from CrashConfig."""
+ def __init__(self):
+ config = CrashConfig.Get().component_classifier
+ super(CrashConfigComponentClassifier, self).__init__(
+ [Component(name, path, function)
+ for path, function, name
+ in config.get('path_function_component', [])],
+ config.get('top_n', 0))
+
+
class ComponentClassifierTest(CrashTestCase):
def testGetClassFromStackFrame(self):
frame = StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2])
self.assertEqual(
- ComponentClassifier().GetClassFromStackFrame(frame),
+ CrashConfigComponentClassifier().GetClassFromStackFrame(frame),
'Comp1>Dummy')
frame = StackFrame(0, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [32])
self.assertEqual(
- ComponentClassifier().GetClassFromStackFrame(frame),
+ CrashConfigComponentClassifier().GetClassFromStackFrame(frame),
'Comp2>Dummy')
frame = StackFrame(0, 'src/', 'no_func', 'comp2.cc', 'src/comp2.cc', [32])
self.assertEqual(
- ComponentClassifier().GetClassFromStackFrame(frame),
+ CrashConfigComponentClassifier().GetClassFromStackFrame(frame),
'')
frame = StackFrame(0, 'src/', 'func2', 'a.cc', 'src/a.cc', [6])
self.assertEqual(
- ComponentClassifier().GetClassFromStackFrame(frame),
+ CrashConfigComponentClassifier().GetClassFromStackFrame(frame),
'')
def testGetClassFromResult(self):
result = Result(self.GetDummyChangeLog(), 'src/')
- self.assertEqual(ComponentClassifier().GetClassFromResult(result),
- '')
+ self.assertEqual(
+ CrashConfigComponentClassifier().GetClassFromResult(result),
+ '')
result.file_to_stack_infos = {
'comp1.cc': [
(StackFrame(0, 'src/', 'func', 'comp1.cc', 'src/comp1.cc', [2]), 0)
]
}
- self.assertEqual(ComponentClassifier().GetClassFromResult(result),
- 'Comp1>Dummy')
+ self.assertEqual(
+ CrashConfigComponentClassifier().GetClassFromResult(result),
+ 'Comp1>Dummy')
def testClassifyCrashStack(self):
crash_stack = CallStack(0)
@@ -54,7 +74,7 @@ class ComponentClassifierTest(CrashTestCase):
StackFrame(2, 'src/', 'func2', 'comp2.cc', 'src/comp2.cc', [8])
])
- self.assertEqual(ComponentClassifier().Classify([], crash_stack),
+ self.assertEqual(CrashConfigComponentClassifier().Classify([], crash_stack),
['Comp1>Dummy', 'Comp2>Dummy'])
def testClassifyResults(self):
@@ -65,8 +85,9 @@ class ComponentClassifierTest(CrashTestCase):
]
}
- self.assertEqual(ComponentClassifier().Classify([result], CallStack(0)),
- ['Comp1>Dummy'])
+ self.assertEqual(
+ CrashConfigComponentClassifier().Classify([result], CallStack(0)),
+ ['Comp1>Dummy'])
def testClassifierDoNotHaveConfig(self):
crash_config = CrashConfig.Get()
@@ -86,5 +107,6 @@ class ComponentClassifierTest(CrashTestCase):
]
}
- self.assertEqual(ComponentClassifier().Classify([result], crash_stack),
- [])
+ self.assertEqual(
+ CrashConfigComponentClassifier().Classify([result], crash_stack),
+ [])
« no previous file with comments | « appengine/findit/crash/findit_for_chromecrash.py ('k') | appengine/findit/model/crash/crash_config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698