-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplain2code_utils.py
More file actions
56 lines (46 loc) · 2.18 KB
/
plain2code_utils.py
File metadata and controls
56 lines (46 loc) · 2.18 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
from typing import Optional
import plain_spec
from plain2code_console import console
def format_duration_hms(total_seconds: int) -> str:
"""Format a duration in seconds as hours, minutes, and seconds (e.g. ``1h 2m 3.45s``, ``45.67s``)."""
if total_seconds < 0:
total_seconds = 0
h = int(total_seconds // 3600)
m = int((total_seconds % 3600) // 60)
s = total_seconds % 60
if h:
return f"{h}h {m}m {s}s"
if m:
return f"{m}m {s}s"
text = f"{s}".rstrip("0").rstrip(".")
return f"{text}s" if text else "0s"
AMBIGUITY_CAUSES = {
"reference_resource_ambiguity": "Ambiguity is in the reference resources",
"definition_ambiguity": "Ambiguity is in the definitions",
"non_functional_requirement_ambiguity": "Ambiguity is in the implementation reqs",
"functional_requirement_ambiguity": "Ambiguity is in the functionality",
"other": "Ambiguity in the other parts of the specification",
}
def print_dry_run_output(plain_source_tree: dict, render_range: Optional[list[str]]):
frid = plain_spec.get_first_frid(plain_source_tree)
while frid is not None:
is_inside_range = render_range is None or frid in render_range
if is_inside_range:
specifications, _ = plain_spec.get_specifications_for_frid(plain_source_tree, frid)
functional_requirement_text = specifications[plain_spec.FUNCTIONAL_REQUIREMENTS][-1]
console.info(
"-------------------------------------\n"
f"Rendering functionality {frid}:\n"
f"{functional_requirement_text}\n"
"-------------------------------------\n"
)
if plain_spec.ACCEPTANCE_TESTS in specifications:
for i, acceptance_test in enumerate(specifications[plain_spec.ACCEPTANCE_TESTS], 1):
console.info(f"Generating acceptance test #{i}:\n\n{acceptance_test}\n")
else:
console.info(
"-------------------------------------\n"
f"Skipping rendering iteration: {frid}\n"
"-------------------------------------"
)
frid = plain_spec.get_next_frid(plain_source_tree, frid)