Skip to content

Commit aeabd29

Browse files
authored
Merge pull request #2274 from strictdoc-project/stanislaw/docs
[[NODE]] migration: extend project statistics and query syntax to support [[SECTION]]
2 parents 03fb9d6 + a743cd7 commit aeabd29

File tree

8 files changed

+56
-14
lines changed

8 files changed

+56
-14
lines changed

strictdoc/backend/sdoc/models/node.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ def has_multiline_fields(self) -> bool:
244244
return True
245245
return False
246246

247+
def has_any_text_nodes(self) -> bool:
248+
# The workaround: hasattr(...) makes mypy happy.
249+
return any(
250+
node_.__class__.__name__ == "SDocNode"
251+
and hasattr(node_, "node_type")
252+
and node_.node_type == "TEXT"
253+
for node_ in self.section_contents
254+
)
255+
247256
#
248257
# Reserved fields
249258
#

strictdoc/core/query_engine/query_object.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ def _evaluate(self, node: SDocElementIF, expression: Any) -> bool:
153153
isinstance(node, SDocNode) and node.node_type == "REQUIREMENT"
154154
)
155155
if isinstance(expression, NodeIsSectionExpression):
156-
return isinstance(node, SDocSection)
156+
return (
157+
isinstance(node, SDocNode) and node.node_type == "SECTION"
158+
) or isinstance(node, SDocSection)
157159
if isinstance(expression, NodeIsRootExpression):
158160
if isinstance(node, SDocNode):
159161
return node.is_root
@@ -295,10 +297,12 @@ def _evaluate_node_contains(
295297
raise NotImplementedError # pragma: no cover
296298

297299
def _evaluate_node_contains_any_text(self, node: SDocElementIF) -> bool:
298-
if not isinstance(node, SDocSection):
300+
if not isinstance(node, SDocSection) and not (
301+
isinstance(node, SDocNode) and node.node_type == "SECTION"
302+
):
299303
raise TypeError(
300304
f"node.contains_any_text can be only called on "
301-
f"Section objects, got: {node.__class__.__name__}. To fix "
305+
f"SECTION objects, got: {node.__class__.__name__}. To fix "
302306
f"the error, prepend your query with node.is_section."
303307
)
304308
return node.has_any_text_nodes()

strictdoc/core/traceability_index_builder.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import glob
44
import os
55
import sys
6-
from time import sleep
76
from typing import Dict, Iterator, List, Optional, Set, Union
87

98
from textx import TextXSyntaxError
@@ -399,12 +398,9 @@ def print_line(text: str):
399398
"document grammar. "
400399
"See the migration guide for more details:\n"
401400
"https://strictdoc.readthedocs.io/en/latest/latest/docs/strictdoc_01_user_guide.html#SECTION-UG-NODE-MIGRATION\n"
402-
"This warning will become an error in 2025 Q3. "
403-
"Sleeping for 5 seconds..."
401+
"This warning will become an error in 2025 Q3."
404402
)
405403

406-
sleep(5)
407-
408404
if isinstance(node, SDocNode):
409405
try:
410406
SDocValidator.validate_node(

strictdoc/export/html/generators/project_statistics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def export(
3737
for node in document_iterator.all_content(
3838
print_fragments=False, print_fragments_from_files=False
3939
):
40-
if isinstance(node, SDocSection):
40+
if isinstance(node, SDocSection) or (
41+
isinstance(node, SDocNode) and node.node_type == "SECTION"
42+
):
4143
document_tree_stats.total_sections += 1
4244
if not node.has_any_text_nodes():
4345
document_tree_stats.sections_without_text_nodes += 1

tests/end2end/screens/project_statistics/view_project_statistics/input.sdoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ TITLE: Requirement title
3333
STATEMENT: Requirement statement. TBC
3434

3535
[/SECTION]
36+
37+
[[SECTION]]
38+
TITLE: New kind of section
39+
40+
[[/SECTION]]

tests/end2end/screens/project_statistics/view_project_statistics/test_case.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
class Test(E2ECase):
1717
expected_search_results = [
18-
("search-total-sections", 1),
19-
("search-sections-without-any-text", 1),
18+
("search-total-sections", 2),
19+
("search-sections-without-any-text", 2),
2020
("search-total-requirements", 5),
2121
("search-requirements-with-no-uid", 2),
2222
(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[DOCUMENT]
2+
TITLE: Hello world doc
3+
4+
[[SECTION]]
5+
TITLE: Section 1 (with text)
6+
7+
[TEXT]
8+
STATEMENT: >>>
9+
Text
10+
<<<
11+
12+
[[/SECTION]]
13+
14+
[[SECTION]]
15+
TITLE: Section 2 (with text)
16+
17+
[TEXT]
18+
STATEMENT: >>>
19+
Text
20+
<<<
21+
22+
[[/SECTION]]
23+
24+
[[SECTION]]
25+
TITLE: Section 3 (without text)
26+
27+
[[/SECTION]]

tests/integration/features/project_statistics/10_metric_sections_without_text/test.itest

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ RUN: %check_exists --file "%S/Output/html/project_statistics.html"
55

66
RUN: %cat "%S/Output/html/project_statistics.html" | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
77
CHECK-HTML: Total sections
8-
CHECK-HTML: 3
8+
CHECK-HTML: 6
99
CHECK-HTML: Sections without any text
10-
CHECK-HTML: 1
10+
CHECK-HTML: 2
1111
CHECK-HTML: Total requirements
12-
CHECK-HTML: 1

0 commit comments

Comments
 (0)