|
9 | 9 | >>> os.mkdir(tmp_path)
|
10 | 10 | """
|
11 | 11 |
|
| 12 | +# ############################################################################# |
| 13 | +# ########## Libraries ############# |
| 14 | +# ################################## |
| 15 | + |
12 | 16 | # standard lib
|
13 | 17 | import logging
|
14 | 18 | import os
|
15 | 19 | import re
|
16 | 20 | import shutil
|
17 | 21 |
|
18 |
| -# 3rd partu |
| 22 | +# MkDocs |
| 23 | +from mkdocs.__main__ import build_command |
| 24 | +from mkdocs.config import load_config |
| 25 | + |
| 26 | +# other 3rd party |
19 | 27 | import git
|
20 | 28 | import pytest
|
21 | 29 | import yaml
|
22 | 30 | from click.testing import CliRunner
|
23 |
| -from mkdocs.__main__ import build_command |
24 | 31 |
|
25 | 32 | # package module
|
26 | 33 | from mkdocs_git_revision_date_localized_plugin.plugin import (
|
27 | 34 | GitRevisionDateLocalizedPlugin,
|
28 | 35 | )
|
29 | 36 | from mkdocs_git_revision_date_localized_plugin.util import Util
|
30 | 37 |
|
31 |
| -# GLOBALS |
| 38 | +# ############################################################################# |
| 39 | +# ######## Globals ################# |
| 40 | +# ################################## |
32 | 41 |
|
33 |
| -plugin_name = "git-revision-date-localized" |
| 42 | +PLUGIN_NAME = "git-revision-date-localized" |
34 | 43 |
|
35 | 44 | # custom log level to get plugin info messages
|
36 | 45 | logging.basicConfig(level=logging.INFO)
|
37 | 46 |
|
38 |
| -# HELPERS |
| 47 | +# ############################################################################# |
| 48 | +# ########## Helpers ############### |
| 49 | +# ################################## |
39 | 50 | def get_locale_from_config(mkdocs_path):
|
40 | 51 | # instanciate plugin
|
41 |
| - plg = GitRevisionDateLocalizedPlugin() |
42 |
| - |
43 |
| - # return yaml.load(open(mkdocs_path, "rb"), Loader=yaml.Loader) |
44 |
| - cfg = yaml.load(open(mkdocs_path, "rb"), Loader=yaml.Loader) |
45 |
| - logging.info("Fixture configuration loaded: " + str(cfg)) |
| 52 | + cfg_mkdocs = load_config(mkdocs_path) |
46 | 53 |
|
47 |
| - # get plugin config |
48 |
| - if "plugins" in cfg and plugin_name not in cfg.get("plugins"): |
49 |
| - t = [i for i in cfg.get("plugins") if isinstance(i, dict) and plugin_name in i] |
50 |
| - plg.config = t[0].get(plugin_name, {}) |
51 |
| - elif "plugins" in cfg and plugin_name in cfg.get("plugins"): |
52 |
| - plg.config = cfg.get(plugin_name, {}) |
53 |
| - else: |
54 |
| - pass |
| 54 | + plugins = cfg_mkdocs.get("plugins") |
| 55 | + plugin_loaded = plugins.get(PLUGIN_NAME) |
55 | 56 |
|
56 |
| - # use plugin config loader |
57 |
| - plg.on_config(cfg) |
| 57 | + cfg = plugin_loaded.on_config(cfg_mkdocs) |
| 58 | + logging.info("Fixture configuration loaded: " + str(cfg)) |
58 | 59 |
|
59 |
| - assert plg.locale is not None, "Locale should never be None after plugin is loaded" |
| 60 | + assert ( |
| 61 | + plugin_loaded.config.get("locale") is not None |
| 62 | + ), "Locale should never be None after plugin is loaded" |
60 | 63 |
|
61 |
| - return plg.locale |
| 64 | + logging.info( |
| 65 | + "Locale '%s' determined from %s" |
| 66 | + % (plugin_loaded.config.get("locale"), mkdocs_path) |
| 67 | + ) |
| 68 | + return plugin_loaded.config.get("locale") |
62 | 69 |
|
63 | 70 |
|
64 | 71 | def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
|
@@ -193,8 +200,7 @@ def validate_build(testproject_path, project_locale: str):
|
193 | 200 |
|
194 | 201 | repo = Util(testproject_path)
|
195 | 202 | date_formats = repo.get_revision_date_for_file(
|
196 |
| - path=testproject_path / "docs/page_with_tag.md", |
197 |
| - locale=project_locale |
| 203 | + path=testproject_path / "docs/page_with_tag.md", locale=project_locale |
198 | 204 | )
|
199 | 205 |
|
200 | 206 | searches = [re.search(x, contents) for x in date_formats.values()]
|
@@ -225,9 +231,9 @@ def validate_mkdocs_file(temp_path: str, mkdocs_yml_file: str):
|
225 | 231 | return testproject_path
|
226 | 232 |
|
227 | 233 |
|
228 |
| -#### Tests #### |
229 |
| - |
230 |
| - |
| 234 | +# ############################################################################# |
| 235 | +# ########### Tests ################ |
| 236 | +# ################################## |
231 | 237 | def test_date_formats():
|
232 | 238 | u = Util()
|
233 | 239 | assert u._date_formats(1582397529) == {
|
|
0 commit comments