11"""
2- Note that pytest offers a `tmp_path`.
2+ Note that pytest offers a `tmp_path`.
33You can reproduce locally with
44
55```python
1616```
1717"""
1818
19+ import os
1920import re
2021import shutil
21- import os
22- import pytest
22+ from contextlib import contextmanager
23+ from typing import Any , Generator
2324
24- from click .testing import CliRunner
25- from mkdocs .__main__ import build_command
26- from git import Repo
2725import git as gitpython
28- from contextlib import contextmanager
26+ import pytest
27+ from click .testing import CliRunner , Result
28+ from git import Repo
29+ from mkdocs .__main__ import build_command
2930
3031SITES_THAT_SHOULD_SUCCEED = [
3132 "mkdocs.yml" ,
4041 "mkdocs_w_macros2.yml" ,
4142]
4243
44+
4345@contextmanager
44- def working_directory (path ):
46+ def working_directory (path ) -> Generator [ None , Any , None ] :
4547 """
4648 Temporarily change working directory.
4749 A context manager which changes the working directory to the given
@@ -62,20 +64,21 @@ def working_directory(path):
6264 os .chdir (prev_cwd )
6365
6466
65- def build_docs_setup (mkdocs_path , output_path ):
67+ def build_docs_setup (mkdocs_path , output_path ) -> Result :
6668 runner = CliRunner ()
6769 return runner .invoke (
6870 build_command , ["--config-file" , mkdocs_path , "--site-dir" , str (output_path )]
6971 )
7072
73+
7174@pytest .mark .parametrize (
7275 "mkdocs_file" ,
7376 SITES_THAT_SHOULD_SUCCEED ,
7477)
75- def test_basic_working (tmp_path , mkdocs_file ) :
78+ def test_basic_working (tmp_path , mkdocs_file : str ) -> None :
7679 """
7780 combination with mkdocs-macros-plugin lead to error.
78- See https://github.com/timvink/mkdocs-git-authors-plugin/issues/60
81+ See https://github.com/timvink/mkdocs-git-authors-plugin/issues/60
7982 """
8083 result = build_docs_setup (f"tests/basic_setup/{ mkdocs_file } " , tmp_path )
8184 assert result .exit_code == 0 , (
@@ -90,12 +93,11 @@ def test_basic_working(tmp_path, mkdocs_file):
9093 assert re .
search (
'<a href="mailto:[email protected] ">Tim Vink</a>' ,
contents )
9194
9295
93- def test_custom_href (tmp_path ):
94- """
95- """
96+ def test_custom_href (tmp_path ) -> None :
97+ """ """
9698 result = build_docs_setup ("tests/basic_setup/mkdocs_custom_href.yml" , tmp_path )
9799 assert result .exit_code == 0 , (
98- "'mkdocs build' command failed. Error: %s" % result .stdout
100+ "'mkdocs build' command failed. Error: %s" % result .stdout
99101 )
100102
101103 index_file = tmp_path / "index.html"
@@ -104,16 +106,20 @@ def test_custom_href(tmp_path):
104106 contents = index_file .read_text ()
105107 assert re .search ("<span class='git-page-authors" , contents )
106108 # Checking Page Authors
107- assert re .search ((r"<p>Page authors:.*<a href='https://teams.microsoft.com/l/chat/0/0\?"
108- "[email protected] '>Tim Vink</a>.*<\/p>" ),
contents )
109+ assert re .search (
110+ r"<p>Page authors:.*<a href='https://teams.microsoft.com/l/chat/0/0\?"
111+ r"[email protected] '>Tim Vink</a>.*</p>" ,
112+ contents ,
113+ )
109114 # Checking Site Authors
110- assert re .search (('<li><a href="https://teams.microsoft.com/l/chat/0/0\?'
111- '[email protected] ">Tim Vink</a><\/li>' ),
contents )
112-
113-
115+ assert re .search (
116+ r'<li><a href="https://teams.microsoft.com/l/chat/0/0\?'
117+ r'[email protected] ">Tim Vink</a></li>' ,
118+ contents ,
119+ )
114120
115- def test_no_email (tmp_path ):
116121
122+ def test_no_email (tmp_path ) -> None :
117123 result = build_docs_setup ("tests/basic_setup/mkdocs_no_email.yml" , tmp_path )
118124 assert result .exit_code == 0 , (
119125 "'mkdocs build' command failed. Error: %s" % result .stdout
@@ -127,9 +133,7 @@ def test_no_email(tmp_path):
127133 assert re .search ("<li>Tim Vink</li>" , contents )
128134
129135
130-
131- def test_exclude_working (tmp_path ):
132-
136+ def test_exclude_working (tmp_path ) -> None :
133137 result = build_docs_setup ("tests/basic_setup/mkdocs_exclude.yml" , tmp_path )
134138 assert result .exit_code == 0 , (
135139 "'mkdocs build' command failed. Error: %s" % result .stdout
@@ -142,12 +146,10 @@ def test_exclude_working(tmp_path):
142146 assert not re .search ("<span class='git-page-authors" , contents )
143147
144148
145-
146- def test_ignore_authors_working (tmp_path ):
147-
149+ def test_ignore_authors_working (tmp_path ) -> None :
148150 result = build_docs_setup ("tests/basic_setup/mkdocs_ignore_authors.yml" , tmp_path )
149151 assert result .exit_code == 0 , (
150- "'mkdocs build' command failed. Error: %s" % result .stdout
152+ "'mkdocs build' command failed. Error: %s" % result .stdout
151153 )
152154
153155 page_file = tmp_path / "page_with_tag/index.html"
@@ -159,18 +161,15 @@ def test_ignore_authors_working(tmp_path):
159161 assert not re .search ("Julien" , contents )
160162
161163
162-
163- def test_exclude_working_with_genfiles (tmp_path ):
164+ def test_exclude_working_with_genfiles (tmp_path ) -> None :
164165 """
165166 A warning for uncommited files should not show up
166167 when those uncommited files are excluded.
167168 """
168-
169+
169170 testproject_path = tmp_path / "testproject_genfiles"
170171
171- shutil .copytree (
172- "tests/basic_setup/docs" , str (testproject_path / "docs" )
173- )
172+ shutil .copytree ("tests/basic_setup/docs" , str (testproject_path / "docs" ))
174173 shutil .copyfile (
175174 "tests/basic_setup/mkdocs_genfiles.yml" ,
176175 str (testproject_path / "mkdocs.yml" ),
@@ -199,18 +198,21 @@ def test_exclude_working_with_genfiles(tmp_path):
199198 str (testproject_path / "mkdocs.yml" ), str (testproject_path / "site" )
200199 )
201200 assert result .exit_code == 0 , (
202- "'mkdocs build' command failed. Error: %s" % result .stdout
201+ "'mkdocs build' command failed. Error: %s" % result .stdout
203202 )
204203
205204 # files generated ourselves right before build but not committed, should not generate warnings
206205 assert "manually_created.md has not been committed yet." not in result .stdout
207- assert "manually_created_infolder.md has not been committed yet." not in result .stdout
208-
209-
206+ assert (
207+ "manually_created_infolder.md has not been committed yet."
208+ not in result .stdout
209+ )
210210
211- def test_enabled_working (tmp_path ):
212211
213- result = build_docs_setup ("tests/basic_setup/mkdocs_complete_material_disabled.yml" , tmp_path )
212+ def test_enabled_working (tmp_path ) -> None :
213+ result = build_docs_setup (
214+ "tests/basic_setup/mkdocs_complete_material_disabled.yml" , tmp_path
215+ )
214216 assert result .exit_code == 0 , (
215217 "'mkdocs build' command failed. Error: %s" % result .stdout
216218 )
@@ -222,11 +224,10 @@ def test_enabled_working(tmp_path):
222224 assert not re .search ("<span class='git-page-authors" , contents )
223225
224226
225-
226- def test_project_with_no_commits (tmp_path ):
227+ def test_project_with_no_commits (tmp_path ) -> None :
227228 """
228229 Structure:
229-
230+
230231 tmp_path/testproject
231232 website/
232233 ├── docs/
@@ -253,12 +254,10 @@ def test_project_with_no_commits(tmp_path):
253254 )
254255
255256
256-
257-
258- def test_building_empty_site (tmp_path ):
257+ def test_building_empty_site (tmp_path ) -> None :
259258 """
260259 Structure:
261-
260+
262261 ```
263262 tmp_path/testproject
264263 website/
@@ -288,11 +287,10 @@ def test_building_empty_site(tmp_path):
288287 )
289288
290289
291-
292- def test_fallback (tmp_path ):
290+ def test_fallback (tmp_path ) -> None :
293291 """
294292 Structure:
295-
293+
296294 ```
297295 tmp_path/testproject
298296 website/
@@ -311,7 +309,6 @@ def test_fallback(tmp_path):
311309 )
312310
313311 with working_directory (str (testproject_path )):
314-
315312 result = build_docs_setup (
316313 str (testproject_path / "website/mkdocs.yml" ), str (testproject_path / "site" )
317314 )
0 commit comments