Skip to content

Commit

Permalink
Migrate all tests toward the mkdocs-test framework (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Franceschetti committed Oct 9, 2024
1 parent 59f82db commit 16be58d
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 1,389 deletions.
42 changes: 0 additions & 42 deletions mkdocs_macros/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,43 +712,6 @@ def render(self, markdown: str, force_rendering:bool=False) -> str:
else:
return error_message

def _save_debug_file(self, page:Page,
rendered_markdown:str) -> str:
"""
Saves a page to disk for debug/testing purposes,
with a reconstituted YAML front matter.
Argument:
- page: the Page (page.markdown contains the old markdown)
- rendered_mardkown (the new markdown)
Returns the saved document.
"""
dest_file = os.path.join(self.rendered_macros_dir,
page.file.src_path)
debug(f"Saving page '{page.title}' in destination file:",
dest_file)
# Create the subdirectory hierarchy if necessary
os.makedirs(os.path.dirname(dest_file), exist_ok=True)
if page.meta:
# recreate the YAML header:
yaml_values = yaml.dump(dict(page.meta),
default_flow_style=False, sort_keys=False)
document = '\n'.join([ '---',
YAML_HEADER_WARNING,
yaml_values.strip(),
'---',
rendered_markdown
])
else:
# re-generate the document with YAML header
document = rendered_markdown
# write on file:
debug("Saved ")
with open(dest_file, 'w') as f:
f.write(document)
return document


# ----------------------------------
# Standard Hooks for a mkdocs plugin
Expand Down Expand Up @@ -989,11 +952,6 @@ def on_page_markdown(self, markdown, page:Page,
for func in self.post_macro_functions:
func(self)

# save the rendered page, with its YAML header
if get_log_level('DEBUG'):
self._save_debug_file(page,
rendered_markdown=self.markdown)

return self.markdown

def on_post_build(self, config: config_options.Config):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# Initialization
# --------------------

VERSION_NUMBER = '1.3.3'
VERSION_NUMBER = '1.3.4'

# required if you want to run document/test
# pip install 'mkdocs-macros-plugin[test]'
TEST_REQUIRE = ['mkdocs-macros-test', 'mkdocs-material>=6.2',
'mkdocs-include-markdown-plugin']
'mkdocs-include-markdown-plugin', 'mkdocs-test']

# --------------------
# Setup
Expand Down
Loading

0 comments on commit 16be58d

Please sign in to comment.