1010from pygem .cad import CADDeformation
1111
1212
13-
1413class TestFFDCAD (TestCase ):
1514
15+ def extract_floats (self , lines ):
16+ """
17+ Extract all numeric values from IGES file content.
18+
19+ This helper function parses a list of IGES file lines and returns
20+ a flattened numpy array of all floating-point numbers, ignoring
21+ line breaks, empty lines, and non-numeric text.
22+
23+ IGES files often wrap data lines differently on different platforms.
24+ By flattening all numeric values into a single array, this function enables reliable numerical comparison of IGES files regardless of
25+ line wrapping or minor formatting differences.
26+ """
27+ all_values = []
28+ for line in lines :
29+ if not line .strip ():
30+ continue
31+ parts = line .strip ().split (',' )[:- 1 ]
32+ for p in parts :
33+ try :
34+ all_values .append (float (p ))
35+ except ValueError :
36+ pass
37+ return np .asarray (all_values )
38+
1639 def test_ffd_iges_pipe_mod_through_files (self ):
1740 ffd = FFD (None ,30 ,30 ,30 ,1e-4 )
1841 ffd .read_parameters (
1942 filename = 'tests/test_datasets/parameters_test_ffd_iges.prm' )
2043 ffd ('tests/test_datasets/test_pipe.iges' , 'test_pipe_result.iges' )
2144 with open ('test_pipe_result.iges' , "r" ) as created , \
2245 open ('tests/test_datasets/test_pipe_out_true.iges' , "r" ) as reference :
23- ref = [line for line in reference .readlines ()[5 :] if line .strip ()]
24- cre = [line for line in created .readlines ()[5 :] if line .strip ()]
25- if abs (len (ref ) - len (cre )) > 1 :
26- self .fail (f"Length mismatch: { len (ref )} vs { len (cre )} " )
27-
28- for r_line , c_line in zip (ref , cre ):
29- ref_ = np .asarray (r_line .split (',' )[:- 1 ], dtype = float )
30- cre_ = np .asarray (c_line .split (',' )[:- 1 ], dtype = float )
31- np .testing .assert_array_almost_equal (cre_ , ref_ , decimal = 6 )
46+ ref_data = self .extract_floats (reference .readlines ()[5 :])
47+ cre_data = self .extract_floats (created .readlines ()[5 :])
48+ np .testing .assert_array_almost_equal (cre_data , ref_data , decimal = 6 )
3249 self .addCleanup (os .remove , 'test_pipe_result.iges' )
3350
3451 def test_ffd_iges_pipe_mod_through_topods_shape (self ):
@@ -41,15 +58,9 @@ def test_ffd_iges_pipe_mod_through_topods_shape(self):
4158 CADDeformation .write_shape ('test_pipe_hollow_result.iges' , mod_shape )
4259 with open ('test_pipe_hollow_result.iges' , "r" ) as created , \
4360 open ('tests/test_datasets/test_pipe_hollow_out_true.iges' , "r" ) as reference :
44- ref = [line for line in reference .readlines ()[5 :] if line .strip ()]
45- cre = [line for line in created .readlines ()[5 :] if line .strip ()]
46- if abs (len (ref ) - len (cre )) > 1 :
47- self .fail (f"Length mismatch: { len (ref )} vs { len (cre )} " )
48-
49- for r_line , c_line in zip (ref , cre ):
50- ref_ = np .asarray (r_line .split (',' )[:- 1 ], dtype = float )
51- cre_ = np .asarray (c_line .split (',' )[:- 1 ], dtype = float )
52- np .testing .assert_array_almost_equal (cre_ , ref_ , decimal = 6 )
61+ ref_data = self .extract_floats (reference .readlines ()[5 :])
62+ cre_data = self .extract_floats (created .readlines ()[5 :])
63+ np .testing .assert_array_almost_equal (cre_data , ref_data , decimal = 6 )
5364 self .addCleanup (os .remove , 'test_pipe_hollow_result.iges' )
5465
5566 """
@@ -68,5 +79,4 @@ def test_ffd_step_pipe_mod_through_files(self):
6879 cre_ = np.asarray(re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", cre[i]),dtype=float)
6980 np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
7081 self.addCleanup(os.remove, 'test_pipe_result.step')
71- """
72-
82+ """
0 commit comments