File: test_title_optional.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 (69 lines) | stat: -rw-r--r-- 1,894 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from pathlib import Path

import pytest

from tests.util import extract_needs_from_html

NS = {"html": "http://www.w3.org/1999/xhtml"}


class HtmlNeed:
    """Helper class to parse HTML needs"""

    def __init__(self, need):
        self.need = need

    @property
    def id(self):
        # return self.need.find(".//html:span[@class='needs-id']", NS)._children[0].text
        return self.need.find(".//html:a[@class='reference internal']", NS).text

    @property
    def title(self):
        title = self.need.find(".//html:span[@class='needs_title']", NS)
        return (
            title[0].text if title is not None else None
        )  # title[0] aims to the span_data element


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

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

    assert needs[0].id == "R_12345"
    assert needs[0].title == "Scenario 1 Title"

    assert needs[1].id is not None
    assert needs[1].title == "Scenario 2 Title"

    assert needs[2].id == "R_12346"
    assert needs[2].title == "Scenario 3 Title"

    assert needs[3].id is not None
    assert needs[3].title == "Scenario 4 Title"

    assert needs[4].id == "R_12347"
    assert needs[4].title is None

    assert needs[5].id is not None
    assert needs[5].title is None

    assert needs[6].id == "R_12348"
    assert needs[6].title == "Title matches this"

    assert needs[7].id is not None
    assert needs[7].title == "Title should match this"

    assert needs[8].id == "R_12349"
    assert needs[8].title == "First sentence is really long so this should be..."

    assert needs[9].id is not None
    assert needs[9].title == "First sentence is really long so this should be..."