def testMultiply(self): """Tests overloading operators ``__mul__`` and ``__rmul__``""" self.assertEqual( MetaWeight({ 'f1': Weight(0.8), 'f2': Weight(0.4) }) * MetaFeatureValue('f', { 'f1': 2., 'f2': 1. }), 2.) self.assertEqual( MetaFeatureValue('f', { 'f1': 0.8, 'f2': 0.4 }) * MetaWeight({ 'f1': Weight(2.), 'f2': Weight(1.) }), 2.) self.assertEqual( MetaWeight({ 'f1': Weight(0.8), 'f3': Weight(0.0) }) * MetaFeatureValue('f', { 'f1': Weight(2.), 'f2': Weight(9), 'f3': Weight(10) }), 1.6)
def testWrapperMetaFeatureWrapsIndependentFeatures(self): for x in self._X: for y in self._Y(x): 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)})}))
def testFormatReasons(self): """Tests ``FormatReasons`` returnes a list of formated reasons.""" feature0 = Feature0() feature1 = Feature1() feature2 = Feature2() meta_feature = MetaFeatureValue( 'dummy', {feature0.name: feature0(1)(False), 'meta': MetaFeatureValue( 'meta', {feature1.name: feature1(2)(True), feature2.name: feature2(3)(True)})}) self.assertEqual(meta_feature.reason, {'Feature0': 'reason0', 'Feature1': 'reason1', 'Feature2': 'reason2'}) self.assertEqual(meta_feature.reason, meta_feature._reason)
def testRankSuspects(self): """Tests ``RankSuspects`` method.""" self.changelist_classifier._model.Features = mock.Mock( return_value=lambda _: MetaFeatureValue('dummy', {})) suspect = Suspect(DUMMY_CHANGELOG1, 'src/') self.changelist_classifier._model.Score = mock.Mock( return_value=lambda _: 1.0) suspects = self.changelist_classifier.RankSuspects( DUMMY_REPORT, [suspect]) self.assertEqual(suspects[0].ToDict(), suspect.ToDict())
def testRankSuspectsAllLogZeros(self): """Tests ``RankSuspects`` method.""" self.mock(self.changelist_classifier._model, 'Features', lambda _: lambda _: MetaFeatureValue('dummy', {})) suspect1 = Suspect(DUMMY_CHANGELOG1, 'src/') suspect2 = Suspect(DUMMY_CHANGELOG2, 'src/') self.mock(self.changelist_classifier._model, 'Score', lambda _: lambda _: lmath.LOG_ZERO) suspects = self.changelist_classifier.RankSuspects( DUMMY_REPORT, [suspect1, suspect2]) self.assertEqual(suspects, [])
def FeatureValueGivenReport(suspect): """Function mapping suspect related data to its FeatureValue. Args: suspect (Suspect): The suspected changelog and some meta information about it. touched_file_to_stack_infos(dict): Dict mapping ``FileChangeInfo`` to a list of ``StackInfo``s representing all the frames that the suspect touched. Returns: The ``FeatureValue`` of this feature. """ grouped_frame_infos = dep_to_grouped_frame_infos.get(suspect.dep_path, {}) matches = crash_util.MatchSuspectWithFrameInfos(suspect, grouped_frame_infos, self.Match) return MetaFeatureValue( self.name, {name: fx(suspect, matches) for name, fx in features_given_report.iteritems()})
def setUp(self): super(MetaFeatureValueTest, self).setUp() self.feature = MetaFeatureValue( 'dummy', {feature.name: feature(3)(False) for feature in [Feature0(), Feature1(), Feature3()]})