Skip to content

Commit

Permalink
Fix some tests to get mocked log order correct (most recent first).
Browse files Browse the repository at this point in the history
  • Loading branch information
netsettler committed Jul 30, 2023
1 parent 572b2dd commit f5572ae
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions test/test_contribution_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,69 +82,69 @@ def test_git_analysis_find_repo():
def test_git_analysis_git_commits():

mocked_commits = [
{
"hexsha": "bbbb",
"committed_datetime": "2020-01-02 12:34:56",
"author": {"name": "Sally", "email": "ssmith@foo"},
"message": "something else"
},
{
"hexsha": "aaaa",
"committed_datetime": "2020-01-01 01:23:45",
"author": {"name": "Jdoe", "email": "jdoe@foo"},
"message": "something"
},
{
"hexsha": "bbbb",
"committed_datetime": "2020-01-02 12:34:56",
"author": {"name": "Sally", "email": "ssmith@foo"},
"message": "something else"
}
]

with git_context(mocked_commits={"foo": mocked_commits}):
foo_repo = GitAnalysis.find_repo('foo')
foo_commits = list(foo_repo.iter_commits())
assert len(foo_commits) == 2
assert all(isinstance(commit, MockGitCommit) for commit in foo_commits)
assert GitAnalysis.json_for_actor(foo_commits[0].author) == {'name': 'Jdoe', 'email': 'jdoe@foo'}
assert GitAnalysis.json_for_actor(foo_commits[1].author) == {'name': 'Sally', 'email': 'ssmith@foo'}
assert foo_commits[0].hexsha == 'aaaa'
assert foo_commits[1].hexsha == 'bbbb'
assert GitAnalysis.json_for_actor(foo_commits[0].author) == {'name': 'Sally', 'email': 'ssmith@foo'}
assert GitAnalysis.json_for_actor(foo_commits[1].author) == {'name': 'Jdoe', 'email': 'jdoe@foo'}
assert foo_commits[0].hexsha == 'bbbb'
assert foo_commits[1].hexsha == 'aaaa'

assert [GitAnalysis.json_for_commit(commit) for commit in foo_commits] == list(GitAnalysis.git_commits('foo'))


def test_git_analysis_iter_commits_scenario(): # Tests .iter_commits, .json_for_commit, .json_for_actor, .git_commits

mocked_commits = [
{
"hexsha": "aaaa",
"committed_datetime": "2020-01-01T01:23:45-05:00",
"author": {"name": "Jdoe", "email": "jdoe@foo"},
"message": "something"
},
{
"hexsha": "bbbb",
"committed_datetime": "2020-01-02T12:34:56-05:00",
"author": {"name": "Sally", "email": "ssmith@foo"},
"co_authors": [{"name": "William Simmons", "email": "bill@someplace"}],
"message": "something else"
}
},
{
"hexsha": "aaaa",
"committed_datetime": "2020-01-01T01:23:45-05:00",
"author": {"name": "Jdoe", "email": "jdoe@foo"},
"message": "something"
},
]

with git_context(mocked_commits={"foo": mocked_commits}):
foo_repo = GitAnalysis.find_repo("foo")
foo_commits_as_json = [GitAnalysis.json_for_commit(commit) for commit in foo_repo.iter_commits()]
assert foo_commits_as_json == [
{
'author': {'email': 'ssmith@foo', 'name': 'Sally'},
'coauthors': [{'email': 'bill@someplace', 'name': 'William Simmons'}],
'commit': 'bbbb',
'date': '2020-01-02T12:34:56-05:00',
'message': 'something else'
},
{
'author': {'email': 'jdoe@foo', 'name': 'Jdoe'},
'coauthors': [],
'commit': 'aaaa',
'date': '2020-01-01T01:23:45-05:00',
'message': 'something'
},
{
'author': {'email': 'ssmith@foo', 'name': 'Sally'},
'coauthors': [{'email': 'bill@someplace', 'name': 'William Simmons'}],
'commit': 'bbbb',
'date': '2020-01-02T12:34:56-05:00',
'message': 'something else'
}
]

assert foo_commits_as_json == list(GitAnalysis.git_commits('foo'))
Expand Down Expand Up @@ -679,19 +679,19 @@ def test_contributions_init_with_cached_pre_fork():
json.dump(cache_data, fp=fp)

mocked_commits = [
{
"hexsha": "aaaa",
"committed_datetime": "2020-01-01T01:23:45-05:00",
"author": {"name": "Jessica", "email": "jdoe@foo"},
"message": "something"
},
{
"hexsha": "bbbb",
"committed_datetime": "2020-01-02T12:34:56-05:00",
"author": {"name": "Sally", "email": "ssmith@foo"},
"co_authors": [{"name": "William Simmons", "email": "bill@someplace"}],
"message": "something else"
}
},
{
"hexsha": "aaaa",
"committed_datetime": "2020-01-01T01:23:45-05:00",
"author": {"name": "Jessica", "email": "jdoe@foo"},
"message": "something"
},
]

with git_context(mocked_commits={"foo": mocked_commits}):
Expand Down Expand Up @@ -732,19 +732,19 @@ def test_contributions_init_with_no_cached_pre_fork():
json.dump(cache_data, fp=fp)

mocked_commits = [
{
"hexsha": "aaaa",
"committed_datetime": "2020-01-01T01:23:45-05:00",
"author": {"name": "Jessica", "email": "jdoe@foo"},
"message": "something"
},
{
"hexsha": "bbbb",
"committed_datetime": "2020-01-02T12:34:56-05:00",
"author": {"name": "Sally", "email": "ssmith@foo"},
"co_authors": [{"name": "William Simmons", "email": "bill@someplace"}],
"message": "something else"
}
},
{
"hexsha": "aaaa",
"committed_datetime": "2020-01-01T01:23:45-05:00",
"author": {"name": "Jessica", "email": "jdoe@foo"},
"message": "something"
},
]

with git_context(mocked_commits={"foo": mocked_commits}):
Expand Down

0 comments on commit f5572ae

Please sign in to comment.