From 8c1def976cb68aa195edea2056d6ee3ee01a6d82 Mon Sep 17 00:00:00 2001 From: Bruno Bord Date: Tue, 9 Jun 2026 17:58:22 +0200 Subject: [PATCH] added an option to remove random messages from the build output refs #4 --- pyproject.toml | 1 + src/writeadoc/main.py | 25 +++++++++++------ tests/test_cli_build.py | 60 +++++++++++++++++++++++++++++++++++++++++ uv.lock | 14 ++++++++++ 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 tests/test_cli_build.py diff --git a/pyproject.toml b/pyproject.toml index a5dc62e..3f1c817 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ GitHub = "https://github.com/jpsca/writeadoc" dev = [ "ipdb>=0.13.13", "pytest-cov>=7.0.0", + "pytest-mock>=3.15.1", "ruff>=0.12.4", "tox-uv", "ty>=0.0.1a15", diff --git a/src/writeadoc/main.py b/src/writeadoc/main.py index fa3fcde..094ee9f 100644 --- a/src/writeadoc/main.py +++ b/src/writeadoc/main.py @@ -133,11 +133,17 @@ def cli(self): default=False, help="Generate a `llms.txt` file with all the markdown content", ) + build_parser.add_argument( + "--boring", + action="store_true", + default=False, + help="Remove the random messages from the log output" + ) args = parser.parse_args() if args.command == "build": - self.cli_build(archive=args.archive, llm=args.llm) + self.cli_build(archive=args.archive, llm=args.llm, boring=args.boring) elif args.command in (None, "run"): self.cli_run() else: @@ -168,7 +174,7 @@ def shutdown(*args): signal.signal(signal.SIGINT, shutdown) signal.signal(signal.SIGTERM, shutdown) - def cli_build(self, *, archive: bool, llm: bool = False) -> None: + def cli_build(self, *, archive: bool, llm: bool = False, boring: bool = False) -> None: """Build the documentation for deployment. """ if archive: @@ -182,23 +188,25 @@ def cli_build(self, *, archive: bool, llm: bool = False) -> None: variant.build_dir = self.build_dir variant.prefix = f"{self.prefix}/{prefix}" if self.prefix else prefix - self.build(devmode=False, llm=llm) + self.build(devmode=False, llm=llm, boring=boring) print("\nDocumentation built successfully.") if archive: print(f"Archived documentation is available in the `archive/{self.site.version}` folder.") else: print("Documentation is available in the `build` folder.") - def build(self, *, devmode: bool = True, llm: bool = False) -> None: - messages = get_random_messages(3) - print(f"{messages[0]}...") + def build(self, *, devmode: bool = True, llm: bool = False, boring: bool = False) -> None: + if not boring: + messages = get_random_messages(3) + print(f"{messages[0]}...") for variant in self.variants.values(): variant.build(devmode=devmode, llm=llm) print("Processing pages...") nav, pages = self.pages_processor.run(self.pages) - print(f"{messages[1]}...") + if not boring: + print(f"{messages[1]}...") self.site.nav = nav self.site.pages = pages @@ -209,7 +217,8 @@ def build(self, *, devmode: bool = True, llm: bool = False) -> None: print("Rendering pages...") for page in pages: self._render_page(page) - print(f"{messages[2]}...") + if not boring: + print(f"{messages[2]}...") if llm: print("Building llms.txt...") diff --git a/tests/test_cli_build.py b/tests/test_cli_build.py new file mode 100644 index 0000000..664a04c --- /dev/null +++ b/tests/test_cli_build.py @@ -0,0 +1,60 @@ +from unittest.mock import call + +import pytest + +from writeadoc.main import Docs + + +@pytest.fixture +def docs(tmp_root): + (tmp_root / "comp").mkdir() + (tmp_root / "comp" / "test.jx").write_text("

{{ content }}

") + + (tmp_root / "content" / "test.md").write_text( + """ +--- +title: Test Page +imports: + "Test": "test.jx" +--- +This **is** a test + +``` + + +``` +""".strip() + ) + + docs = Docs(tmp_root, pages=["test.md"]) + docs.catalog.add_folder(tmp_root / "comp") + return docs + + +def test_build_with_random_messages(mocker, docs): + mocker.patch( + "writeadoc.main.get_random_messages", return_value=["one", "two", "three"] + ) + mock_print = mocker.patch("builtins.print") + docs.build() + assert mock_print.call_count == 5 + mock_print.assert_has_calls([ + call("one..."), + call("Processing pages..."), + call("two..."), + call("Rendering pages..."), + call("three..."), + ]) + + +def test_build_with_no_random_messages(mocker, docs): + mocker.patch( + "writeadoc.main.get_random_messages", return_value=["one", "two", "three"] + ) + mock_print = mocker.patch("builtins.print") + docs.build(boring=True) + assert mock_print.call_count == 2 + mock_print.assert_has_calls([ + call("Processing pages..."), + call("Rendering pages..."), + ]) diff --git a/uv.lock b/uv.lock index c127591..8ce6e49 100644 --- a/uv.lock +++ b/uv.lock @@ -474,6 +474,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678", size = 22876, upload-time = "2026-03-21T20:11:14.438Z" }, ] +[[package]] +name = "pytest-mock" +version = "3.15.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/68/14/eb014d26be205d38ad5ad20d9a80f7d201472e08167f0bb4361e251084a9/pytest_mock-3.15.1.tar.gz", hash = "sha256:1849a238f6f396da19762269de72cb1814ab44416fa73a8686deac10b0d87a0f", size = 34036, upload-time = "2025-09-16T16:37:27.081Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5a/cc/06253936f4a7fa2e0f48dfe6d851d9c56df896a9ab09ac019d70b760619c/pytest_mock-3.15.1-py3-none-any.whl", hash = "sha256:0a25e2eb88fe5168d535041d09a4529a188176ae608a6d249ee65abc0949630d", size = 10095, upload-time = "2025-09-16T16:37:25.734Z" }, +] + [[package]] name = "python-dateutil" version = "2.9.0.post0" @@ -741,6 +753,7 @@ dependencies = [ dev = [ { name = "ipdb" }, { name = "pytest-cov" }, + { name = "pytest-mock" }, { name = "ruff" }, { name = "tox-uv" }, { name = "ty" }, @@ -766,6 +779,7 @@ requires-dist = [ dev = [ { name = "ipdb", specifier = ">=0.13.13" }, { name = "pytest-cov", specifier = ">=7.0.0" }, + { name = "pytest-mock", specifier = ">=3.15.1" }, { name = "ruff", specifier = ">=0.12.4" }, { name = "tox-uv" }, { name = "ty", specifier = ">=0.0.1a15" },