-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrender_conformance_tests.py
More file actions
180 lines (158 loc) · 8.59 KB
/
Copy pathrender_conformance_tests.py
File metadata and controls
180 lines (158 loc) · 8.59 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
from typing import Any
import file_utils
import plain_spec
from memory_management import MemoryManager
from plain2code_console import console
from render_machine.actions.base_action import BaseAction
from render_machine.implementation_code_helpers import ImplementationCodeHelpers
from render_machine.render_context import RenderContext
class RenderConformanceTests(BaseAction):
SUCCESSFUL_OUTCOME = "conformance_test_rendered"
def execute(self, render_context: RenderContext, _previous_action_payload: Any | None):
if self._should_render_conformance_tests(render_context):
return self._render_conformance_tests(render_context)
else:
return self._render_acceptance_test(render_context)
def _should_render_conformance_tests(self, render_context: RenderContext) -> bool:
return render_context.conformance_tests_running_context.conformance_test_phase_index == 0
def _render_conformance_tests(self, render_context: RenderContext):
if render_context.verbose:
console.info("Implementing test requirements:")
console.print_list(
render_context.conformance_tests_running_context.current_testing_frid_specifications[
plain_spec.TEST_REQUIREMENTS
],
style=console.INFO_STYLE,
)
if not render_context.conformance_tests_running_context.current_conformance_tests_exist():
with console.status(
f"[{console.INFO_STYLE}]Generating folder name for conformance tests for functional requirement {render_context.conformance_tests_running_context.current_testing_frid}...\n"
):
fr_subfolder_name = render_context.codeplain_api.generate_folder_name_from_functional_requirement(
frid=render_context.conformance_tests_running_context.current_testing_frid,
functional_requirement=render_context.conformance_tests_running_context.current_testing_frid_specifications[
plain_spec.FUNCTIONAL_REQUIREMENTS
][
-1
],
existing_folder_names=render_context.conformance_tests.fetch_existing_conformance_test_folder_names(
render_context.conformance_tests_running_context.current_testing_module_name
),
run_state=render_context.run_state,
)
conformance_tests_folder_name = os.path.join(
render_context.conformance_tests.get_module_conformance_tests_folder(render_context.module_name),
fr_subfolder_name,
)
if render_context.verbose:
console.info(f"Storing conformance test files in subfolder {conformance_tests_folder_name}/")
render_context.conformance_tests_running_context.get_conformance_tests_json(
render_context.conformance_tests_running_context.current_testing_module_name
)[render_context.conformance_tests_running_context.current_testing_frid] = {
"folder_name": conformance_tests_folder_name,
"functional_requirement": render_context.frid_context.specifications[
plain_spec.FUNCTIONAL_REQUIREMENTS
][-1],
}
else:
conformance_tests_folder_name = (
render_context.conformance_tests_running_context.get_current_conformance_test_folder_name()
)
_, existing_files_content = ImplementationCodeHelpers.fetch_existing_files(render_context.build_folder)
_, memory_files_content = MemoryManager.fetch_memory_files(render_context.memory_manager.memory_folder)
if render_context.verbose:
tmp_resources_list = []
plain_spec.collect_linked_resources(
render_context.plain_source_tree,
tmp_resources_list,
[
plain_spec.DEFINITIONS,
plain_spec.TEST_REQUIREMENTS,
plain_spec.FUNCTIONAL_REQUIREMENTS,
],
False,
render_context.frid_context.frid,
)
console.print_resources(tmp_resources_list, render_context.frid_context.linked_resources)
console.print_files(
"Files sent as input for generating conformance tests:",
render_context.build_folder,
existing_files_content,
style=console.INPUT_STYLE,
)
all_acceptance_tests = render_context.frid_context.specifications.get(plain_spec.ACCEPTANCE_TESTS, [])
with console.status(
f"[{console.INFO_STYLE}]Rendering conformance test for functional requirement {render_context.conformance_tests_running_context.current_testing_frid}...\n"
):
response_files, implementation_plan_summary = render_context.codeplain_api.render_conformance_tests(
render_context.frid_context.frid,
render_context.conformance_tests_running_context.current_testing_frid,
render_context.plain_source_tree,
render_context.frid_context.linked_resources,
existing_files_content,
memory_files_content,
render_context.module_name,
render_context.get_required_modules_functionalities(),
conformance_tests_folder_name,
render_context.conformance_tests_running_context.get_conformance_tests_json(
render_context.conformance_tests_running_context.current_testing_module_name
),
all_acceptance_tests,
run_state=render_context.run_state,
)
render_context.conformance_tests_running_context.current_testing_frid_high_level_implementation_plan = (
implementation_plan_summary
)
file_utils.store_response_files(conformance_tests_folder_name, response_files, [])
if render_context.verbose:
console.print_files(
"Conformance test files generated:",
conformance_tests_folder_name,
response_files,
style=console.OUTPUT_STYLE,
)
return self.SUCCESSFUL_OUTCOME, None
def _render_acceptance_test(self, render_context: RenderContext):
_, existing_files_content = ImplementationCodeHelpers.fetch_existing_files(render_context.build_folder)
_, memory_files_content = MemoryManager.fetch_memory_files(render_context.memory_manager.memory_folder)
(
conformance_tests_files,
conformance_tests_files_content,
) = render_context.conformance_tests.fetch_existing_conformance_test_files(
render_context.module_name,
render_context.required_modules,
render_context.conformance_tests_running_context.current_testing_module_name,
render_context.conformance_tests_running_context.get_current_conformance_test_folder_name(),
)
acceptance_test = render_context.frid_context.specifications[plain_spec.ACCEPTANCE_TESTS][
render_context.conformance_tests_running_context.conformance_test_phase_index - 1
]
if render_context.verbose:
console.info(f"Generating acceptance test:\n {acceptance_test}")
with console.status(
f"[{console.INFO_STYLE}]Generating acceptance test for functional requirement {render_context.frid_context.frid}...\n"
):
response_files = render_context.codeplain_api.render_acceptance_tests(
render_context.frid_context.frid,
render_context.plain_source_tree,
render_context.frid_context.linked_resources,
existing_files_content,
memory_files_content,
conformance_tests_files_content,
render_context.module_name,
render_context.get_required_modules_functionalities(),
acceptance_test,
run_state=render_context.run_state,
)
conformance_tests_folder_name = (
render_context.conformance_tests_running_context.get_current_conformance_test_folder_name()
)
file_utils.store_response_files(conformance_tests_folder_name, response_files, conformance_tests_files)
console.print_files(
f"Conformance test files in folder {conformance_tests_folder_name} updated:",
conformance_tests_folder_name,
response_files,
style=console.OUTPUT_STYLE,
)
return self.SUCCESSFUL_OUTCOME, None