Beispiel #1
0
    def test_authors_top(self, mock_fetch):
        with patch("pygit2.Repository"),\
                patch("pygit2.Mailmap"):
            stat = GitRepository(MagicMock())

            authors_ts = stat.get_authors_ranking_by_year()
            self.assertEqual(2, authors_ts.loc[(2020, 'Author1')])
            self.assertEqual(1, authors_ts.loc[(2019, 'Author2')])

            authors_ts = stat.get_authors_ranking_by_month()
            self.assertEqual(1, authors_ts.loc[('2020-03', 'Author1')])
            self.assertEqual(1, authors_ts.loc[('2019-11', 'Author2')])
Beispiel #2
0
 def test_active_days_count(self, mock_fetch):
     with patch("pygit2.Repository"),\
             patch("pygit2.Mailmap"):
         expected_active_days = {datetime.fromtimestamp(rec['author_timestamp']).strftime('%Y-%m-%d') for rec in
                                 self.test_whole_history_records}
         stat = GitRepository(MagicMock())
         self.assertEqual(len(expected_active_days), stat.active_days_count)
Beispiel #3
0
    def test_first_last_timestamps(self, mock_fetch):
        with patch("pygit2.Repository"),\
                patch("pygit2.Mailmap"):
            timestamps = [rec['author_timestamp'] for rec in self.test_whole_history_records]
            expected_last_commit_timestamp = max(timestamps)
            expected_first_commit_timestamp = min(timestamps)

            stat = GitRepository(MagicMock())
            self.assertEqual(expected_first_commit_timestamp, stat.first_commit_timestamp)
            self.assertEqual(expected_last_commit_timestamp, stat.last_commit_timestamp)
Beispiel #4
0
def main():
    try:
        config = Configuration(sys.argv[1:])
    except EnvironmentError as ee:
        warnings.warn("Environment exception occurred: {}".format(ee))
        sys.exit(1)

    print('Git path: %s' % config.git_repository_path)
    print('Collecting data...')

    repository_statistics = GitRepository(config.git_repository_path)

    output_path = config.statistics_output_path
    print('Output path: %s' % output_path)
    os.makedirs(output_path, exist_ok=True)

    print('Generating HTML report...')
    report = HTMLReportCreator(config, repository_statistics)

    report.set_time_sampling(config.get_time_sampling())\
        .generate_index_page(config.do_generate_index_page())\
        .set_max_orphaned_extensions_count(config.get_max_orphaned_extensions_count())

    if config.do_calculate_contribution():
        report.allow_blame_data()

    report.create(output_path)

    exec_time_seconds = get_execution_time()
    print('Report generated in %.2f secs.' % exec_time_seconds)

    url = os.path.join(output_path, 'general.html').replace("'", "'\\''")
    if config.do_open_in_browser():
        webbrowser.open(url, new=2)
    else:
        print("You may open your report in a browser. Path: {}".format(url))
Beispiel #5
0
 def setUp(cls):
     with patch("pygit2.Mailmap"), \
          patch("pygit2.Repository"), \
          patch.object(WholeHistory, 'fetch', return_value=cls.test_whole_history_records):
         cls.repo = GitRepository(MagicMock())
Beispiel #6
0
 def test_repository_name(self):
     _, expected_name = os.path.split(self.test_repo.location)
     repo = GitRepository(self.test_repo.location)
     self.assertEqual(expected_name, repo.name)
Beispiel #7
0
    def test_domains_distribution(self, mock_fetch):
        with patch("pygit2.Repository"), patch("pygit2.Mailmap"):
            stat = GitRepository(MagicMock())

            expected_domains = {'author1.com': 2, 'author2.com': 1, 'author3.com': 1}
            self.assertDictEqual(expected_domains, stat.domains_distribution.to_dict())
Beispiel #8
0
 def test_timezones_distribution(self, mock_fetch):
     with patch("pygit2.Repository"),\
             patch("pygit2.Mailmap"):
         stat = GitRepository(MagicMock())
         expected_timezones = self.get_expected_timezones_dict()
         self.assertDictEqual(expected_timezones, stat.timezones_distribution)
Beispiel #9
0
 def test_whole_history_once_for_statistics(self, mock_fetch):
     with patch("pygit2.Repository"),\
             patch("pygit2.Mailmap"):
         GitRepository(MagicMock())
         self.assertEqual(1, mock_fetch.call_count)
Beispiel #10
0
 def test_recent_activity(self, mock_fetch):
     with patch("pygit2.Repository"),\
             patch("pygit2.Mailmap"):
         stat = GitRepository(MagicMock())
         two_weeks_activity = stat.get_recent_weekly_activity(2)
         self.assertListEqual([0, 1], list(two_weeks_activity))