Skip to content

Commit 6ea9a66

Browse files
authored
Merge pull request #164 from strictdoc-project/stanislaw/capella_fixture
reqif_bundle: add iterate_specification_hierarchy_for_conversion() helper
2 parents da65059 + 9436e08 commit 6ea9a66

2 files changed

Lines changed: 30 additions & 34 deletions

File tree

reqif/reqif_bundle.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import collections
2-
from typing import Deque, Dict, Iterator, List, Optional
2+
from typing import Deque, Dict, Iterator, List, Optional, Any
33

44
from reqif.helpers.debug import auto_described
55
from reqif.models.error_handling import ReqIFSchemaError
@@ -75,6 +75,34 @@ def iterate_specification_hierarchy(
7575
if current.children is not None:
7676
task_list.extendleft(reversed(current.children))
7777

78+
def iterate_specification_hierarchy_for_conversion(
79+
self,
80+
specification: ReqIFSpecification,
81+
root_node: Any,
82+
get_level_lambda,
83+
node_lambda,
84+
):
85+
section_stack: List[Any] = [root_node]
86+
87+
for current_hierarchy in self.iterate_specification_hierarchy(specification):
88+
current_section = section_stack[-1]
89+
section_level = get_level_lambda(current_section)
90+
91+
if current_hierarchy.level <= section_level:
92+
for _ in range(
93+
0,
94+
(section_level - current_hierarchy.level) + 1,
95+
):
96+
assert len(section_stack) > 0
97+
section_stack.pop()
98+
99+
current_section = section_stack[-1]
100+
converted_node, converted_node_is_section = node_lambda(
101+
current_hierarchy, current_section
102+
)
103+
if converted_node_is_section:
104+
section_stack.append(converted_node)
105+
78106
def get_spec_object_by_ref(self, ref) -> ReqIFSpecObject:
79107
return self.lookup.get_spec_object_by_ref(ref)
80108

tests/integration/examples/04_convert_reqif_to_json/script.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ def node_converter_lambda(
115115
is_section = reqif_schema.is_spec_object_a_heading(spec_object)
116116
return node, is_section
117117

118-
ReqIFToDictConverter._iterate(
118+
reqif_bundle.iterate_specification_hierarchy_for_conversion(
119119
specification,
120-
reqif_bundle,
121120
specification_dict,
122121
lambda s: s.level,
123122
node_converter_lambda,
@@ -127,37 +126,6 @@ def node_converter_lambda(
127126

128127
return reqif_dict
129128

130-
@staticmethod
131-
def _iterate(
132-
specification: ReqIFSpecification,
133-
reqif_bundle: ReqIFBundle,
134-
root_node: Any,
135-
get_level_lambda,
136-
node_converter_lambda,
137-
):
138-
section_stack: List = [root_node]
139-
140-
for current_hierarchy in reqif_bundle.iterate_specification_hierarchy(
141-
specification
142-
):
143-
current_section = section_stack[-1]
144-
section_level = get_level_lambda(current_section)
145-
146-
if current_hierarchy.level <= section_level:
147-
for _ in range(
148-
0,
149-
(section_level - current_hierarchy.level) + 1,
150-
):
151-
assert len(section_stack) > 0
152-
section_stack.pop()
153-
154-
current_section = section_stack[-1]
155-
converted_node, converted_node_is_section = node_converter_lambda(
156-
current_hierarchy, current_section
157-
)
158-
if converted_node_is_section:
159-
section_stack.append(converted_node)
160-
161129
@staticmethod
162130
def convert_spec_object_to_node(
163131
spec_object: ReqIFSpecObject,

0 commit comments

Comments
 (0)