From b4a6ddd751edac231be90f443732e54da3888eda Mon Sep 17 00:00:00 2001 From: daveoconnor Date: Fri, 8 Nov 2024 13:31:32 -0800 Subject: [PATCH] Added support for release notes asciidoc macros (#1082) (#1377) Related to ticket #1082, this adds support for asciidoc macros to emulate macros from qbk. Macro support is documented at https://github.com/cppalliance/asciidoctor-boost/ --- conftest.py | 16 ++++++++++++++++ core/asciidoc.py | 2 +- core/tests/content/asciidoc.adoc | 24 ++++++++++++++++++++++++ core/tests/content/asciidoc.html | 27 +++++++++++++++++++++++++++ core/tests/test_asciidoc.py | 19 +++++++++++++++++++ docker/Dockerfile | 2 +- justfile | 3 +++ pytest.ini | 2 ++ 8 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 core/tests/content/asciidoc.adoc create mode 100644 core/tests/content/asciidoc.html diff --git a/conftest.py b/conftest.py index e9402a98..03313239 100644 --- a/conftest.py +++ b/conftest.py @@ -25,3 +25,19 @@ def temp_image_file(): tmp_file.seek(0) file_obj = DjangoFile(open(tmp_file.name, mode="rb"), name="tmp_file") yield file_obj.seek(0) + + +def pytest_collection_modifyitems(config, items): + """ + Adds support for skipping tests based on the presence of markers: + - asciidoctor + """ + keywordexpr = config.option.keyword + markexpr = config.option.markexpr + if keywordexpr or markexpr: + return # let pytest handle this + + skip_asciidoctor = pytest.mark.skip(reason="asciidoctor not selected") + for item in items: + if "asciidoctor" in item.keywords: + item.add_marker(skip_asciidoctor) diff --git a/core/asciidoc.py b/core/asciidoc.py index 8d70612b..c607d79f 100644 --- a/core/asciidoc.py +++ b/core/asciidoc.py @@ -15,7 +15,7 @@ def convert_adoc_to_html(input): :param input: The contents of the AsciiDoc file """ result = subprocess.run( - ["asciidoctor", "-e", "-o", "-", "-"], + ["asciidoctor", "-r", "asciidoctor_boost", "-e", "-o", "-", "-"], check=True, capture_output=True, text=True, diff --git a/core/tests/content/asciidoc.adoc b/core/tests/content/asciidoc.adoc new file mode 100644 index 00000000..25eb1e85 --- /dev/null +++ b/core/tests/content/asciidoc.adoc @@ -0,0 +1,24 @@ +:noheader: +:nofooter: +:notitle: + +// standard asciidoctor content +Some text + +https://asciidoctor.org - automatic! + +https://asciidoctor.org[Asciidoctor] + +devel@discuss.example.org + +// boost specific asciidoc content + +boost_at:/tools/boost/boost_1_75_0/libs/algorithm/doc/html/algorithm/[Algorithm Library] + +boost_phrase:library[Hi!] + +PR: boost_gh:pr[geometry,1247] + +Issue: boost_gh:issue[geometry,1231] + +boost_phrase:library[Charconv:,/libs/charconv/] diff --git a/core/tests/content/asciidoc.html b/core/tests/content/asciidoc.html new file mode 100644 index 00000000..ecd4c91a --- /dev/null +++ b/core/tests/content/asciidoc.html @@ -0,0 +1,27 @@ +
+

Some text

+
+
+

https://asciidoctor.org - automatic!

+
+
+

Asciidoctor

+
+
+

devel@discuss.example.org

+
+
+

Algorithm Library

+
+
+

Hi!

+
+
+

PR: PR#1247

+
+
+

Issue: #1231

+
+
+

Charconv:

+
diff --git a/core/tests/test_asciidoc.py b/core/tests/test_asciidoc.py index 70199447..4fc596a2 100644 --- a/core/tests/test_asciidoc.py +++ b/core/tests/test_asciidoc.py @@ -1,5 +1,9 @@ +from os import getcwd, makedirs from unittest.mock import patch +import pytest + + from core.asciidoc import convert_adoc_to_html @@ -14,6 +18,7 @@ def test_convert_adoc_to_html_subprocess(): assert result == "html_content" +@pytest.mark.asciidoctor def test_convert_adoc_to_html_content(): """Test the process_adoc_to_html_content function.""" content = "sample" @@ -21,3 +26,17 @@ def test_convert_adoc_to_html_content(): result = convert_adoc_to_html(content) assert result == expected_html + + +@pytest.mark.asciidoctor +def test_convert_adoc_to_html_content_file(): + # for dev, change this to True, and update the test_pytest_asciidoctor run + # command to include "-v /tmp/asciidocs:/tmp/asciidocs" after "run" + generate_files_for_debugging = False + expected_output = open(f"{getcwd()}/core/tests/content/asciidoc.html").read() + adoc_file_path = f"{getcwd()}/core/tests/content/asciidoc.adoc" + output = convert_adoc_to_html(open(adoc_file_path).read()) + if generate_files_for_debugging: + makedirs("/tmp/asciidocs", exist_ok=True) + open("/tmp/asciidocs/tmp.html", "w").write(output) + assert output == expected_output diff --git a/docker/Dockerfile b/docker/Dockerfile index 6f7815b3..3ec1fd8c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -38,7 +38,7 @@ FROM python:3.11-slim AS release RUN apt update && apt install -y git libpq-dev ruby ruby-dev && rm -rf /var/lib/apt/lists/* # Install Asciidoctor -RUN gem install asciidoctor +RUN gem install asciidoctor asciidoctor-boost # Boostrap uv. RUN pip install 'uv>=0.2.27,<0.3' diff --git a/justfile b/justfile index e2ae32e6..af5f458c 100644 --- a/justfile +++ b/justfile @@ -49,6 +49,9 @@ alias shell := console @test_pytest: -docker compose run --rm web pytest -s +@test_pytest_asciidoctor: + -docker compose run --rm web pytest -m asciidoctor -s + @test: just test_pytest docker compose down diff --git a/pytest.ini b/pytest.ini index 8a098549..38aebf27 100644 --- a/pytest.ini +++ b/pytest.ini @@ -4,3 +4,5 @@ addopts = --reuse-db --no-migrations norecursedirs = .git config node_modules scss static templates static_deploy uploads frontend media kube docker config content .github .pytest_cache venv python_files = test_*.py +markers= + asciidoctor: indicating test involving local asciidoctor rendering