def test_create_changeset_list(self):
     fields1 = ChangesetFields()
     fields2 = ChangesetFields()
     fields2.node = "defg5678defg"
     logoutput = "%s\n%s\n" % (fields1.get_logoutput(),
                               fields2.get_logoutput())
     chg_list = ChangesetList()
     self.repo._populate_changeset_list(logoutput, chg_list)
     self.assertEquals(2, len(chg_list.get_changesets()))
Example #2
0
 def test_create_changeset_list(self):
     fields1 = ChangesetFields()
     fields2 = ChangesetFields()
     fields2.node = "defg5678defg"
     logoutput = "%s\n%s\n" % (fields1.get_logoutput(),
                               fields2.get_logoutput())
     chg_list = ChangesetList()
     self.repo._populate_changeset_list(logoutput, chg_list)
     self.assertEquals(2, len(chg_list.get_changesets()))
Example #3
0
 def test_really_interacting_with_mercurial_repo(self):
     self.create_real_repo()
     commitopts = '-m "commit" -u "user name <*****@*****.**>"'
     self.repo.get_command_output('echo hello > hello')
     self.repo.get_command_output('hg add hello')
     self.repo.get_command_output('hg commit ' + commitopts)
     self.repo.get_command_output('echo goodbye > bye')
     self.repo.get_command_output('hg add bye')
     self.repo.get_command_output('hg commit ' + commitopts)
     startdate = datetime(2011, 1, 4, 0, 0, 0)
     chg_list = ChangesetList()
     self.repo.get_full_changesetlist(startdate, chg_list)
     self.assertEquals(2, len(chg_list.get_changesets()))
 def test_really_interacting_with_mercurial_repo(self):
     self.create_real_repo()
     commitopts = '-m "commit" -u "user name <*****@*****.**>"'
     self.repo.get_command_output('echo hello > hello')
     self.repo.get_command_output('hg add hello')
     self.repo.get_command_output('hg commit ' + commitopts)
     self.repo.get_command_output('echo goodbye > bye')
     self.repo.get_command_output('hg add bye')
     self.repo.get_command_output('hg commit ' + commitopts)
     startdate = datetime(2011, 1, 4, 0, 0, 0)
     chg_list = ChangesetList()
     self.repo.get_full_changesetlist(startdate, chg_list)
     self.assertEquals(2, len(chg_list.get_changesets()))
Example #5
0
 def __init__(self, bugid_file, repodir, startdate, showbugs,
              output_format):
     self._bugid_file = bugid_file
     self._startdate = startdate
     self._showbugs = showbugs
     self._repodir = repodir
     self._output_format = output_format
     self._buglist = BugList()
     self._buggy_file_list = BuggyFileList()
     self._changesets = ChangesetList()
Example #6
0
 def setUp(self):
     self.changeset_list = ChangesetList()
Example #7
0
class TestChangesetList(unittest.TestCase):
    def setUp(self):
        self.changeset_list = ChangesetList()

    def test_add_changeset(self):
        chg = MockChangeset()
        self.changeset_list.add(chg)
        self.assertIn(chg.commitid, self.changeset_list._changesets)

    def test_add_changeset_refuses_to_keep_dupes(self):
        self.changeset_list.add(MockChangeset('abc'))
        self.changeset_list.add(MockChangeset('abc'))
        self.assertEquals(1, len(self.changeset_list._changesets))

    def test_remove_changesets_with_no_bugs_fixed(self):
        self.changeset_list.add(MockChangeset(num_bugs_fixed=0))
        self.changeset_list.remove_changesets_which_do_not_fix_a_bug()
        self.assertEquals(0, len(self.changeset_list._changesets))

    def test_remove_changesets_leaves_bugs_which_fix_bugs(self):
        no_bugs = MockChangeset(commitid='nobugs', num_bugs_fixed=0)
        with_bugs = MockChangeset(commitid='bugs', num_bugs_fixed=2)
        self.changeset_list.add(no_bugs)
        self.changeset_list.add(with_bugs)
        self.changeset_list.remove_changesets_which_do_not_fix_a_bug()
        self.assertEquals(1, len(self.changeset_list._changesets))
        self.assertIn(with_bugs.commitid, self.changeset_list._changesets)
Example #8
0
class FlyPaper(object):
    def __init__(self, bugid_file, repodir, startdate, showbugs,
                 output_format):
        self._bugid_file = bugid_file
        self._startdate = startdate
        self._showbugs = showbugs
        self._repodir = repodir
        self._output_format = output_format
        self._buglist = BugList()
        self._buggy_file_list = BuggyFileList()
        self._changesets = ChangesetList()

    def show_bug_catchers(self):
        #populate list of bugs
        self._buglist.read_bug_list(self._bugid_file)

        #populate list of changesets
        self._repo = RepoFactory.get_repo(self._repodir)
        self._repo.get_full_changesetlist(self._startdate, self._changesets)

        #match bugs with the changesets that fix them
        self._match_bugs_with_changesets()

        #forget changesets which do not fix a bug
        self._changesets.remove_changesets_which_do_not_fix_a_bug()

        #populate list of files which were modified when fixing bugs
        self._build_buggy_file_list()

        #sort files by bugginess and output results
        results = self._get_buggy_files_sorted_by_bugginess()
        print self._get_output(results)

    def _match_bugs_with_changesets(self):
        for changeset in self._changesets.get_changesets():
            for bugid in self._buglist.bugs.keys():
                if changeset.description_contains(bugid):
                    bug = self._buglist.bugs[bugid]
                    bug.add_fixing_changeset(changeset)
                    changeset.add_bug_fixed(bug)

    def _build_buggy_file_list(self):
        for changeset in self._changesets.get_changesets():
            for filename in changeset.modified_files:
                for bug in changeset.bugs_fixed:
                    self._buggy_file_list.add_buggy_file(bug, filename)

    def _get_buggy_files_sorted_by_bugginess(self):
        #create dict mapping scores to buggy files
        score_map = {}
        for buggyfile in self._buggy_file_list.get_files():
            score = buggyfile.get_score(self._startdate)
            if score not in score_map:
                score_map[score] = []
            score_map[score].append(buggyfile)

        #create list sorted by score
        sorted_buggy_files = []
        all_scores = score_map.keys()
        all_scores.sort()
        all_scores.reverse()
        for score in all_scores:
            buggyfiles = score_map[score]
            buggyfiles.sort(cmp=lambda x, y: cmp(x.filename, y.filename))
            sorted_buggy_files.extend(buggyfiles)
        return sorted_buggy_files

    def _get_output(self, buggyfiles):
        if self._output_format == 'json':
            return self._get_output_json(buggyfiles)
        return self._get_output_plain_text(buggyfiles)

    def _get_output_plain_text(self, buggyfiles):
        output = ""
        for buggyfile in buggyfiles:
            score_str = "%.03f" % buggyfile.get_score(self._startdate)
            output += score_str + " " + buggyfile.filename
            if self._showbugs:
                buglist = [x.__str__() for x in buggyfile.get_bugs()]
                output += " "
                output += ",".join(buglist)
            output += "\n"
        return output

    def _get_output_json(self, buggyfiles):
        out_obj = {}
        files = []
        for buggyfile in buggyfiles:
            onefile = {}
            onefile['filename'] = buggyfile.filename
            onefile['score'] = buggyfile.get_score(self._startdate)
            if self._showbugs:
                onefile['bugs'] = [x.__str__() for x in buggyfile.get_bugs()]
            files.append(onefile)
        out_obj['files'] = files
        return json.dumps(out_obj, sort_keys=True, indent=2)