|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | + |
| 7 | +def is_need_present(need_id, html, needs_list, is_present=True): |
| 8 | + 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" |
| 9 | + 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" |
| 10 | + 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" |
| 11 | + assert (need_id in needs_list) is is_present, f"{need_id} should {'not ' if not is_present else ''}be present in needs.json" |
| 12 | + |
| 13 | + |
| 14 | +def is_need_in_html(need_id, html): |
| 15 | + return 'id="' + need_id + '">' in html |
| 16 | + |
| 17 | + |
| 18 | +def is_need_in_needtable(need_id, html): |
| 19 | + return '<td class="needs_id"><p><a class="reference internal" href="#' + need_id + '">' + need_id + '</a></p></td>' in html |
| 20 | + |
| 21 | + |
| 22 | +def is_need_in_needlist(need_id, html): |
| 23 | + return '<div class="line"><a class="reference external" href="#' + need_id + '">' + need_id + ':' in html |
| 24 | + |
| 25 | + |
| 26 | +def get_json_needs(needs_file: Path): |
| 27 | + with open(needs_file) as file: |
| 28 | + data = json.load(file) |
| 29 | + return data["versions"][data["current_version"]]["needs"] |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize( |
| 33 | + "test_app", |
| 34 | + [ |
| 35 | + {"buildername": "html", "srcdir": "doc_test/doc_directive_only", "tags": ["tag_a"]}, |
| 36 | + ], |
| 37 | + indirect=True, |
| 38 | +) |
| 39 | +def test_need_excluded_under_only_a(test_app): |
| 40 | + app = test_app |
| 41 | + app.build() |
| 42 | + html = Path(app.outdir, "index.html").read_text() |
| 43 | + needs_list = get_json_needs(Path(app.outdir, "needs.json")) |
| 44 | + |
| 45 | + is_need_present("REQ_000", html, needs_list) |
| 46 | + is_need_present("REQ_001", html, needs_list) |
| 47 | + is_need_present("REQ_001_1", html, needs_list) |
| 48 | + is_need_present("REQ_002", html, needs_list, False) |
| 49 | + is_need_present("REQ_003", html, needs_list) |
| 50 | + is_need_present("REQ_004", html, needs_list) |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.parametrize( |
| 54 | + "test_app", |
| 55 | + [ |
| 56 | + {"buildername": "html", "srcdir": "doc_test/doc_directive_only", "tags": ["tag_b"]}, |
| 57 | + ], |
| 58 | + indirect=True, |
| 59 | +) |
| 60 | +def test_need_excluded_under_only_b(test_app): |
| 61 | + app = test_app |
| 62 | + app.build() |
| 63 | + html = Path(app.outdir, "index.html").read_text() |
| 64 | + needs_list = get_json_needs(Path(app.outdir, "needs.json")) |
| 65 | + |
| 66 | + is_need_present("REQ_000", html, needs_list) |
| 67 | + is_need_present("REQ_001", html, needs_list, False) |
| 68 | + is_need_present("REQ_001_1", html, needs_list, False) |
| 69 | + is_need_present("REQ_002", html, needs_list) |
| 70 | + is_need_present("REQ_003", html, needs_list) |
| 71 | + is_need_present("REQ_004", html, needs_list) |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize("test_app", [{"buildername": "html", "srcdir": "doc_test/doc_directive_only"}], indirect=True) |
| 75 | +def test_need_excluded_under_only_no_tag(test_app): |
| 76 | + app = test_app |
| 77 | + app.build() |
| 78 | + html = Path(app.outdir, "index.html").read_text() |
| 79 | + needs_list = get_json_needs(Path(app.outdir, "needs.json")) |
| 80 | + |
| 81 | + is_need_present("REQ_000", html, needs_list) |
| 82 | + is_need_present("REQ_001", html, needs_list, False) |
| 83 | + is_need_present("REQ_001_1", html, needs_list, False) |
| 84 | + is_need_present("REQ_002", html, needs_list, False) |
| 85 | + is_need_present("REQ_003", html, needs_list, False) |
| 86 | + is_need_present("REQ_004", html, needs_list) |
0 commit comments