forked from useblocks/sphinx-needs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exclude needs under only directive if required (useblocks#1103)
- Loading branch information
1 parent
73b961e
commit 6f788ef
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
extensions = ["sphinx_needs"] | ||
|
||
# also build the needs.json as some needs shall be hidden in it too | ||
needs_build_json = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Only directive Test | ||
===================== | ||
|
||
.. only:: tag_a | ||
|
||
.. req:: req_001 | ||
|
||
I shall not appear if not running tag_a | ||
|
||
.. only:: tag_b | ||
|
||
.. req:: req_002 | ||
|
||
I shall not appear if not running tag_b | ||
|
||
.. only:: tag_a or tag_b | ||
|
||
.. req:: req_003 | ||
|
||
I shall not appear if not running either tag_a or tag_b | ||
|
||
|
||
.. req:: req_004 | ||
|
||
I shall always appear | ||
|
||
|
||
.. needtable:: | ||
types: req |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_app", | ||
[ | ||
{"buildername": "html", "srcdir": "doc_test/doc_directive_only", "tags": ["tag_a"]}, | ||
], | ||
indirect=True, | ||
) | ||
def test_need_excluded_under_only_a(test_app): | ||
app = test_app | ||
app.build() | ||
html = Path(app.outdir, "index.html").read_text() | ||
needs_list = json.loads(Path(app.outdir, "needs.json").read_text()) | ||
|
||
assert "req_001" in html | ||
assert "req_002" not in html | ||
assert "req_003" in html | ||
assert "req_004" in html | ||
|
||
assert "req_001" in needs_list | ||
assert "req_002" not in needs_list | ||
assert "req_003" in needs_list | ||
assert "req_004" in needs_list | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_app", | ||
[ | ||
{"buildername": "html", "srcdir": "doc_test/doc_directive_only", "tags": ["tag_a"]}, | ||
], | ||
indirect=True, | ||
) | ||
def test_need_excluded_under_only_b(test_app): | ||
app = test_app | ||
app.build() | ||
html = Path(app.outdir, "index.html").read_text() | ||
needs_list = json.loads(Path(app.outdir, "needs.json").read_text()) | ||
|
||
assert "req_001" not in html | ||
assert "req_002" in html | ||
assert "req_003" in html | ||
assert "req_004" in html | ||
|
||
assert "req_001" not in needs_list | ||
assert "req_002" in needs_list | ||
assert "req_003" in needs_list | ||
assert "req_004" in needs_list | ||
|
||
|
||
@pytest.mark.parametrize("test_app", [{"buildername": "html", "srcdir": "doc_test/doc_directive_only"}], indirect=True) | ||
def test_need_excluded_under_only_no_tag(test_app): | ||
app = test_app | ||
app.build() | ||
html = Path(app.outdir, "index.html").read_text() | ||
needs_list = json.loads(Path(app.outdir, "needs.json").read_text()) | ||
|
||
assert "req_001" not in html | ||
assert "req_002" not in html | ||
assert "req_003" not in html | ||
assert "req_004" in html | ||
|
||
assert "req_001" not in needs_list | ||
assert "req_002" not in needs_list | ||
assert "req_003" not in needs_list | ||
assert "req_004" in needs_list |