示例#1
0
    def test_check_exclude_py(self):
        """
        Test whether the check method of the PostfixExclude class
        correctly returns False for all python files.        directory.
        """

        self.assertTrue(PostfixExclude(['py']).check(self.file_gitignore))
        self.assertTrue(PostfixExclude(['py']).check(self.file_authors))
        self.assertTrue(PostfixExclude(['py']).check(self.file_bin))

        self.assertFalse(PostfixExclude(['py']).check(self.file_py))
        self.assertFalse(PostfixExclude(['py']).check(self.file__init__))
示例#2
0
    def test_check(self):
        """
        Test whether the check method of the PostfixExclude class
        correctly returns False for all README and markdown files,
        which are excluded by default.
        """

        self.assertTrue(PostfixExclude().check(self.file_gitignore))
        self.assertTrue(PostfixExclude().check(self.file_py))
        self.assertTrue(PostfixExclude().check(self.file_authors))
        self.assertTrue(PostfixExclude().check(self.file__init__))
        self.assertTrue(PostfixExclude().check(self.file_bin))
示例#3
0
    def test_check_exclude_none(self):
        """
        Test whether the check method of the PostfixExclude class
        correctly returns True for all files when no extensions
        to be excluded are passed to the check method.
        """

        self.assertTrue(PostfixExclude([]).check(self.file_gitignore))
        self.assertTrue(PostfixExclude([]).check(self.file_py))
        self.assertTrue(PostfixExclude([]).check(self.file_authors))
        self.assertTrue(PostfixExclude([]).check(self.file__init__))
        self.assertTrue(PostfixExclude([]).check(self.file_bin))
示例#4
0
    def test__flatten_PostfixExclude(self):
        """
        Test whether _flatten correctly excludes commits based
        on PostfixExclude condition. The default file types of
        markdown(.md) and README are excluded in this test.
        """

        commit = CommitGit(self.items, is_code=[PostfixExclude()])
        expected_df = CommitGit(self.items).df

        for index, item in expected_df.iterrows():

            valid_files = [
                file['file'] for file in item['files'] if all(
                    condition.check(file['file'])
                    for condition in commit.is_code)
            ]

            if len(valid_files) == 0:
                expected_df.drop(index, inplace=True)
        expected_df = expected_df.reset_index(drop=True)
        assert_frame_equal(expected_df, commit.df)
示例#5
0
        y = 'count'
        use_index = True
        return {'x': x, 'y': y, 'title': title, 'use_index': use_index}

    def __str__(self):
        return "Code Changes"


if __name__ == "__main__":
    date_since = datetime.strptime("2018-09-07", "%Y-%m-%d")
    items = read_json_file('../git-commits.json')

    # total changes
    changes = CodeChangesGit(items, date_range=(date_since, None))
    print("Code_Changes, total:", changes.compute())

    # excluding certain files
    changes = CodeChangesGit(items, date_range=(date_since, None),
                             is_code=[DirExclude(['tests']),
                                      PostfixExclude(['.md', 'COPYING'])])
    print("Code_Changes, excluding some files:", changes.compute())

    # considering commits only on the master
    changes = CodeChangesGit(items, date_range=(date_since, None),
                             conds=[MasterInclude()])
    print("Code_Changes, only for master:", changes.compute())

    # time-series on a monthly basis considering only master commits
    print("The number of commits created on a monthly basis is:")
    print(changes.time_series(period='M'))