Ejemplo n.º 1
0
    def test_presence_of_diffs(self):

        #how to handle project-specific settings?
        analyze_command = AnalyzeCommand(self.project, self.settings,
                                         self.backend)
        analyze_command.opts['n'] = 3
        analyze_command.opts['branch'] = 'master'
        analyze_command.run()

        snapshots = self.backend.filter(GitSnapshot,
                                        {}).sort('committer_date', 1)

        assert len(self.backend.filter(Diff, {})) == 2

        assert len(self.backend.filter(Diff, {})) == 2

        assert len(self.backend.filter(DiffFileRevision, {})) == 2
        assert len(self.backend.filter(DiffIssueOccurrence, {})) == 2

        i = 0
        for last_snapshot, snapshot in zip(snapshots[:-1], snapshots[1:]):
            diff = self.backend.get(
                Diff, {
                    'snapshot_a.git_snapshot': last_snapshot,
                    'snapshot_b.git_snapshot': snapshot
                })
            assert diff.issue_occurrences
            print len(diff.issue_occurrences) == 10
            if i == 0:
                assert len(diff.file_revisions) == 1
                assert len(diff.file_revisions.filter({'key': 'deleted'})) == 1
            i += 1
Ejemplo n.º 2
0
    def test_analyze(self):
        #how to handle project-specific settings?
        analyze_command = AnalyzeCommand(self.project, self.settings,
                                         self.backend)
        analyze_command.opts['n'] = 1
        analyze_command.opts['branch'] = 'origin/master'
        analyze_command.run()

        snapshot = self.backend.get(GitSnapshot, {})
        assert snapshot
        issues = self.backend.filter(Issue, {})
        assert len(issues) == 1
        issue_occurrences = self.backend.filter(IssueOccurrence, {})
        assert len(issue_occurrences) == 3
        branch = self.backend.get(GitBranch, {})
        assert branch.name == 'origin/master'
Ejemplo n.º 3
0
    def test_number_of_snapshots(self):

        #how to handle project-specific settings?
        analyze_command = AnalyzeCommand(self.project, self.settings,
                                         self.backend)
        analyze_command.opts['n'] = 3
        analyze_command.opts['branch'] = 'master'
        analyze_command.run()

        repository = self.project.git.repository
        git_snapshots = self.project.git.get_snapshots(branch='master')[::-1]
        snapshots = self.backend.filter(GitSnapshot,
                                        {}).sort('committer_date', -1)

        assert len(snapshots) == 3

        for snapshot, git_snapshot in zip(snapshots,
                                          git_snapshots[:len(snapshots)]):
            assert snapshot['sha'] == git_snapshot['sha']
def analyze_branch(project,
                   branch,
                   snapshots_per_run=2,
                   runs=2,
                   analysis_types=("latest", "daily", "weekly"),
                   shas=None,
                   diffs=None):
    """ Analyzes the given branch of the given project.
    :param project: project to analyze
    :param branch: branch to analyze
    :param snapshots_per_run: number of snapshots to create per run
    :param runs: number of runs to perform
    :param analysis_types: types of analysis to perform
    :param shas: list of shas
    :param diffs: list of diffs
    :return:
    """
    checkmate_settings = settings.checkmate_settings
    logger.info("Analyzing branch: {}".format(branch))

    for analysis_type in analysis_types:

        for i in range(runs):

            opts = {
                'n': snapshots_per_run,
                'offset': max(i * snapshots_per_run - 1, 0),
                'branch': branch,
                'shas': ','.join(shas) if shas is not None else '',
                'diffs': diffs,
                'type': analysis_type
            }

            analyze_command = AnalyzeCommand(project,
                                             settings.checkmate_settings,
                                             backend)
            analyze_command.opts.update(opts)
            analyze_command.run()