def testCheckFileSameLineChanged(self):
        def MockGetChangedLines(*_):
            return [1, 3]

        self.mock(build_failure_analysis, '_GetChangedLinesForChromiumRepo',
                  MockGetChangedLines)
        touched_file = FileChangeInfo.FromDict({
            'change_type': ChangeType.MODIFY,
            'old_path': 'a/b/c.cc',
            'new_path': 'a/b/c.cc'
        })
        file_path_in_log = 'a/b/c.cc'
        justification = build_failure_analysis._Justification()
        file_name_occurrences = {'c.cc': 1}
        line_numbers = [1, 3]
        repo_info = {
            'repo_url': 'https://chromium.googlesource.com/chromium/src.git',
            'revision': 'dummy_abcd1234'
        }
        commit_revision = 'dummy_1'
        build_failure_analysis._CheckFile(touched_file, file_path_in_log,
                                          justification, file_name_occurrences,
                                          line_numbers, repo_info,
                                          commit_revision)

        expected_justification = {
            'score': 4,
            'hints': {
                'modified c.cc[1, 3] (and it was in log)': 4
            }
        }
        self.assertEqual(expected_justification, justification.ToDict())
Exemple #2
0
 def testFileChangeinfo(self):
     filechange_dict = {
         'change_type': 'copy',
         'old_path': 'a',
         'new_path': 'b'
     }
     filechange_info = FileChangeInfo.FromDict(filechange_dict)
     self.assertEqual(filechange_dict, filechange_info.ToDict())
  def testCall(self):
    """Tests ``__call__`` method."""
    suspect = Suspect(self.GetDummyChangeLog(), 'src/')

    touched_file = FileChangeInfo.FromDict({'old_path': None,
                                            'new_path': 'a.cc',
                                            'change_type': 'add'})
    suspect.changelog = suspect.changelog._replace(
        touched_files=[touched_file]*15)
    self.assertEqual(self._feature(None)(suspect).value, 0.0)
 def testMatchWhenCrashedDirectryIsEmpty(self):
     """Tests ``Match`` returns False when the crashed directory is empty."""
     self.assertFalse(
         self._feature.Match(
             None,
             FileChangeInfo.FromDict({
                 'change_type': 'add',
                 'new_path': 'p/a.cc',
                 'old_path': None,
             })))
 def testFeatureValueIsOneWhenThereIsMatchedDirectory(self):
     """Test that feature value is 1 when there is matched directory."""
     changelog = self.GetDummyChangeLog()._replace(touched_files=[
         FileChangeInfo.FromDict({
             'change_type': 'add',
             'new_path': 'p/a.cc',
             'old_path': None,
         })
     ])
     suspect = Suspect(changelog, 'src/')
     feature_value = self._feature(self._report)(suspect)
     self.assertEqual(1.0, feature_value.value)
 def testFeatureValueIsZeroWhenAFileIsDeleted(self):
     """Tests that the feature returns 0 when a file is deleted."""
     changelog = self.GetDummyChangeLog()._replace(
         # File deleted in the same directory:
         touched_files=[
             FileChangeInfo.FromDict({
                 'change_type': 'delete',
                 'new_path': None,
                 'old_path': 'p/a.cc',
             })
         ])
     suspect = Suspect(changelog, 'src/')
     feature_value = self._feature(self._report)(suspect)
     self.assertEqual(0.0, feature_value.value)
    def testGetChangedLinesNoneBlame(self):
        repo_info = {
            'repo_url': 'https://chromium.googlesource.com/chromium/src.git',
            'revision': '10'
        }
        touched_file = FileChangeInfo.FromDict({
            'change_type': ChangeType.MODIFY,
            'old_path': 'a/b/c.cc',
            'new_path': 'a/b/c.cc'
        })
        line_numbers = [2, 7, 8]
        commit_revision = '7'
        self.mock(CachedGitilesRepository, 'GetBlame', self._MockGetBlame)
        changed_line_numbers = (
            build_failure_analysis._GetChangedLinesForChromiumRepo(
                repo_info, touched_file, line_numbers, commit_revision))

        self.assertEqual([], changed_line_numbers)
 def testFeatureValueIsOneWhenThereIsMatchedDirectory(self):
     """Test that feature value is 1 when there is matched directory."""
     frame1 = StackFrame(0, 'src/', 'func', 'p/f.cc', 'src/p/f.cc', [2, 3],
                         'h://repo')
     stack = CallStack(0, frame_list=[frame1])
     stack_trace = Stacktrace([stack], stack)
     deps = {'src/': Dependency('src/', 'h://repo', '8')}
     dep_rolls = {'src/': DependencyRoll('src/', 'h://repo', '2', '6')}
     report = CrashReport('8', 'sig', 'linux', stack_trace, ('2', '6'),
                          deps, dep_rolls)
     changelog = self.GetDummyChangeLog()._replace(touched_files=[
         FileChangeInfo.FromDict({
             'change_type': 'add',
             'new_path': 'p/a.cc',
             'old_path': None,
         })
     ])
     suspect = Suspect(changelog, 'src/')
     feature_value = self._feature(report)(suspect)
     self.assertEqual(1.0, feature_value.value)
def ChangeLogFromDict(data):
    touched_files = [
        FileChangeInfo.FromDict(touched_file)
        for touched_file in data.get('touched_files', [])
    ]

    author = Contributor(
        data.get('author', {}).get('name', 'author'),
        data.get('author', {}).get('email', 'email'),
        data.get('author', {}).get('time', 'time'))
    committer = Contributor(
        data.get('committer', {}).get('name', 'committer'),
        data.get('committer', {}).get('email', 'email'),
        data.get('committer', {}).get('time', 'time'))
    return ChangeLog(author, committer, data.get('revision'),
                     data.get('commit_position'), data.get('message'),
                     touched_files, data.get('commit_url'),
                     data.get('code_review_url'),
                     data.get('reverted_revision'),
                     data.get('review_server_host'),
                     data.get('review_change_id'))
    def testIncludeTestFilesFlag(self):
        """Tests the ``include_test_files`` flag."""
        # Change in a test file:
        changelog = self.GetDummyChangeLog()._replace(touched_files=[
            FileChangeInfo.FromDict({
                'change_type': 'modify',
                'new_path': 'p/a_unittest.cc',
                'old_path': 'p/a_unittest.cc',
            })
        ])
        suspect = Suspect(changelog, 'src/')

        feature_with_flag = TouchCrashedDirectoryFeature(
            include_test_files=True)
        feature_value = feature_with_flag(self._report)(suspect)
        self.assertEqual(1.0, feature_value.value)

        feature_without_flag = TouchCrashedDirectoryFeature(
            include_test_files=False)
        feature_value = feature_without_flag(self._report)(suspect)
        self.assertEqual(0.0, feature_value.value)
    def _MockGetChangeLog(self, revision):
        class MockChangeLog(object):
            def __init__(self, revision, touched_files, **kwargs):
                self.author = kwargs.get('author') or Contributor(
                    'name',
                    '*****@*****.**',
                    # use revision as the date as well for testing purpose.
                    datetime.strptime('Jun %s 04:35:32 2015' % revision,
                                      '%b %d %H:%M:%S %Y'))
                self.touched_files = touched_files
                self.revision = revision

        MOCK_CHANGE_LOGS = {}
        MOCK_CHANGE_LOGS['1'] = MockChangeLog('1', [])
        MOCK_CHANGE_LOGS['2'] = MockChangeLog('2', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.ADD,
                'old_path': 'dev/null',
                'new_path': 'third_party/dep/f.cc'
            })
        ])
        MOCK_CHANGE_LOGS['3'] = MockChangeLog('3', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f.cc',
                'new_path': 'third_party/dep/f.cc'
            })
        ])
        MOCK_CHANGE_LOGS['4'] = MockChangeLog('4', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f2.cc',
                'new_path': 'third_party/dep/f2.cc'
            })
        ])
        MOCK_CHANGE_LOGS['5'] = MockChangeLog('5', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f3.cc',
                'new_path': 'third_party/dep/f3.cc'
            })
        ])
        MOCK_CHANGE_LOGS['6'] = MockChangeLog('6', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f.cc',
                'new_path': 'third_party/dep/f.cc'
            })
        ])
        MOCK_CHANGE_LOGS['7'] = MockChangeLog('7', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f.cc',
                'new_path': 'third_party/dep/f.cc'
            })
        ])
        MOCK_CHANGE_LOGS['8'] = MockChangeLog('8', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f.cc',
                'new_path': 'third_party/dep/f.cc'
            })
        ])
        MOCK_CHANGE_LOGS['9'] = MockChangeLog('9', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.DELETE,
                'old_path': 'third_party/dep/f.cc',
                'new_path': 'dev/null'
            })
        ])
        MOCK_CHANGE_LOGS['10'] = MockChangeLog('10', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f2.cc',
                'new_path': 'third_party/dep/f2.cc'
            })
        ])
        MOCK_CHANGE_LOGS['11'] = MockChangeLog('11', [
            FileChangeInfo.FromDict({
                'change_type': ChangeType.MODIFY,
                'old_path': 'third_party/dep/f2.cc',
                'new_path': 'third_party/dep/f2.cc'
            })
        ])

        return MOCK_CHANGE_LOGS.get(revision, MockChangeLog('12', []))