@@ -142,7 +142,7 @@ def setup_commit_history(testproject_path):
142142
143143 # page_with_tags contains tags we replace and test
144144 repo .git .add ("docs/page_with_tag.md" )
145- repo .git .commit (message = "add homepage" , author = author , date = "1500854705 -0700 " ) # Mon Jul 24 2017 00:05:05 GMT+0000
145+ repo .git .commit (message = "add homepage" , author = author , date = "1500854705" ) # Mon Jul 24 2017 00:05:05 GMT+0000
146146
147147 file_name = os .path .join (testproject_path , "docs/page_with_tag.md" )
148148 with open (file_name , "a" ) as the_file :
@@ -270,6 +270,33 @@ def validate_mkdocs_file(temp_path: str, mkdocs_yml_file: str):
270270 return testproject_path
271271
272272
273+
274+ MKDOCS_FILES = [
275+ 'basic_project/mkdocs_theme_no_locale.yml' ,
276+ 'basic_project/mkdocs.yml' ,
277+ 'basic_project/mkdocs_theme_timeago_locale.yml' ,
278+ 'basic_project/mkdocs_datetime.yml' ,
279+ 'basic_project/mkdocs_plugin_locale.yml' ,
280+ 'basic_project/mkdocs_with_override.yml' ,
281+ 'basic_project/mkdocs_theme_language.yml' ,
282+ 'basic_project/mkdocs_creation_date.yml' ,
283+ 'basic_project/mkdocs_theme_locale_disabled.yml' ,
284+ 'basic_project/mkdocs_timeago_locale.yml' ,
285+ 'basic_project/mkdocs_timeago.yml' ,
286+ 'basic_project/mkdocs_theme_timeago.yml' ,
287+ 'basic_project/mkdocs_fallback_to_build_date.yml' ,
288+ 'basic_project/mkdocs_theme_locale.yml' ,
289+ 'basic_project/mkdocs_locale.yml' ,
290+ 'basic_project/mkdocs_theme_timeago_override.yml' ,
291+ 'basic_project/mkdocs_theme_timeago_instant.yml' ,
292+ 'basic_project/mkdocs_exclude.yml'
293+ ]
294+
295+ INVALID_MKDOCS_FILES = [
296+ 'basic_project/mkdocs_unknown_type.yml' ,
297+ ]
298+
299+
273300# ##################################
274301# ########### Tests ################
275302# ##################################
@@ -286,11 +313,7 @@ def test_date_formats():
286313 }
287314
288315
289-
290-
291- @pytest .mark .parametrize ("mkdocs_file" , [
292- "basic_project/mkdocs.yml" ,
293- "basic_project/mkdocs_creation_date.yml" ])
316+ @pytest .mark .parametrize ("mkdocs_file" , MKDOCS_FILES , ids = lambda x : f"mkdocs file: { x } " )
294317def test_tags_are_replaced (tmp_path , mkdocs_file ):
295318 """
296319 Make sure the {{ }} tags are replaced properly.
@@ -302,17 +325,56 @@ def test_tags_are_replaced(tmp_path, mkdocs_file):
302325 result = build_docs_setup (testproject_path )
303326 assert result .exit_code == 0 , "'mkdocs build' command failed"
304327
328+ plugin_config = get_plugin_config_from_mkdocs (str (testproject_path / "mkdocs.yml" ))
305329 tags_file = testproject_path / "site/page_with_tag/index.html"
306330 contents = tags_file .read_text (encoding = "utf8" )
307- # Assert {{ git_revision_date_localized }} is replaced
308- assert re .search (r"January 23, 2022\<\/span.+" , contents )
309331
332+ # validate the build
333+ validate_build (
334+ testproject_path , plugin_config = plugin_config
335+ )
336+
337+ if plugin_config .get ("enabled" ) == False :
338+ return True
339+
340+ if plugin_config .get ("type" ) == "timeago" :
341+ pytest .skip ("Not necessary to test the JS library" )
342+
343+
344+ # the revision date was in 'setup_commit_history' was set to 1642911026 (Sun Jan 23 2022 04:10:26 GMT+0000)
345+ # Assert {{ git_revision_date_localized }} is replaced
346+ date_formats_revision_date = Util ()._date_formats (1642911026 ,
347+ locale = plugin_config .get ("locale" ),
348+ time_zone = plugin_config .get ("timezone" ))
349+ for k , v in date_formats_revision_date .items ():
350+ assert v is not None
351+ date = date_formats_revision_date .get (plugin_config .get ('type' ))
352+ assert re .search (rf"{ date } \<\/span.+" , contents )
353+
354+ # The last site revision was set in setup_commit_history to 1643911026 (Thu Feb 03 2022 17:57:06 GMT+0000)
310355 # Assert {{ git_site_revision_date_localized }} is replaced
311- assert re .search (r"February 3, 2022\<\/span.+" , contents )
356+ date_formats_revision_date = Util ()._date_formats (1643911026 ,
357+ locale = plugin_config .get ("locale" ),
358+ time_zone = plugin_config .get ("timezone" ))
359+ for k , v in date_formats_revision_date .items ():
360+ assert v is not None
361+ date = date_formats_revision_date .get (plugin_config .get ('type' ))
362+ assert re .search (rf"{ date } \<\/span.+" , contents )
312363
313364 # Note {{ git_creation_date_localized }} is only replaced when configured in the config
314- if mkdocs_file == "basic_project/mkdocs_creation_date.yml" :
315- assert re .search (r"July 24, 2017\<\/span.+" , contents )
365+ if plugin_config .get ("enable_creation_date" ):
366+ # The creation of page_with_tag.md was set in setup_commit_history to 1500854705 ( Mon Jul 24 2017 00:05:05 GMT+0000 )
367+ date_formats_revision_date = Util ()._date_formats (1500854705 ,
368+ locale = plugin_config .get ("locale" ),
369+ time_zone = plugin_config .get ("timezone" ))
370+ for k , v in date_formats_revision_date .items ():
371+ assert v is not None
372+ date = date_formats_revision_date .get (plugin_config .get ('type' ))
373+ assert re .search (rf"{ date } \<\/span.+" , contents )
374+
375+
376+
377+
316378
317379
318380def test_git_not_available (tmp_path , recwarn ):
@@ -336,32 +398,6 @@ def test_git_not_available(tmp_path, recwarn):
336398 assert result .exit_code == 0
337399
338400
339- def test_build_no_options (tmp_path ):
340- # Enable plugin with no extra options set
341- validate_mkdocs_file (tmp_path , "tests/fixtures/basic_project/mkdocs.yml" )
342-
343-
344- def test_build_creation_date (tmp_path ):
345- # Enable plugin with no extra options set
346- validate_mkdocs_file (tmp_path , "tests/fixtures/basic_project/mkdocs_creation_date.yml" )
347-
348-
349- def test_build_locale_plugin (tmp_path ):
350- # Enable plugin with plugin locale set to 'nl'
351- validate_mkdocs_file (
352- tmp_path , "tests/fixtures/basic_project/mkdocs_plugin_locale.yml"
353- )
354-
355-
356- def test_build_locale_mkdocs (tmp_path ):
357- # Enable plugin with mkdocs locale set to 'fr'
358- validate_mkdocs_file (tmp_path , "tests/fixtures/basic_project/mkdocs_locale.yml" )
359-
360-
361- def test_build_material_theme_timeago (tmp_path ):
362- validate_mkdocs_file (
363- tmp_path , "tests/fixtures/basic_project/mkdocs_theme_timeago.yml"
364- )
365401
366402
367403def test_build_material_theme (tmp_path ):
@@ -396,6 +432,7 @@ def test_material_theme_locale(tmp_path):
396432 contents = index_file .read_text (encoding = "utf8" )
397433 assert re .search (r"Last update\:\s[<span class].+" , contents )
398434
435+
399436def test_material_theme_locale_disabled (tmp_path ):
400437 """
401438 When using mkdocs-material theme, test correct working
@@ -413,7 +450,6 @@ def test_material_theme_locale_disabled(tmp_path):
413450 assert re .search (r"Last update\:\s[<span class].+" , contents ) is None
414451
415452
416-
417453def test_material_theme_no_locale (tmp_path ):
418454 """
419455 When using mkdocs-material theme, test correct working
@@ -430,13 +466,6 @@ def test_material_theme_no_locale(tmp_path):
430466 assert re .search (r"Last update\:\s[<span class].+" , contents )
431467
432468
433- def test_type_timeago (tmp_path ):
434- validate_mkdocs_file (tmp_path , "tests/fixtures/basic_project/mkdocs_timeago.yml" )
435-
436-
437- def test_type_datetime (tmp_path ):
438- validate_mkdocs_file (tmp_path , "tests/fixtures/basic_project/mkdocs_datetime.yml" )
439-
440469
441470def test_type_unknown (tmp_path ):
442471 with pytest .raises (AssertionError ):
@@ -445,10 +474,6 @@ def test_type_unknown(tmp_path):
445474 )
446475
447476
448- def test_build_with_timezone (tmp_path ):
449- validate_mkdocs_file (
450- tmp_path , "tests/fixtures/basic_project/mkdocs_theme_timeago.yml"
451- )
452477
453478
454479def test_exclude_pages (tmp_path ):
0 commit comments