Skip to content

Commit 724bc10

Browse files
committed
🧪 Added nested needs test with schema
1 parent 89664a8 commit 724bc10

6 files changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# serializer version: 1
2+
# name: test_nested[test_app0]
3+
list([
4+
'''
5+
Need 'SPEC_002' has schema violations:
6+
Severity: violation
7+
Need path: SPEC_002 > parent_needs
8+
Schema path: spec-has-req-parent[0] > validate > network > parent_needs > contains
9+
Schema message: Too few valid links of type 'parent_needs' (0 < 1) [sn_schema_violation.network_contains_too_few]
10+
11+
''',
12+
])
13+
# ---
14+
# name: test_nested[test_app0].1
15+
list([
16+
NeedItem(core={'id': 'REQ_001', 'type': 'req', 'type_name': 'Requirement', 'type_prefix': 'R_', 'type_color': '#BFD8D2', 'type_style': 'node', 'title': 'Req lvl 1', 'status': 'open', 'tags': [], 'constraints': [], 'collapse': False, 'hide': False, 'style': None, 'layout': None, 'external_css': 'external_link', 'arch': {}, 'has_dead_links': False, 'has_forbidden_dead_links': False, 'sections': ('TEST DOCUMENT',), 'signature': None}, extras={'duration': None, 'completion': None, 'query': '', 'specific': '', 'max_amount': '', 'max_content_lines': '', 'id_prefix': '', 'user': '', 'created_at': '', 'updated_at': '', 'closed_at': '', 'service': '', 'url': '', 'avatar': '', 'params': '', 'prefix': '', 'url_postfix': ''}, links={'links': [], 'parent_needs': []}, backlinks={'links': ['TEST_001'], 'parent_needs': ['SPEC_001']}, source=NeedItemSourceDirective(docname='index', lineno=4, lineno_content=8), content=NeedsContent(doctype='.rst', content='Content before\n\n.. spec:: Spec lvl 2\n :id: SPEC_001\n :status: open\n\n .. test:: Test lvl 3\n :id: TEST_001\n :status: open\n :links: REQ_001\n\nContent after', pre_content=None, post_content=None, jinja_content=False, template=None, pre_template=None, post_template=None), parts={}, modifications=(), dynamic_fields={}),
17+
NeedItem(core={'id': 'SPEC_001', 'type': 'spec', 'type_name': 'Specification', 'type_prefix': 'S_', 'type_color': '#FEDCD2', 'type_style': 'node', 'title': 'Spec lvl 2', 'status': 'open', 'tags': [], 'constraints': [], 'collapse': False, 'hide': False, 'style': None, 'layout': None, 'external_css': 'external_link', 'arch': {}, 'has_dead_links': False, 'has_forbidden_dead_links': False, 'sections': ('TEST DOCUMENT',), 'signature': None}, extras={'duration': None, 'completion': None, 'query': '', 'specific': '', 'max_amount': '', 'max_content_lines': '', 'id_prefix': '', 'user': '', 'created_at': '', 'updated_at': '', 'closed_at': '', 'service': '', 'url': '', 'avatar': '', 'params': '', 'prefix': '', 'url_postfix': ''}, links={'links': [], 'parent_needs': ['REQ_001']}, backlinks={'links': [], 'parent_needs': ['TEST_001']}, source=NeedItemSourceDirective(docname='index', lineno=10, lineno_content=14), content=NeedsContent(doctype='.rst', content='.. test:: Test lvl 3\n :id: TEST_001\n :status: open\n :links: REQ_001', pre_content=None, post_content=None, jinja_content=False, template=None, pre_template=None, post_template=None), parts={}, modifications=(), dynamic_fields={}),
18+
NeedItem(core={'id': 'TEST_001', 'type': 'test', 'type_name': 'Test Case', 'type_prefix': 'T_', 'type_color': '#DCB239', 'type_style': 'node', 'title': 'Test lvl 3', 'status': 'open', 'tags': [], 'constraints': [], 'collapse': False, 'hide': False, 'style': None, 'layout': None, 'external_css': 'external_link', 'arch': {}, 'has_dead_links': False, 'has_forbidden_dead_links': False, 'sections': ('TEST DOCUMENT',), 'signature': None}, extras={'duration': None, 'completion': None, 'query': '', 'specific': '', 'max_amount': '', 'max_content_lines': '', 'id_prefix': '', 'user': '', 'created_at': '', 'updated_at': '', 'closed_at': '', 'service': '', 'url': '', 'avatar': '', 'params': '', 'prefix': '', 'url_postfix': ''}, links={'links': ['REQ_001'], 'parent_needs': ['SPEC_001']}, backlinks={'links': [], 'parent_needs': []}, source=NeedItemSourceDirective(docname='index', lineno=14, lineno_content=19), content=NeedsContent(doctype='.rst', content='', pre_content=None, post_content=None, jinja_content=False, template=None, pre_template=None, post_template=None), parts={}, modifications=(), dynamic_fields={}),
19+
NeedItem(core={'id': 'SPEC_002', 'type': 'spec', 'type_name': 'Specification', 'type_prefix': 'S_', 'type_color': '#FEDCD2', 'type_style': 'node', 'title': 'Spec lvl 1', 'status': 'open', 'tags': [], 'constraints': [], 'collapse': False, 'hide': False, 'style': None, 'layout': None, 'external_css': 'external_link', 'arch': {}, 'has_dead_links': False, 'has_forbidden_dead_links': False, 'sections': ('TEST DOCUMENT',), 'signature': None}, extras={'duration': None, 'completion': None, 'query': '', 'specific': '', 'max_amount': '', 'max_content_lines': '', 'id_prefix': '', 'user': '', 'created_at': '', 'updated_at': '', 'closed_at': '', 'service': '', 'url': '', 'avatar': '', 'params': '', 'prefix': '', 'url_postfix': ''}, links={'links': [], 'parent_needs': []}, backlinks={'links': [], 'parent_needs': []}, source=NeedItemSourceDirective(docname='index', lineno=21, lineno_content=25), content=NeedsContent(doctype='.rst', content='', pre_content=None, post_content=None, jinja_content=False, template=None, pre_template=None, post_template=None), parts={}, modifications=(), dynamic_fields={}),
20+
])
21+
# ---
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project = "nested needs test"
2+
extensions = ["sphinx_needs", "sphinxcontrib.plantuml"]
3+
needs_from_toml = "ubproject.toml"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
TEST DOCUMENT
2+
=============
3+
4+
.. req:: Req lvl 1
5+
:id: REQ_001
6+
:status: open
7+
8+
Content before
9+
10+
.. spec:: Spec lvl 2
11+
:id: SPEC_001
12+
:status: open
13+
14+
.. test:: Test lvl 3
15+
:id: TEST_001
16+
:status: open
17+
:links: REQ_001
18+
19+
Content after
20+
21+
.. spec:: Spec lvl 1
22+
:id: SPEC_002
23+
:status: open
24+
25+
.. needtable:: Table from sphinx-needs 'needtable' directive
26+
:columns: id;title;tags;links;parent_need;parent_needs
27+
28+
.. needflow::
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"$defs": {
3+
"type-req": {
4+
"properties": {
5+
"type": { "const": "req" }
6+
}
7+
},
8+
"type-spec": {
9+
"properties": {
10+
"type": { "const": "spec" }
11+
}
12+
},
13+
"type-test": {
14+
"properties": {
15+
"type": { "const": "test" }
16+
}
17+
}
18+
},
19+
"schemas": [
20+
{
21+
"id": "spec-has-req-parent",
22+
"select": {
23+
"$ref": "#/$defs/type-spec"
24+
},
25+
"validate": {
26+
"network": {
27+
"parent_needs": {
28+
"contains": {
29+
"local": {
30+
"$ref": "#/$defs/type-req"
31+
}
32+
},
33+
"minContains": 1,
34+
"maxContains": 1
35+
}
36+
}
37+
}
38+
}
39+
]
40+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[needs]
2+
build_json = true
3+
schema_definitions_from_json = "schemas.json"

‎tests/test_nested.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
from sphinx.testing.util import SphinxTestApp
5+
6+
from sphinx_needs.api.need import get_needs_view
7+
8+
9+
@pytest.mark.parametrize(
10+
"test_app",
11+
[{"buildername": "html", "srcdir": "doc_test/doc_nested", "no_plantuml": False}],
12+
indirect=True,
13+
)
14+
def test_nested(test_app: SphinxTestApp, snapshot, get_warnings_list):
15+
app = test_app
16+
app.build()
17+
warnings = get_warnings_list(app)
18+
assert warnings == snapshot
19+
20+
needs = list(get_needs_view(app).values())
21+
assert needs == snapshot

0 commit comments

Comments
 (0)