Skip to content

Commit e8d240d

Browse files
committed
Add test for git in docs direcotry
1 parent af27821 commit e8d240d

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

tests/test_basic.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def build_docs_setup(testproject_path):
177177
raise
178178

179179

180-
def validate_build(testproject_path, plugin_config: dict):
180+
def validate_build(testproject_path, plugin_config: dict = {}):
181181
"""
182182
Validates a build from a testproject
183183
@@ -196,7 +196,7 @@ def validate_build(testproject_path, plugin_config: dict):
196196
contents = page_with_tag.read_text(encoding="utf8")
197197
assert re.search(r"Markdown tag\:\s[<span>|\w].+", contents)
198198

199-
repo = Util(str(testproject_path))
199+
repo = Util(str(testproject_path / "docs"))
200200
date_formats = repo.get_revision_date_for_file(
201201
path=str(testproject_path / "docs/page_with_tag.md"),
202202
locale=plugin_config.get("locale"),
@@ -231,9 +231,11 @@ def validate_mkdocs_file(temp_path: str, mkdocs_yml_file: str):
231231
return testproject_path
232232

233233

234-
# #############################################################################
234+
# ##################################
235235
# ########### Tests ################
236236
# ##################################
237+
238+
237239
def test_date_formats():
238240
u = Util()
239241
assert u._date_formats(1582397529) == {
@@ -321,6 +323,44 @@ def test_type_unknown(tmp_path):
321323
validate_mkdocs_file(tmp_path, "tests/basic_setup/mkdocs_unknown_type.yml")
322324

323325

326+
def test_git_in_docs_dir(tmp_path):
327+
"""
328+
In https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/pull/31
329+
a use case is described where `.git` dir lives in `docs/`
330+
"""
331+
332+
testproject_path = setup_clean_mkdocs_folder(
333+
"tests/basic_setup/mkdocs.yml", tmp_path
334+
)
335+
336+
# Setup git repo in the 'docs' dir
337+
testproject_docs = str(testproject_path / "docs")
338+
repo = git.Repo.init(testproject_docs, bare=False)
339+
author = "Test Person <testtest@gmail.com>"
340+
341+
# Change the working directory
342+
cwd = os.getcwd()
343+
os.chdir(testproject_docs)
344+
345+
try:
346+
repo.git.add("page_with_tag.md")
347+
repo.git.commit(message="homepage", author=author)
348+
os.chdir(cwd)
349+
except:
350+
os.chdir(cwd)
351+
raise
352+
353+
# Build project
354+
result = build_docs_setup(testproject_path)
355+
assert result.exit_code == 0
356+
validate_build(
357+
testproject_path,
358+
plugin_config=get_plugin_config_from_mkdocs(
359+
str(testproject_path / "mkdocs.yml")
360+
),
361+
)
362+
363+
324364
def test_low_fetch_depth(tmp_path, caplog):
325365
"""
326366
On gitlab and github runners, a GIT might have a low fetch

0 commit comments

Comments
 (0)