From d6299fc345205db9dea5d9568f26788f9d5c0d59 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: May 15 2018 19:20:19 +0000 Subject: [PATCH 1/3] Add tests for getting commit author stats --- diff --git a/tests/test_tasks.py b/tests/test_tasks.py new file mode 100644 index 0000000..7aa5a64 --- /dev/null +++ b/tests/test_tasks.py @@ -0,0 +1,116 @@ +from mock import patch, Mock +from collections import namedtuple +import os +import unittest + +from pagure.lib import tasks + + +MockUser = namedtuple('MockUser', ['fullname', 'default_email']) + + +class MockCommit(object): + def __init__(self, name, email, time='1970-01-01 00:00'): + self.author = Mock(email=email) + self.author.name = name + self.commit_time = time + + +@patch('pagure.lib.create_session', new=Mock()) +class TestCommitsAuthorStats(unittest.TestCase): + + def setUp(self): + self.search_user_patcher = patch('pagure.lib.search_user') + mock_search_user = self.search_user_patcher.start() + mock_search_user.side_effect = lambda _, email: self.authors.get(email) + + self.pygit_patcher = patch('pygit2.Repository') + mock_repo = self.pygit_patcher.start().return_value + + def mock_walk_impl(*args, **kwargs): + for commit in self.commits: + yield commit + + mock_repo.walk.side_effect = mock_walk_impl + + self.repopath = Mock() + exists = os.path.exists + + def mock_exists_impl(path): + if path == self.repopath: + return True + return exists(path) + + self.exists_patcher = patch('os.path.exists') + mock_exists = self.exists_patcher.start() + mock_exists.side_effect = mock_exists_impl + + def tearDown(self): + self.search_user_patcher.stop() + self.pygit_patcher.stop() + self.exists_patcher.stop() + + def test_no_change(self): + self.commits = [ + MockCommit('Alice', 'alice@example.com', '2018-01-01 00:00'), + ] + self.authors = { + 'alice@example.com': MockUser('Alice', 'alice@example.com'), + } + + num_commits, authors, num_authors, last_time = \ + tasks.commits_author_stats(self.repopath) + + self.assertEqual(num_commits, 1) + self.assertEqual(num_authors, 1) + self.assertEqual(last_time, '2018-01-01 00:00') + self.assertEqual(authors, [(1, [('Alice', 'alice@example.com')])]) + + def test_rename_user_and_merge(self): + self.commits = [ + MockCommit('Alice', 'alice@example.com'), + MockCommit('Bad name', 'alice@example.com', '2018-01-01 00:00'), + ] + self.authors = { + 'alice@example.com': MockUser('Alice', 'alice@example.com'), + } + + num_commits, authors, num_authors, last_time = \ + tasks.commits_author_stats(self.repopath) + + self.assertEqual(num_commits, 2) + self.assertEqual(num_authors, 1) + self.assertEqual(last_time, '2018-01-01 00:00') + self.assertEqual(authors, [(2, [('Alice', 'alice@example.com')])]) + + def test_preserve_unknown_author(self): + self.commits = [ + MockCommit('Alice', 'alice@example.com', '2018-01-01 00:00'), + ] + self.authors = {} + + num_commits, authors, num_authors, last_time = \ + tasks.commits_author_stats(self.repopath) + + self.assertEqual(num_commits, 1) + self.assertEqual(num_authors, 1) + self.assertEqual(last_time, '2018-01-01 00:00') + self.assertEqual(authors, [(1, [('Alice', 'alice@example.com')])]) + + def test_handle_empty_email(self): + self.commits = [ + # Two commits for Alice to ensure order of the result. + MockCommit('Alice', None), + MockCommit('Alice', None), + MockCommit('Bob', '', '2018-01-01 00:00'), + ] + self.authors = {} + + num_commits, authors, num_authors, last_time = \ + tasks.commits_author_stats(self.repopath) + + self.assertEqual(num_commits, 3) + self.assertEqual(num_authors, 2) + self.assertEqual(last_time, '2018-01-01 00:00') + self.assertEqual(authors, [(2, [('Alice', None)]), + (1, [('Bob', '')])]) From 4c1623df459387c423baa06c4749bceeacf724a8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 15 2018 19:20:19 +0000 Subject: [PATCH 2/3] Force install/upgrade of pygments and chardet in CI Signed-off-by: Pierre-Yves Chibon --- diff --git a/run_ci_tests.sh b/run_ci_tests.sh index 508e068..55a053d 100755 --- a/run_ci_tests.sh +++ b/run_ci_tests.sh @@ -31,6 +31,7 @@ git log -2 fi pip install --upgrade tox +pip install --upgrade --force-reinstall pygments chardet tox --sitepackages -e 'py{27,34}-flask011-ci' -- -v --with-xcoverage --cover-erase --cover-package=pagure set +e From 5e6606fccb723104c4a4cab99d188ec418cdcfe1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 15 2018 19:20:19 +0000 Subject: [PATCH 3/3] Install the header files for python 3.4 Signed-off-by: Pierre-Yves Chibon --- diff --git a/run_ci_tests.sh b/run_ci_tests.sh index 55a053d..c467cd1 100755 --- a/run_ci_tests.sh +++ b/run_ci_tests.sh @@ -1,6 +1,6 @@ set -x -yum install -y python-virtualenv python34 \ +yum install -y python-virtualenv python34 python34-devel \ gcc python-cryptography python34-cryptography \ libgit2 python-pygit2 \ redis swig openssl-devel m2crypto \