|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | + |
| 7 | +def get_json_needs(needs_file: Path): |
| 8 | + with open(needs_file, "r") as file: |
| 9 | + data = json.load(file) |
| 10 | + return data["versions"][data["current_version"]]["needs"] |
| 11 | + |
| 12 | +@pytest.mark.parametrize( |
| 13 | + "test_app", |
| 14 | + [ |
| 15 | + {"buildername": "html", "srcdir": "doc_test/doc_directive_only", "tags": ["tag_a"]}, |
| 16 | + ], |
| 17 | + indirect=True, |
| 18 | +) |
| 19 | +def test_need_excluded_under_only_a(test_app): |
| 20 | + app = test_app |
| 21 | + app.build() |
| 22 | + html = Path(app.outdir, "index.html").read_text() |
| 23 | + |
| 24 | + assert "req_001" in html |
| 25 | + assert "req_002" not in html |
| 26 | + assert "req_003" in html |
| 27 | + assert "req_004" in html |
| 28 | + |
| 29 | + needs_list = get_json_needs(Path(app.outdir, "needs.json")) |
| 30 | + |
| 31 | + assert not needs_list["req_001"]["excluded_by_only"] |
| 32 | + assert needs_list["req_002"]["excluded_by_only"] |
| 33 | + assert not needs_list["req_003"]["excluded_by_only"] |
| 34 | + assert not needs_list["req_004"]["excluded_by_only"] |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.parametrize( |
| 38 | + "test_app", |
| 39 | + [ |
| 40 | + {"buildername": "html", "srcdir": "doc_test/doc_directive_only", "tags": ["tag_a"]}, |
| 41 | + ], |
| 42 | + indirect=True, |
| 43 | +) |
| 44 | +def test_need_excluded_under_only_b(test_app): |
| 45 | + app = test_app |
| 46 | + app.build() |
| 47 | + html = Path(app.outdir, "index.html").read_text() |
| 48 | + |
| 49 | + assert "req_001" not in html |
| 50 | + assert "req_002" in html |
| 51 | + assert "req_003" in html |
| 52 | + assert "req_004" in html |
| 53 | + |
| 54 | + needs_list = get_json_needs(Path(app.outdir, "needs.json")) |
| 55 | + |
| 56 | + assert needs_list["req_001"]["excluded_by_only"] |
| 57 | + assert not needs_list["req_002"]["excluded_by_only"] |
| 58 | + assert not needs_list["req_003"]["excluded_by_only"] |
| 59 | + assert not needs_list["req_004"]["excluded_by_only"] |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.parametrize("test_app", [{"buildername": "html", "srcdir": "doc_test/doc_directive_only"}], indirect=True) |
| 63 | +def test_need_excluded_under_only_no_tag(test_app): |
| 64 | + app = test_app |
| 65 | + app.build() |
| 66 | + html = Path(app.outdir, "index.html").read_text() |
| 67 | + |
| 68 | + assert "req_001" not in html |
| 69 | + assert "req_002" not in html |
| 70 | + assert "req_003" not in html |
| 71 | + assert "req_004" in html |
| 72 | + |
| 73 | + needs_list = get_json_needs(Path(app.outdir, "needs.json")) |
| 74 | + |
| 75 | + assert needs_list["req_001"]["excluded_by_only"] |
| 76 | + assert needs_list["req_002"]["excluded_by_only"] |
| 77 | + assert needs_list["req_003"]["excluded_by_only"] |
| 78 | + assert not needs_list["req_004"]["excluded_by_only"] |
0 commit comments