Skip to content

Commit c716530

Browse files
fpozzobonGuts
authored andcommitted
Adding tests, removed first space
Co-authored-by: Julien Guts <[email protected]>
1 parent 421a4db commit c716530

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

src/mkdocs_git_authors_plugin/git/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def _process_git_log(self, sha, commit) -> None:
256256
# skip author as already available in Commit object
257257
continue
258258

259-
result = re.search(r"Co-authored-by:(.*) <(.*)>", line)
259+
result = re.search(r"Co-authored-by: (.*) <(.*)>", line)
260260
if result is not None and result.group(1) != "" and result.group(2) != "":
261261
# Extract co-authors from the commit
262262
co_author = self.repo().author(result.group(1), result.group(2))
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Test with co-authors
1+
# Test with co-authors mentioned
22

33
Page authors: {{ git_page_authors }}
4-
5-
----
6-
7-
Site authors: {{ git_site_authors }}

tests/test_basic.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
]
4646

4747

48-
49-
5048
def build_docs_setup(mkdocs_path, output_path) -> Result:
5149
runner = CliRunner()
5250
return runner.invoke(
@@ -144,6 +142,25 @@ def test_ignore_authors_working(tmp_path) -> None:
144142
assert not re.search("Julien", contents)
145143

146144

145+
def test_co_authors_working(tmp_path) -> None:
146+
result = build_docs_setup("tests/basic_setup/mkdocs_ignore_authors.yml", tmp_path)
147+
assert (
148+
result.exit_code == 0
149+
), f"'mkdocs build' command failed. Error: {result.stdout}"
150+
151+
page_file = tmp_path / "page_with_co_authors/index.html"
152+
assert page_file.exists(), f"{page_file} does not exist"
153+
154+
contents = page_file.read_text()
155+
assert re.search("<span class='git-page-authors", contents)
156+
assert re.search(
157+
"<a href='mailto:12074690\[email protected]'>Fabien Pozzobon</a>",
158+
contents,
159+
)
160+
assert re.search("<a href='mailto:[email protected]'>John Doe</a>", contents)
161+
assert not re.search("Julien", contents)
162+
163+
147164
def test_exclude_working_with_genfiles(tmp_path) -> None:
148165
"""
149166
A warning for uncommited files should not show up
@@ -331,11 +348,12 @@ def test_mkapi_v20x(tmp_path) -> None:
331348
assert True
332349

333350

334-
@pytest.mark.skipif(sys.version_info < (3, 7) or sys.version_info > (3, 9), reason="Requires Python 3.7 or higher")
335351
@pytest.mark.skipif(
336-
not (
337-
Version(mkdocs.__version__) < Version("1.6")
338-
),
352+
sys.version_info < (3, 7) or sys.version_info > (3, 9),
353+
reason="Requires Python 3.7 or higher",
354+
)
355+
@pytest.mark.skipif(
356+
not (Version(mkdocs.__version__) < Version("1.6")),
339357
reason="Requires mkdocs >= 1.6",
340358
)
341359
def test_mkapi_v1(tmp_path) -> None:
@@ -354,12 +372,12 @@ def test_mkapi_v1(tmp_path) -> None:
354372
contents,
355373
)
356374

375+
357376
def test_custom_docs_dir(tmp_path):
358377

359378
testproject_path = tmp_path / "testproject"
360379
shutil.copytree("tests/custom_docs_dir", testproject_path)
361380

362-
363381
# init git inside the docs directory
364382
with working_directory(str(testproject_path / "documentation")):
365383
# setup git history
@@ -380,4 +398,3 @@ def test_custom_docs_dir(tmp_path):
380398

381399
contents = index_file.read_text()
382400
assert re.search("<span class='git-page-authors", contents)
383-

tests/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def setup_commit_history(testproject_path):
129129
repo.git.commit(message="homepage", author=author)
130130
repo.git.add("docs/page_with_co_authors.md")
131131
repo.git.commit(
132-
message="co-authors commit\nCo-authored-by: Test Person <[email protected]>\nCo-authored-by: John Doe <jdoe@john.com>",
132+
message="co-authors commit\nCo-authored-by: Test Person <[email protected]>\nCo-authored-by: Roger Doe <rdoe@john.com>",
133133
author=author,
134134
)
135135
os.chdir(str(cwd))

0 commit comments

Comments
 (0)