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 = reference .readlines ()[5 :]
24- cre = created .readlines ()[5 :]
25- self .assertEqual (len (ref ),len (cre ))
26- for i in range (len (cre )):
27- ref_ = np .asarray (ref [i ].split (',' )[:- 1 ], dtype = float )
28- cre_ = np .asarray (cre [i ].split (',' )[:- 1 ], dtype = float )
29- 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 )
3049 self .addCleanup (os .remove , 'test_pipe_result.iges' )
3150
3251 def test_ffd_iges_pipe_mod_through_topods_shape (self ):
@@ -39,13 +58,9 @@ def test_ffd_iges_pipe_mod_through_topods_shape(self):
3958 CADDeformation .write_shape ('test_pipe_hollow_result.iges' , mod_shape )
4059 with open ('test_pipe_hollow_result.iges' , "r" ) as created , \
4160 open ('tests/test_datasets/test_pipe_hollow_out_true.iges' , "r" ) as reference :
42- ref = reference .readlines ()[5 :]
43- cre = created .readlines ()[5 :]
44- self .assertEqual (len (ref ),len (cre ))
45- for i in range (len (cre )):
46- ref_ = np .asarray (ref [i ].split (',' )[:- 1 ], dtype = float )
47- cre_ = np .asarray (cre [i ].split (',' )[:- 1 ], dtype = float )
48- 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 )
4964 self .addCleanup (os .remove , 'test_pipe_hollow_result.iges' )
5065
5166 """
@@ -64,5 +79,4 @@ def test_ffd_step_pipe_mod_through_files(self):
6479 cre_ = np.asarray(re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", cre[i]),dtype=float)
6580 np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
6681 self.addCleanup(os.remove, 'test_pipe_result.step')
67- """
68-
82+ """
0 commit comments