@@ -259,6 +259,59 @@ def test_retrieve_authors(tmp_path):
259259 }]
260260 os .chdir (cwd )
261261
262+ def test_mkdocs_in_git_subdir (tmp_path ):
263+ """
264+ Sometimes `mkdocs.yml` is not in the root of the repo.
265+ We need to make sure things still work in this edge case.
266+
267+ tmp_path/testproject
268+ website/
269+ ├── docs/
270+ └── mkdocs.yml
271+ """
272+ testproject_path = tmp_path / 'testproject'
273+
274+ shutil .copytree ('tests/basic_setup/docs' , testproject_path / 'website' / 'docs' )
275+ shutil .copyfile ("tests/basic_setup/mkdocs.yml" , testproject_path / 'website' / 'mkdocs.yml' )
276+
277+ cwd = os .getcwd ()
278+ os .chdir (str (testproject_path ))
279+
280+ # Create file
281+ file_name = str (testproject_path / 'website' / 'new-file' )
282+ with open (file_name , 'w' ) as the_file :
283+ the_file .write ('Hello\n ' )
284+
285+ # Create git repo and commit file
286+ r = gitpython .Repo .init (testproject_path )
287+ r .index .add ([file_name ])
288+ author = gitpython .
Actor (
'Tim' ,
'[email protected] ' )
289+ r .index .commit ("initial commit" , author = author )
290+
291+ # Test retrieving author
292+ repo_instance = repo .Repo ()
293+ repo_instance .set_config (DEFAULT_CONFIG )
294+ repo_instance .page (file_name )
295+
296+ authors = repo_instance .get_authors ()
297+ assert len (authors ) == 1
298+ # We don't want to test datetime
299+ authors = util .page_authors (authors , file_name )
300+ authors [0 ]['last_datetime' ] = None
301+
302+ assert authors == [{
303+ 'name' : "Tim" ,
304+ 305+ 'last_datetime' : None ,
306+ 'lines' : 1 ,
307+ 'lines_all_pages' : 1 ,
308+ 'contribution' : '100.0%' ,
309+ 'contribution_all_pages' : '100.0%'
310+ }]
311+
312+ os .chdir (cwd )
313+
314+
262315def test_summarize_authors ():
263316 """
264317 Test summary functions.
@@ -292,3 +345,4 @@ def test_summarize_authors():
292345 # # Now contribution is displayed
293346 # summary = util.Util().summarize(authors, config)
294347 # assert summary == "<span class='git-authors'><a href='mailto:[email protected] '>Tim</a> (64.23%), <a href='mailto:[email protected] '>Tom</a> (35.77%)</span>" 348+
0 commit comments