1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
"""
Specific for MkDocs Projects
(C) Laurent Franceschetti 2024
"""
import warnings
import json
import subprocess
from super_collections import SuperDict
from mkdocs_test import DocProject, MkDocsPage
class MacrosPage(MkDocsPage):
"Specific for MkDocs-Macros"
def has_error(self:MkDocsPage):
"Predicate: check whether the page has an error"
return self.find_text('Macro Rendering Error')
@property
def is_rendered(self):
"Accomodate earlier formulation"
warnings.warn("The page property `.is_rendered` is DEPRECATED "
"use `.is_markdown_rendered()` instead.",
UserWarning, stacklevel=2)
return self.is_markdown_rendered()
class MacrosDocProject(DocProject):
"Specific for MkDocs-Macros"
def build(self, strict:bool=False) -> subprocess.CompletedProcess:
"""
Build the documentation, to perform the tests
Verbose is forced to True, to get the variables, functions and filters
"""
super().build(strict=strict, verbose=True)
@property
def pages(self) -> dict[MacrosPage]:
"List of pages"
pages = super().pages
return {key: MacrosPage(value) for key, value in pages.items()}
@property
def macros_plugin(self):
"Information on the plugin"
return self.get_plugin('macros')
# ------------------------------------
# Get information through the payload
# ------------------------------------
@property
def variables(self):
"Return the variables"
try:
return self._variables
except AttributeError:
entry = self.find_entry("config variables",
source='macros',
severity='debug')
if entry and entry.payload:
self._variables = SuperDict(json.loads(entry.payload))
else:
print(entry)
raise ValueError("Cannot find variables")
return self._variables
@property
def macros(self):
"Return the macros"
try:
return self._macros
except AttributeError:
entry = self.find_entry("config macros",
source='macros',
severity='debug')
if entry and entry.payload:
self._macros = SuperDict(json.loads(entry.payload))
else:
print(entry)
raise ValueError("Cannot find macros")
return self._macros
@property
def filters(self):
"Return the filters"
try:
return self._filters
except AttributeError:
entry = self.find_entry("config filters",
source='macros',
severity='debug')
if entry and entry.payload:
self._filters = SuperDict(json.loads(entry.payload))
else:
print(entry)
raise ValueError("Cannot find filters")
return self._filters
|