Skip to content

Commit f3595b7

Browse files
add enable_creation_date test
1 parent 3f85e7a commit f3595b7

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# test page
22

33
Tag <mark>\{\{ git_revision_date_localized \}\}</mark> renders as: {{ git_revision_date_localized }}
4+
5+
Tag <mark>\{\{ git_creation_date_localized \}\}</mark> renders as: {{ git_creation_date_localized }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
site_name: test gitrevisiondatelocalized_plugin
2+
use_directory_urls: true
3+
4+
plugins:
5+
- search
6+
- git-revision-date-localized:
7+
enable_creation_date: True

tests/test_builds.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def setup_commit_history(testproject_path):
120120
os.chdir(testproject_path)
121121

122122
try:
123+
repo.git.add("docs/page_with_tag.md")
124+
repo.git.commit(message="add homepage", author=author, date="1500854705 -0700")
125+
123126
repo.git.add("mkdocs.yml")
124127
repo.git.commit(message="add mkdocs", author=author)
125128

@@ -139,8 +142,12 @@ def setup_commit_history(testproject_path):
139142
repo.git.commit(message="second page", author=author)
140143
repo.git.add("docs/index.md")
141144
repo.git.commit(message="homepage", author=author)
145+
146+
file_name = os.path.join(testproject_path, "docs/page_with_tag.md")
147+
with open(file_name, "a") as the_file:
148+
the_file.write("awa\n")
142149
repo.git.add("docs/page_with_tag.md")
143-
repo.git.commit(message="homepage", author=author)
150+
repo.git.commit(message="update homepage", author=author)
144151
os.chdir(cwd)
145152
except:
146153
os.chdir(cwd)
@@ -204,7 +211,22 @@ def validate_build(testproject_path, plugin_config: dict = {}):
204211
)
205212

206213
searches = [x in contents for x in date_formats.values()]
207-
assert any(searches), "No correct date formats output was found"
214+
assert any(searches), "No correct revision date formats output was found"
215+
216+
if plugin_config.get("enable_creation_date"):
217+
commit_timestamp=repo.get_git_commit_timestamp(
218+
path=str(testproject_path / "docs/page_with_tag.md"),
219+
is_first_commit=True,
220+
fallback_to_build_date=plugin_config.get("fallback_to_build_date"),
221+
)
222+
assert commit_timestamp == 1500854705
223+
date_formats = repo.get_revision_date_for_file(
224+
commit_timestamp=commit_timestamp,
225+
locale=plugin_config.get("locale"), # type: ignore
226+
)
227+
228+
searches = [x in contents for x in date_formats.values()]
229+
assert any(searches), "No correct creation date formats output was found"
208230

209231

210232
def validate_mkdocs_file(temp_path: str, mkdocs_yml_file: str):
@@ -273,6 +295,11 @@ def test_build_no_options(tmp_path):
273295
validate_mkdocs_file(tmp_path, "tests/fixtures/basic_project/mkdocs.yml")
274296

275297

298+
def test_build_creation_date(tmp_path):
299+
# Enable plugin with no extra options set
300+
validate_mkdocs_file(tmp_path, "tests/fixtures/basic_project/mkdocs_creation_date.yml")
301+
302+
276303
def test_build_locale_plugin(tmp_path):
277304
# Enable plugin with plugin locale set to 'nl'
278305
validate_mkdocs_file(

0 commit comments

Comments
 (0)