def testCallOneSuspect(self, mock_generate_suspects, mock_rank_suspects): """Tests that ``__call__`` returns immediately when there's one suspect.""" suspect = Suspect(DUMMY_CHANGELOG1, 'src/') mock_generate_suspects.return_value = [suspect] suspects = self.changelist_classifier(DUMMY_REPORT) expected_suspects = [suspect.ToDict()] self.assertListEqual([suspect.ToDict() for suspect in suspects], expected_suspects) self.assertFalse(mock_rank_suspects.called)
def testSuspectToDict(self): suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1, reasons=['MinDistance', 0.5, 'some reason'], changed_files={ 'file': 'f', 'blame_url': 'http://b', 'info': 'min distance (LOC) 5' }) expected_suspect_json = { 'url': DUMMY_CHANGELOG1.commit_url, 'review_url': DUMMY_CHANGELOG1.code_review_url, 'revision': DUMMY_CHANGELOG1.revision, 'project_path': 'src/', 'author': DUMMY_CHANGELOG1.author.email, 'time': str(DUMMY_CHANGELOG1.author.time), 'reasons': ['MinDistance', 0.5, 'some reason'], 'changed_files': { 'file': 'f', 'blame_url': 'http://b', 'info': 'min distance (LOC) 5' }, 'confidence': 1, 'description': 'dummy', } self.assertDictEqual(suspect.ToDict(), expected_suspect_json)
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 testCallFindsSuspects(self): """Tests that ``__call__`` method finds suspects.""" suspect1 = Suspect(DUMMY_CHANGELOG1, 'src/') suspect2 = Suspect(DUMMY_CHANGELOG2, 'src/') self.mock(self.changelist_classifier, 'GenerateSuspects', lambda *_: [suspect1, suspect2]) self.mock(self.changelist_classifier, 'RankSuspects', 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 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 testSuspectToString(self): suspect = Suspect(DUMMY_CHANGELOG1, 'src/', confidence=1) self.assertEqual(suspect.ToString(), str(suspect.ToDict())) self.assertEqual(str(suspect), str(suspect.ToDict()))