-
Notifications
You must be signed in to change notification settings - Fork 71
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 (#1103)
- Loading branch information
1 parent
f6b090a
commit eda2264
Showing
5 changed files
with
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea | ||
*.iml | ||
.venv* | ||
.pvenv | ||
.nox | ||
|
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,53 @@ | ||
Only directive Test | ||
===================== | ||
|
||
.. req:: always_here_1 | ||
:id: REQ_000 | ||
|
||
out of only is alwasy here | ||
|
||
.. only:: tag_a | ||
|
||
.. req:: only_tag_a | ||
:id: REQ_001 | ||
|
||
I shall not appear if not running tag_a | ||
|
||
.. req:: only_tag_a_again | ||
:id: REQ_001_1 | ||
|
||
need within need under only, shall neither appear if not running tag_a | ||
|
||
|
||
.. only:: tag_b | ||
|
||
.. req:: only_tag_b | ||
:id: REQ_002 | ||
|
||
I shall not appear if not running tag_b | ||
|
||
|
||
.. only:: tag_a or tag_b | ||
|
||
.. req:: only_tag_a_or_b | ||
:id: REQ_003 | ||
|
||
I shall not appear if not running either tag_a or tag_b | ||
|
||
|
||
.. req:: always_here_2 | ||
:id: REQ_004 | ||
|
||
I shall always appear | ||
|
||
|
||
Needs table | ||
-------------- | ||
|
||
.. needtable:: | ||
|
||
|
||
Needs list | ||
-------------- | ||
.. needlist:: | ||
|
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,100 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
def is_need_present(need_id, html, needs_list, is_present=True): | ||
assert ( | ||
is_need_in_html(need_id, html) is is_present | ||
), f"{need_id} should {'not ' if not is_present else ''}be present in html" | ||
|
||
assert ( | ||
is_need_in_needtable(need_id, html) is is_present | ||
), f"{need_id} should {'not ' if not is_present else ''}be present in needtable" | ||
|
||
assert ( | ||
is_need_in_needlist(need_id, html) is is_present | ||
), f"{need_id} should {'not ' if not is_present else ''}be present in needlist" | ||
|
||
assert ( | ||
need_id in needs_list | ||
) is is_present, f"{need_id} should {'not ' if not is_present else ''}be present in needs.json" | ||
|
||
|
||
def is_need_in_html(need_id, html): | ||
return 'id="' + need_id + '">' in html | ||
|
||
|
||
def is_need_in_needtable(need_id, html): | ||
return ( | ||
'<td class="needs_id"><p><a class="reference internal" href="#' + need_id + '">' + need_id + "</a></p></td>" | ||
in html | ||
) | ||
|
||
|
||
def is_need_in_needlist(need_id, html): | ||
return '<div class="line"><a class="reference external" href="#' + need_id + '">' + need_id + ":" in html | ||
|
||
|
||
def get_json_needs(needs_file: Path): | ||
with open(needs_file) as file: | ||
data = json.load(file) | ||
return data["versions"][data["current_version"]]["needs"] | ||
|
||
|
||
@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 = get_json_needs(Path(app.outdir, "needs.json")) | ||
|
||
is_need_present("REQ_000", html, needs_list) | ||
is_need_present("REQ_001", html, needs_list) | ||
is_need_present("REQ_001_1", html, needs_list) | ||
is_need_present("REQ_002", html, needs_list, False) | ||
is_need_present("REQ_003", html, needs_list) | ||
is_need_present("REQ_004", html, needs_list) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_app", | ||
[ | ||
{"buildername": "html", "srcdir": "doc_test/doc_directive_only", "tags": ["tag_b"]}, | ||
], | ||
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 = get_json_needs(Path(app.outdir, "needs.json")) | ||
|
||
is_need_present("REQ_000", html, needs_list) | ||
is_need_present("REQ_001", html, needs_list, False) | ||
is_need_present("REQ_001_1", html, needs_list, False) | ||
is_need_present("REQ_002", html, needs_list) | ||
is_need_present("REQ_003", html, needs_list) | ||
is_need_present("REQ_004", html, 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 = get_json_needs(Path(app.outdir, "needs.json")) | ||
|
||
is_need_present("REQ_000", html, needs_list) | ||
is_need_present("REQ_001", html, needs_list, False) | ||
is_need_present("REQ_001_1", html, needs_list, False) | ||
is_need_present("REQ_002", html, needs_list, False) | ||
is_need_present("REQ_003", html, needs_list, False) | ||
is_need_present("REQ_004", html, needs_list) |