-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# test page | ||
|
||
this page has no git authors tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,36 @@ | |
import os | ||
from git import Actor, Repo | ||
|
||
def test_retrieve_authors(tmp_path): | ||
def test_empty_file(tmp_path): | ||
|
||
# Create empty file | ||
file_name = os.path.join(tmp_path, 'new-file') | ||
open(file_name, 'a').close() | ||
|
||
# Get authors of empty, uncommitted file | ||
r = Repo.init(tmp_path) | ||
instance = util.Util(tmp_path) | ||
authors = instance.get_authors(path = file_name) | ||
assert authors == "" | ||
|
||
# Create empty file | ||
# Get authors of empty, committed file | ||
r.index.add([file_name]) | ||
author = Actor('Tim', '[email protected]') | ||
r.index.commit("initial commit", author = author) | ||
authors = instance.get_authors(path = file_name) | ||
assert authors == "" | ||
|
||
def test_retrieve_authors(tmp_path): | ||
|
||
tmp_path = "/Users/ue86yw/workspace/testrepo" | ||
|
||
# Create file | ||
file_name = os.path.join(tmp_path, 'new-file') | ||
with open(file_name, 'w') as the_file: | ||
the_file.write('Hello\n') | ||
|
||
# Commit | ||
|
||
# Create git repo and commit file | ||
r = Repo.init(tmp_path) | ||
r.index.add([file_name]) | ||
author = Actor('Tim', '[email protected]') | ||
r.index.commit("initial commit", author = author) | ||
|
@@ -27,6 +47,50 @@ def test_retrieve_authors(tmp_path): | |
'lines' : 1, | ||
'contribution' : '100.0%' | ||
}] | ||
|
||
# Now add a line to the file | ||
# From a second author with same email | ||
with open(file_name, 'a+') as the_file: | ||
the_file.write('World\n') | ||
r.index.add([file_name]) | ||
author = Actor('Tim2', '[email protected]') | ||
r.index.commit("another commit", author = author) | ||
|
||
authors = instance.get_authors(path = file_name) | ||
authors[0]['last_datetime'] = None | ||
|
||
assert authors == [{ | ||
'name' : "Tim", | ||
'email' : "[email protected]", | ||
'last_datetime' : None, | ||
'lines' : 2, | ||
'contribution' : '100.0%' | ||
}] | ||
|
||
# Then a third commit from a new author | ||
with open(file_name, 'a+') as the_file: | ||
the_file.write('A new line\n') | ||
r.index.add([file_name]) | ||
author = Actor('John', '[email protected]') | ||
r.index.commit("third commit", author = author) | ||
|
||
authors = instance.get_authors(path = file_name) | ||
authors[0]['last_datetime'] = None | ||
authors[1]['last_datetime'] = None | ||
|
||
assert authors == [{ | ||
'name' : "John", | ||
'email' : "[email protected]", | ||
'last_datetime' : None, | ||
'lines' : 1, | ||
'contribution' : '33.33%' | ||
},{ | ||
'name' : "Tim", | ||
'email' : "[email protected]", | ||
'last_datetime' : None, | ||
'lines' : 2, | ||
'contribution' : '66.67%' | ||
}] | ||
|
||
def test_summarize_authors(): | ||
|
||
|