22System tests — full CAD workflow.
33
44These tests exercise the Model end-to-end: file loading, topology queries,
5- point addition and render-data consistency. No Panda3D required.
5+ point addition and curve-discretization consistency. No Panda3D required.
66"""
77
8+ import pickle
89import unittest
9- from bot .core .cad import Model as CADModel
10+
11+ from bot .core .cad import CADModel
1012
1113GEO_FILE = "data/profil_1.geo"
1214
1315
16+ def _total_vertices (discretization ):
17+ return sum (len (pts ) for pts , _ in discretization .values ())
18+
19+
1420class TestLoadAndTopology (unittest .TestCase ):
1521 """Open profil_1.geo and verify the full topology is coherent."""
1622
@@ -48,8 +54,8 @@ def test_get_adjacent_points_returns_two_per_curve(self):
4854 self .assertEqual (2 , len (self .cad .get_adjacent_points (tag )))
4955
5056
51- class TestRenderDataCoherence (unittest .TestCase ):
52- """Verify get_render_data () returns a consistent, picklable snapshot ."""
57+ class TestCurveDiscretizationCoherence (unittest .TestCase ):
58+ """Verify get_curve_discretization () and bounds stay consistent ."""
5359
5460 def setUp (self ):
5561 self .cad = CADModel ()
@@ -58,41 +64,48 @@ def setUp(self):
5864 def tearDown (self ):
5965 self .cad .finalize ()
6066
61- def test_render_data_has_all_keys (self ):
62- data = self .cad .get_render_data ()
63- self .assertIn ( "points" , data )
64- self .assertIn ( "edges" , data )
65- self .assertIn ("bounds" , data )
67+ def test_discretization_has_one_entry_per_curve (self ):
68+ discretization = self .cad .get_curve_discretization ()
69+ self .assertEqual ( len ( self . cad . get_curve_tags ()), len ( discretization ) )
70+ for tag in self .cad . get_curve_tags ():
71+ self .assertIn (tag , discretization )
6672
6773 def test_edges_reference_valid_point_indices (self ):
68- data = self .cad .get_render_data ()
69- n = len (data ["points" ])
70- for idx_a , idx_b , _curve_tag in data ["edges" ]:
71- self .assertGreaterEqual (idx_a , 0 )
72- self .assertLess (idx_a , n )
73- self .assertGreaterEqual (idx_b , 0 )
74- self .assertLess (idx_b , n )
74+ for pts , edges in self .cad .get_curve_discretization ().values ():
75+ n = len (pts )
76+ for idx_a , idx_b in edges :
77+ self .assertGreaterEqual (idx_a , 0 )
78+ self .assertLess (idx_a , n )
79+ self .assertGreaterEqual (idx_b , 0 )
80+ self .assertLess (idx_b , n )
81+
82+ def test_bounds_has_expected_keys (self ):
83+ bounds = self .cad .bounds
84+ for key in ("min" , "max" , "center" , "size" ):
85+ self .assertIn (key , bounds )
7586
7687 def test_bounds_center_is_inside_min_max (self ):
77- bounds = self .cad .get_render_data ()[ " bounds" ]
88+ bounds = self .cad .bounds
7889 for axis in range (3 ):
7990 self .assertGreaterEqual (bounds ["center" ][axis ], bounds ["min" ][axis ] - 1e-9 )
8091 self .assertLessEqual (bounds ["center" ][axis ], bounds ["max" ][axis ] + 1e-9 )
8192
8293 def test_bounds_size_matches_min_max (self ):
83- bounds = self .cad .get_render_data ()[ " bounds" ]
94+ bounds = self .cad .bounds
8495 for axis in range (3 ):
8596 expected = bounds ["max" ][axis ] - bounds ["min" ][axis ]
8697 self .assertAlmostEqual (bounds ["size" ][axis ], expected , places = 9 )
8798
88- def test_render_data_is_picklable (self ):
89- import pickle
90-
91- data = self .cad .get_render_data ()
92- serialised = pickle .dumps (data )
99+ def test_discretization_is_picklable (self ):
100+ discretization = self .cad .get_curve_discretization ()
101+ serialised = pickle .dumps (discretization )
93102 restored = pickle .loads (serialised )
94- self .assertEqual (data ["bounds" ], restored ["bounds" ])
95- self .assertEqual (len (data ["points" ]), len (restored ["points" ]))
103+ self .assertEqual (len (discretization ), len (restored ))
104+ for tag , (pts , edges ) in discretization .items ():
105+ self .assertIn (tag , restored )
106+ restored_pts , restored_edges = restored [tag ]
107+ self .assertEqual (pts , restored_pts )
108+ self .assertEqual (edges , restored_edges )
96109
97110
98111class TestAddPointWorkflow (unittest .TestCase ):
@@ -102,7 +115,6 @@ def setUp(self):
102115 self .cad = CADModel ()
103116 self .cad .open (GEO_FILE )
104117 self .initial_point_count = len (self .cad .get_point_tags ())
105- self .initial_render_pts = len (self .cad .get_render_data ()["points" ])
106118
107119 def tearDown (self ):
108120 self .cad .finalize ()
@@ -118,17 +130,16 @@ def test_add_point_returns_valid_tag(self):
118130 tag = self .cad .add_point ([1.0 , 1.0 , 0.0 ])
119131 self .assertIn (tag , self .cad .get_point_tags ())
120132
121- def test_add_point_updates_render_data (self ):
133+ def test_add_point_updates_discretization (self ):
122134 self .cad .add_point ([100.0 , 100.0 , 0.0 ])
123- new_count = len (self .cad .get_render_data ()["points" ])
124- # Mesh is regenerated: number of discretisation nodes changes
135+ new_count = _total_vertices (self .cad .get_curve_discretization ())
125136 self .assertGreater (new_count , 0 )
126137
127138 def test_bounds_extend_when_point_is_outside (self ):
128- old_bounds = self .cad .get_render_data ()[ " bounds" ]
139+ old_bounds = self .cad .bounds
129140 far_x = old_bounds ["max" ][0 ] + 1000.0
130141 self .cad .add_point ([far_x , 0.0 , 0.0 ])
131- new_bounds = self .cad .get_render_data ()[ " bounds" ]
142+ new_bounds = self .cad .bounds
132143 self .assertGreaterEqual (new_bounds ["max" ][0 ], far_x - 1e-6 )
133144
134145 def test_cumulative_additions (self ):
0 commit comments