Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix dynamic functions in needextract need #1273

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sphinx_needs/directives/needextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
used_filter_paragraph,
)
from sphinx_needs.filter_common import FilterBase, process_filters
from sphinx_needs.functions.functions import find_and_replace_node_content
from sphinx_needs.layout import build_need_repr
from sphinx_needs.logging import log_warning
from sphinx_needs.utils import add_doc, remove_node_from_tree
Expand Down Expand Up @@ -202,6 +203,7 @@ def _build_needextract(
env.resolve_references(dummy_need, extract_data["docname"], app.builder) # type: ignore[arg-type]

dummy_need.attributes["ids"].append(need_data["id"])
find_and_replace_node_content(dummy_need, env, need_data)
rendered_node = build_need_repr(
dummy_need, # type: ignore[arg-type]
need_data,
Expand Down
4 changes: 4 additions & 0 deletions tests/doc_test/needextract_with_nested_needs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Test

Another, child spec

This is id [[copy("id")]]

.. spec:: Child spec
:id: SPEC_1_1

Expand All @@ -27,5 +29,7 @@ Test
:id: SPEC_1_1_2

awesome grandchild spec number 2.

This is grandchild id [[copy("id")]]

Some parent text
75 changes: 52 additions & 23 deletions tests/test_needextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,24 @@
from pathlib import Path

import pytest
from lxml import html as html_parser


@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_needextract"}],
[
{
"buildername": "html",
"srcdir": "doc_test/doc_needextract",
"no_plantuml": True,
}
],
indirect=True,
)
def test_needextract_filter_options(test_app):
import subprocess

app = test_app

srcdir = Path(app.srcdir)
out_dir = srcdir / "_build"

out = subprocess.run(
["sphinx-build", "-M", "html", srcdir, out_dir], capture_output=True
)
assert out.returncode == 0


@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_needextract"}],
indirect=True,
)
def test_needextract_basic_run(test_app):
def test_needextract_basic(test_app):
app = test_app
app.build()

from lxml import html as html_parser
assert not app._warning.getvalue()

def run_checks(checks, html_path):
html_path = str(Path(app.outdir, html_path))
Expand Down Expand Up @@ -66,3 +53,45 @@ def run_checks(checks, html_path):

index_html = Path(app.outdir, "check_need_refs.html").read_text()
assert "Awesome Sphinx-Needs" in index_html


@pytest.mark.parametrize(
"test_app",
[
{
"buildername": "html",
"srcdir": "doc_test/needextract_with_nested_needs",
"no_plantuml": True,
}
],
indirect=True,
)
def test_needextract_with_nested_needs(test_app):
app = test_app
app.build()
assert not app._warning.getvalue()

needextract_html = Path(app.outdir, "needextract.html").read_text()

# ensure that the needs exist and that their hrefs point to the correct location
assert (
'<span class="needs-id"><a class="reference internal" href="index.html#SPEC_1" title="SPEC_1">SPEC_1</a>'
in needextract_html
)
assert (
'<span class="needs-id"><a class="reference internal" href="index.html#SPEC_1_1" title="SPEC_1_1">SPEC_1_1</a>'
in needextract_html
)
assert (
'<span class="needs-id"><a class="reference internal" '
'href="index.html#SPEC_1_1_1" title="SPEC_1_1_1">SPEC_1_1_1</a>'
in needextract_html
)
assert (
'<span class="needs-id"><a class="reference internal" '
'href="index.html#SPEC_1_1_2" title="SPEC_1_1_2">SPEC_1_1_2</a>'
in needextract_html
)

assert "This is id SPEC_1" in needextract_html
assert "This is grandchild id SPEC_1_1_2" in needextract_html
34 changes: 0 additions & 34 deletions tests/test_needextract_with_nested_needs.py

This file was deleted.

Loading