Esempio n. 1
0
 def test_sorted_results_inverse(self):
     results = result.Results()
     commit1 = results.get_result('hash1')
     commit1.add_file(git.GitFile('file1', 'M'))
     commit2 = results.get_result('hash2')
     expected = [commit1, commit2]
     self.assertEqual(expected, results.get_sorted_results())
Esempio n. 2
0
def lookup_stacktrace(traceback, git_range, fast):
    """Lookup to see what commits in git_range could have caused the stacktrace.

    If fast is True, don't run pickaxe if cannot find the file in git.

    Pass in a stacktrace object and returns a results object."""
    results = result.Results()

    commit_files = git.files_touched(git_range)
    git_files = git.files(git_range)
    _lookup_files(commit_files, git_files, traceback, results)

    for line in traceback.lines:
        commits = []
        if not (line.git_filename is None and fast is True):
            try:
                commits = git.pickaxe(line.code, git_range, line.git_filename)
            except Exception:
                # If this fails, move on
                continue
        for commit, line_removed in commits:
            if line_removed is True:
                results.get_result(commit).lines_removed.add(line.code)
            if line_removed is False:
                results.get_result(commit).lines_added.add(line.code)
    return results
Esempio n. 3
0
 def test_get_sorted_results_by_dict(self, mocked_git_info):
     mocked_git_info.return_value = fake_commit_info
     results = result.Results()
     commit2 = results.get_result('hash2')
     commit1 = results.get_result('hash1')
     commit1.add_file(git.GitFile('file1', 'M'))
     expected = [dict(commit1), dict(commit2)]
     self.assertEqual(expected, results.get_sorted_results_by_dict())
Esempio n. 4
0
def lookup_stacktrace(traceback, git_range, fast=False):
    """Lookup to see what commits in git_range could have caused the stacktrace.

    Pass in a stacktrace object and returns a results object.

    :param traceback: Traceback object
    :type traceback: git_stacktrace.parse_trace.Traceback
    :param git_range: git commit range
    :type git_range: str
    :param fast: If True, don't run pickaxe if cannot find the file in git.
    :type fast: bool
    :returns: results
    :rtype: git_stacktrace.result.Results
    """
    results = result.Results()

    commit_files = git.files_touched(git_range)
    git_files = git.files(git_range)
    _lookup_files(commit_files, git_files, traceback, results)

    for line in traceback.lines:
        commits = []
        if line.code and not (line.git_filename is None and fast is True):
            try:
                commits = git.pickaxe(line.code, git_range, line.git_filename)
            except Exception:
                # If this fails, move on
                if log.isEnabledFor(logging.DEBUG):
                    log.exception("pickaxe failed")
                continue
        for commit, line_removed in commits:
            if line_removed is True:
                results.get_result(commit).lines_removed.add(line.code)
            if line_removed is False:
                results.get_result(commit).lines_added.add(line.code)
    return results
Esempio n. 5
0
 def test_results(self):
     results = result.Results()
     commit1 = results.get_result('hash1')
     commit1.add_file(git.GitFile('file1', 'A'))
     commit2 = results.get_result('hash1')
     self.assertEqual(commit1, commit2)