def testCallFindsSuspects(self, mock_generate_suspects, mock_rank_suspects): """Tests that ``__call__`` method finds suspects.""" suspect1 = Suspect(DUMMY_CHANGELOG1, 'src/') suspect2 = Suspect(DUMMY_CHANGELOG2, 'src/') suspect1.confidence = 2.0 suspect2.confidence = 1.0 mock_generate_suspects.return_value = [suspect1, suspect2] mock_rank_suspects.side_effect = lambda report, suspects: [suspects[0]] suspects = self.changelist_classifier(DUMMY_REPORT) expected_suspects = [suspect1.ToDict()] self.assertListEqual([suspect.ToDict() for suspect in suspects], expected_suspects)
def testFilterLessLikelySuspects(self): """Tests ``FilterLessLikelySuspects`` filter.""" suspect1 = Suspect(self.GetDummyChangeLog(), 'src/') suspect2 = Suspect(self.GetDummyChangeLog(), 'src/') suspect3 = Suspect(self.GetDummyChangeLog(), 'src/') suspect1.confidence = 2 suspect2.confidence = 2 self.assertListEqual( suspect_filters.FilterLessLikelySuspects(0.5)([suspect1, suspect2]), []) suspect2.confidence = 1.8 suspect3.confidence = 1.0 self.assertListEqual( suspect_filters.FilterLessLikelySuspects(0.5)([suspect1, suspect2, suspect3]), [suspect1, suspect2])
def testFilterSuspectWithLessConfidenceThanLowerThreshold(self): """Tests filter suspect if it is with lower confidence than threshold.""" suspect = Suspect(self.GetDummyChangeLog(), 'src/') suspect.confidence = 2 self.assertListEqual( suspect_filters.FilterLessLikelySuspects(0.5, lower_threshold=5)( [suspect]), [])
def testSortAndFilterSuspects(self): """Tests ``SortAndFilterSuspects`` method.""" suspect1 = Suspect(DUMMY_CHANGELOG1, 'src/') suspect2 = Suspect(DUMMY_CHANGELOG1, 'src/') suspect3 = Suspect(DUMMY_CHANGELOG1, 'src/') suspect1.confidence = 2 self.assertListEqual( self.changelist_classifier.SortAndFilterSuspects([suspect1]), [suspect1]) suspect2.confidence = 2 self.assertListEqual( self.changelist_classifier.SortAndFilterSuspects( [suspect1, suspect2]), []) suspect2.confidence = 1.8 suspect3.confidence = 1.0 self.assertListEqual( self.changelist_classifier.SortAndFilterSuspects( [suspect1, suspect2, suspect3]), [suspect1, suspect2])