From 56418062b60c13faa4bbc15ab75fe6301c531fba Mon Sep 17 00:00:00 2001 From: Laurent Franceschetti Date: Fri, 18 Oct 2024 21:59:44 +0200 Subject: [PATCH] Fixed incompatibility with d2 module (#249) - Added test case --- CHANGELOG.md | 2 +- mkdocs_macros/util.py | 6 +++- pyproject.toml | 1 + test/plugin_d2/.cache/plugin/d2/db.db | Bin 0 -> 32768 bytes test/plugin_d2/__init__.py | 4 +++ test/plugin_d2/docs/index.md | 12 +++++++ test/plugin_d2/mkdocs.yaml | 17 ++++++++++ test/plugin_d2/test_t2.py | 43 ++++++++++++++++++++++++++ 8 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 test/plugin_d2/.cache/plugin/d2/db.db create mode 100644 test/plugin_d2/__init__.py create mode 100644 test/plugin_d2/docs/index.md create mode 100644 test/plugin_d2/mkdocs.yaml create mode 100644 test/plugin_d2/test_t2.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a106a2..44a3e6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 1.3.7, 2024-10-17 +## 1.3.6, 2024-10-17 * Added: complete test framework, using pytest and Mkdocs-Test (#244) A number of automated test cases are implemented. * Changed: move from setup.py to pyproject.toml (#250) diff --git a/mkdocs_macros/util.py b/mkdocs_macros/util.py index 09f48dc..6796dfc 100644 --- a/mkdocs_macros/util.py +++ b/mkdocs_macros/util.py @@ -137,7 +137,11 @@ def default(self, obj: Any) -> Any: return super().default(obj) except TypeError: debug(f"json: cannot encode {obj.__class__}") - return str(obj) + try: + return str(obj) + except Exception: + # in case something happens along the line + return f"!Non printable object: {obj.__class__}" diff --git a/pyproject.toml b/pyproject.toml index 54ce588..5731e53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ test = [ "mkdocs-macros-test", "mkdocs-material>=6.2", "mkdocs-test", + "mkdocs-d2-plugin" ] [project.entry-points."mkdocs.plugins"] diff --git a/test/plugin_d2/.cache/plugin/d2/db.db b/test/plugin_d2/.cache/plugin/d2/db.db new file mode 100644 index 0000000000000000000000000000000000000000..04f07d612a3ef69ceb93a8ad13407b9bd922cb33 GIT binary patch literal 32768 zcmeHPNsr@5c9yFOc6Y&;@x^yq1sh#fDYuN*G8ONEk>MNEk>MNEk>MNEk>MNEk>MNErCFG4OxCJ^bwdwdtMcn=p_tkT8%i zkT8%ikT8%ikT8%ikT8%ikT8%i@LUF7rCxz|{QsMr0X&zmq+Y^6!a%}6!a%}6!a%}6 z!a%}6!a%}6!a%~nuaJR1Bv-;f!a%}6!a%}6!a%}6!a%}6!a%}6!a%}6!oZ(B18-9Q z{oB{6*WdjHoL&4T_3?LGT|+jKWvixfo5ruOG$I+IIadwkHtjlcmQ4Td(?@%wAfTdQ z-=-Iiv%W@A&-1Rl+?8o5D1l)Z3TmVeRj#+1YOKyx#LML}>X)XGIWY`{VpqkhQW{xX zk}X*qiL%#{==23gHE+{fPBkXrgXogvq>+s(d9=B`O=Ad#5Csy+=kn=;dg}Z(Jtwlh z9-=1LKvj?x2x(51rI{oZr956LkeDFlWf{*CbAl*gg*4)+b7ygz24HDqA*ss3xlKdV zqpU2B;fS9cC0am51n2=DUxEIED~;@)au(x56mx;!Peg(=KWV8S*)LNiUh)L{DNbW~k|JOdM|GJz>k z%aIaZTYxeaWZSSl)r1MtYsuc25o$Ol!My9il!Hlyn)6h1ZqEpQ0kTX6KBS;LszHGs z*)@D2)nV4J4jzJw0bTGaxtU&drl9MT-!l%9(P$}4Z@8*@vmB3seC-Y-6b)}F1ue6% ze-%nKnGNVLc*dwo(^vk^Yqcm1%B@PE|8xuDDt4XnIF|An3|#~HjR+FZKDubS&o;YI zpGFr&DYt~u5TdNmEEGH?4>e_q(cm4ZNBLa`{CEdD0x*_hd=Y)D zcmqE00^dG0pi4a()?_A13)qbV6jNP_29$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s.yaml new file mode 100644 index 0000000..0cf7e00 --- /dev/null +++ b/test/plugin_d2/mkdocs.yaml @@ -0,0 +1,17 @@ + +# Documentation name +site_name: 'Compatibility with d2 plugin' + +# Your repository URL and name +repo_url: https://gitlab.com/karreg/mkdocs-macros-d2-issue +repo_name: mkdocs-macros-d2-issue + +# Plugins +plugins: + - search + - d2 + - macros + +# Documentation content +nav: + - Home: 'index.md' diff --git a/test/plugin_d2/test_t2.py b/test/plugin_d2/test_t2.py new file mode 100644 index 0000000..d27f20f --- /dev/null +++ b/test/plugin_d2/test_t2.py @@ -0,0 +1,43 @@ +""" +Testing the d2 project + +There was an incompatibility: +Error: The current file is not set for the '!relative' tag. It cannot be used in this context; the intended usage is within `markdown_extensions`. + +see https://github.com/fralau/mkdocs-macros-plugin/issues/249 + +Requires d2 + +(C) Laurent Franceschetti 2024 +""" + +REQUIRED = "d2" + +import pytest +import subprocess + +def is_d2_installed(): + try: + subprocess.run(["brew", "list", REQUIRED], check=True, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + return True + except subprocess.CalledProcessError: + return False + + +import test +from test.fixture import MacrosDocProject + + +@pytest.mark.skipif(not is_d2_installed(), reason="d2 is not installed") +def test_d2(): + """ + This test will run only if d2 library is installed; + otherwise the d2 plugin will not run + https://d2lang.com/tour/install/ + """ + project = MacrosDocProject() + project.build(strict=False) + # did not fail + print(project.build_result.stderr) + assert not project.build_result.returncode, "Failed when it should not" \ No newline at end of file