-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_logic.py
More file actions
79 lines (63 loc) · 2.35 KB
/
verify_logic.py
File metadata and controls
79 lines (63 loc) · 2.35 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
import sys
import os
import shutil
import json
from pathlib import Path
# Add project root to path
sys.path.append("d:/projects/ags")
# Mocking config to avoid import errors if config.py needs env vars
# Assuming helpers don't need app context
from tbag.helpers.components import save_component, load_component, new_component_slug, COMPONENTS
from tbag.helpers.projects import save_config, load_config, new_project_slug, PROJECTS
def test_logic():
print("Testing Thickness Logic...")
# --- Component Test ---
c_name = "ThickTestComp"
cid = new_component_slug(c_name)
print(f"1. Creating component '{c_name}' (ID: {cid}) with default_thickness=0.55")
c_data = {
"name": c_name,
"gpio": 2, # L1
"image": None,
"default_thickness": 0.55
}
save_component(cid, c_data)
# Reload and verify
loaded_c = load_component(cid)
if loaded_c and loaded_c.get("default_thickness") == 0.55:
print(" [PASS] Component saved and loaded with default_thickness.")
else:
print(f" [FAIL] Component data mismatch: {loaded_c}")
# --- Project Test ---
p_name = "ThickTestProj"
pid = new_project_slug(p_name)
print(f"2. Creating project '{p_name}' (ID: {pid}) with sequence thickness override.")
p_data = {
"name": p_name,
"sequence": [
{"comp": cid, "label": "Step 1", "thickness": 1.25},
{"comp": cid, "label": "Step 2"} # Should imply default or 0 (logic handles missing key)
]
}
save_config(pid, p_data)
# Reload and verify
loaded_p = load_config(pid)
seq = loaded_p.get("sequence", [])
if len(seq) == 2:
if seq[0].get("thickness") == 1.25:
print(" [PASS] Step 1 has thickness 1.25")
else:
print(f" [FAIL] Step 1 thickness mismatch: {seq[0]}")
if "thickness" not in seq[1]:
print(" [PASS] Step 2 has no explicit thickness (correct).")
else:
print(f" [INFO] Step 2 has thickness: {seq[1].get('thickness')}")
else:
print(" [FAIL] Sequence length mismatch.")
# Cleanup
print("Cleaning up...")
shutil.rmtree(COMPONENTS / cid, ignore_errors=True)
shutil.rmtree(PROJECTS / pid, ignore_errors=True)
print("Done.")
if __name__ == "__main__":
test_logic()