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

Unified Diff: appengine/findit/crash/loglinear/test/feature_test.py

Issue 2625073003: [Predator] Add MetaWeight and MetaFeatureValue to group multiple weights and features together. (Closed)
Patch Set: Rebase. Created 3 years, 11 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/loglinear/test/feature_test.py
diff --git a/appengine/findit/crash/loglinear/test/feature_test.py b/appengine/findit/crash/loglinear/test/feature_test.py
index 75536e9e49c2273c63af664968e74f8749fb6b18..1d341806a8d42b21b8227adef3ad4b524497083e 100644
--- a/appengine/findit/crash/loglinear/test/feature_test.py
+++ b/appengine/findit/crash/loglinear/test/feature_test.py
@@ -2,9 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import copy
import unittest
from crash.loglinear import feature
+from crash.loglinear.feature import ChangedFile
+from crash.loglinear.feature import MetaFeatureValue
+from crash.loglinear.test.loglinear_testcase import Feature0
+from crash.loglinear.test.loglinear_testcase import Feature1
+from crash.loglinear.test.loglinear_testcase import Feature2
+from crash.loglinear.test.loglinear_testcase import Feature3
+from crash.loglinear.test.loglinear_testcase import Feature4
from crash.loglinear.test.loglinear_testcase import LoglinearTestCase
import libs.math.logarithms as lmath
@@ -41,11 +49,69 @@ class ChangelistFeatureTest(unittest.TestCase):
self.assertEqual(lmath.LOG_ZERO, feature.LogLinearlyScaled(42., 10.))
-class FeatureFunctionTest(LoglinearTestCase):
+class MetaFeatureValueTest(unittest.TestCase):
- def testFeatureFunction(self):
- """Test that ``FeatureFunction`` obeys the equality its docstring says."""
+ def setUp(self):
+ super(MetaFeatureValueTest, self).setUp()
+ self.feature = MetaFeatureValue(
+ 'dummy', {feature.name: feature(3)(False)
+ for feature in [Feature0(), Feature1()]})
+
+ def testEqaul(self):
+ """Tests overriding ``__eq__`` and ``__ne__``."""
+ copy_meta_feature = copy.deepcopy(self.feature)
+ self.assertTrue(self.feature == copy_meta_feature)
+ copy_meta_feature._name = 'dummy2'
+ self.assertTrue(self.feature != copy_meta_feature)
+
+ def testLen(self):
+ """Tests overriding ``__len__``."""
+ self.assertEqual(len(self.feature), 2)
+
+ def testFormatReasons(self):
+ """Tests ``FormatReasons`` returnes a list of formated reasons."""
+ self.assertEqual(self.feature.reason,
+ 'Feature0: 1.000000 -- reason0\n'
+ 'Feature1: 0.000000 -- reason1')
+ self.assertEqual(self.feature.reason, self.feature._reason)
+
+ def testAggregateChangedFilesAggregates(self):
+ """Test that ``AggregateChangedFiles`` does aggregate reasons per file.
+
+ In the main/inner loop of ``AggregateChangedFiles``: if multiple
+ features all blame the same file change, we try to aggregate those
+ reasons so that we only report the file once (with all reasons). None
+ of the other tests here actually check the case where the same file
+ is blamed multiple times, so we check that here.
+
+ In particular, we provide the same ``FeatureValue`` twice, and
+ hence the same ``ChangedFile`` twice; so we should get back a single
+ ``ChangedFile`` but with the ``reasons`` fields concatenated.
+ """
+ self.assertListEqual(self.feature.changed_files,
+ [ChangedFile(name='a.cc',
+ blame_url=None,
+ reasons=['file_reason0']),
+ ChangedFile(name='b.cc',
+ blame_url=None,
+ reasons=['file_reason0',
+ 'file_reason1'])])
+ self.assertEqual(self.feature.changed_files,
+ self.feature._changed_files)
+
+
+class WrapperMetaFeatureTest(LoglinearTestCase):
+
+ def testWrapperMetaFeatureWrapsIndependentFeatures(self):
for x in self._X:
for y in self._Y(x):
- for f in self._feature_list:
- self.assertEqual(f(x)(y), self._feature_function(x)(y)[f.name])
+ self.assertTrue(
+ self._meta_feature(x)(y) ==
+ MetaFeatureValue('WrapperFeature',
+ {'Feature0': Feature0()(x)(y),
+ 'Feature1': Feature1()(x)(y),
+ 'Feature2': Feature2()(x)(y),
+ 'WrapperFeature': MetaFeatureValue(
+ 'WrapperFeature',
+ {'Feature3': Feature3()(x)(y),
+ 'Feature4': Feature4()(x)(y)})}))

Powered by Google App Engine
This is Rietveld 408576698