File: test_extra_options.py

package info (click to toggle)
sphinx-needs 5.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 11,924 kB
  • sloc: python: 21,132; javascript: 187; makefile: 89; sh: 29; xml: 10
file content (54 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import json
import re
from pathlib import Path

import pytest
from sphinx.util.console import strip_colors
from syrupy.filters import props


@pytest.mark.parametrize(
    "test_app",
    [{"buildername": "html", "srcdir": "doc_test/extra_options", "no_plantuml": True}],
    indirect=True,
)
def test_custom_attributes_appear(test_app, snapshot):
    app = test_app
    app.build()

    warnings = strip_colors(app._warning.getvalue()).splitlines()
    assert warnings == [
        'WARNING: extra_option "introduced" already registered. [needs.config]',
        "WARNING: extra_option is a dict, but does not contain a 'name' key: {} [needs.config]",
        "WARNING: extra_option is not a string or dict: 1 [needs.config]",
    ]

    needs = json.loads(Path(app.outdir, "needs.json").read_text("utf8"))
    assert needs == snapshot(exclude=props("created", "project", "creator"))

    html = Path(app.outdir, "index.html").read_text()

    # Custom options should appear
    # assert 'introduced: <cite>1.0.0</cite>' in html
    assert '<span class="needs_data">1.5.1' in html
    assert '<span class="needs_data">1.1.1' in html
    assert '<span class="needs_data">component_b' in html

    tables = re.findall("(<table .*?</table>)", html, re.DOTALL)
    assert len(tables) == 4

    # First table should have all requirements
    assert "R_12345" in tables[2]
    assert "R_12346" in tables[2]
    assert all(column in tables[2] for column in ("Introduced", "Updated", "Impacts"))

    # Second table should only have component A requirements
    assert "R_12345" in tables[3]
    assert "R_12346" not in tables[3]

    # Need list should only have component B requirements
    items = re.findall(
        '(<div class="line-block" id="needlist-index-.*?</div>)', html, re.DOTALL
    )
    assert len(items) == 1
    assert "R_12346" in items[0]