def test_label__return(self):
        """To test the condition:
            if not (self.fixing_commits or self.fixed_files):
                return
        """
        miner = BaseMiner(
            url_to_repo='https://github.com/stefanodallapalma/radon-repository-miner-testing.git',
            clone_repo_to=os.path.join(os.getcwd(), 'test_data', 'tmp')
        )

        miner.fixing_commits = ['3de3d8c2bbccf62ef5698cf33ad258aae5316432']
        miner.fixed_files = []
        for item in miner.label():
            self.assertIsNone(item)

        miner.fixing_commits = []
        miner.fixed_files = [FixedFile(filepath='filepath', fic='', bic='')]
        for item in miner.label():
            self.assertIsNone(item)
    def test_get_fixed_files_with_more_than_one_commits(self):
        """To test else branch in condition: if len(self.fixing_commits) == 1"""
        miner = BaseMiner(
            url_to_repo='https://github.com/stefanodallapalma/radon-repository-miner-testing.git',
            clone_repo_to=os.path.join(os.getcwd(), 'test_data', 'tmp')
        )

        miner.fixing_commits = ['3de3d8c2bbccf62ef5698cf33ad258aae5316432', 'c029d7520456e5468d66b56fe176146680520b20']
        miner.get_fixed_files()
        self.assertListEqual([], miner.fixed_files)
    def test_get_fixing_commits__continue(self):
        """To test if branch in condition:
            if commit.hash in self.fixing_commits:
                continue
        """
        miner = BaseMiner(
            url_to_repo='https://github.com/stefanodallapalma/radon-repository-miner-testing.git',
            clone_repo_to=os.path.join(os.getcwd(), 'test_data', 'tmp')
        )

        commits = [
            '3de3d8c2bbccf62ef5698cf33ad258aae5316432',
            'fa91aedc17a7dfb08a60f189c86a9d86dac72b41',
            'ea49aab402a7cb64e9382e764f202d9e6c8f4cbe',
            'c029d7520456e5468d66b56fe176146680520b20',
            'd39fdb44e98869835fe59a86d20d05a9e82d5282',
        ]

        miner.fixing_commits = commits
        miner.get_fixing_commits()
        self.assertListEqual(miner.fixing_commits, commits)
Esempio n. 4
0
def mine_fixing_commits(miner: BaseMiner,
                        verbose: bool,
                        dest: str,
                        exclude_commits: str = None,
                        include_commits: str = None):

    if exclude_commits:
        with open(exclude_commits, 'r') as f:
            commits = json.load(f)
            miner.exclude_commits = set(commits)

    if include_commits:
        with open(include_commits, 'r') as f:
            commits = json.load(f)
            miner.fixing_commits = commits

    if verbose:
        print('Identifying fixing-commits from closed issues related to bugs')

    from_issues = miner.get_fixing_commits_from_closed_issues(labels=None)

    if verbose:
        print('Identifying fixing-commits from commit messages')

    from_msg = miner.get_fixing_commits_from_commit_messages(regex=None)

    if verbose:
        print(
            f'Saving {len(miner.fixing_commits)} fixing-commits ({len(from_issues)} from closed issue, {len(from_msg)} from commit messages) [{datetime.now().hour}:{datetime.now().minute}]'
        )

    filename_json = os.path.join(dest, 'fixing-commits.json')

    with io.open(filename_json, "w") as f:
        json.dump(miner.fixing_commits, f)

    if verbose:
        print(f'JSON created at {filename_json}')