@@ -70,61 +70,52 @@ def _reader_for_file(path: str):
7070            return  vtk .vtkJPEGReader ()
7171        return  vtk .vtkJPEGReader ()
7272
73-     def  images_diff (self , first_image_path , second_image_path , tolerance : float  =  0.0 ):
74-         first_reader  =  self ._reader_for_file (first_image_path )
73+     def  images_diff (self , first_image_path , second_image_path ):
74+         if  ".png"  in  first_image_path :
75+             first_reader  =  vtk .vtkPNGReader ()
76+         elif  (".jpg"  in  first_image_path ) or  (".jpeg"  in  first_image_path ):
77+             first_reader  =  vtk .vtkJPEGReader ()
7578        first_reader .SetFileName (first_image_path )
7679
77-         second_reader  =  self ._reader_for_file (second_image_path )
80+         if  ".png"  in  second_image_path :
81+             second_reader  =  vtk .vtkPNGReader ()
82+         elif  (".jpg"  in  second_image_path ) or  (".jpeg"  in  second_image_path ):
83+             second_reader  =  vtk .vtkJPEGReader ()
7884        second_reader .SetFileName (second_image_path )
7985
8086        images_diff  =  vtk .vtkImageDifference ()
8187        images_diff .SetInputConnection (first_reader .GetOutputPort ())
8288        images_diff .SetImageConnection (second_reader .GetOutputPort ())
8389        images_diff .Update ()
8490
85-         error  =  images_diff .GetThresholdedError ()
86-         print (f"Image comparison error for { second_image_path }  : { error }   (tolerance: { tolerance }  )" , flush = True )
87-         return  error  <=  tolerance 
91+         print (f"{ images_diff .GetThresholdedError ()= }  " )
92+         return  images_diff .GetThresholdedError ()
8893
89-     def  compare_image (self , nb_messages , filename , tolerance = 0.0 ):
90- 
91-         self .ws .settimeout (4.0 )
92-         image  =  None 
93-         deadline  =  time .time () +  12.0 
94-         while  time .time () <  deadline :
95-             try :
96-                 msg  =  self .ws .recv ()
97-             except  WebSocketTimeoutException :
98-                 continue 
99-             if  isinstance (msg , bytes ):
100-                 image  =  msg 
101-                 break 
102-         if  not  isinstance (msg , bytes ):
103-             return  False 
104-         test_file_path  =  os .path .abspath (
105-             os .path .join (self .test_output_dir , "test.jpeg" )
106-         )
107-         with  open (test_file_path , "wb" ) as  f :
108-             f .write (image )
109-         format  =  "jpeg" 
110-         try :
111-             meta  =  self .ws .recv ()
112-             try :
113-                 format  =  json .loads (meta )["result" ]["format" ]
114-             except  Exception :
115-                 pass 
116-         except  WebSocketTimeoutException :
117-             pass 
118- 
119-         if  format  !=  "jpeg" :
120-             new_path  =  os .path .abspath (
94+     def  compare_image (self , nb_messages , filename ):
95+         for  message  in  range (nb_messages ):
96+             print (f"{ message = }  " , flush = True )
97+             image  =  self .ws .recv ()
98+             if  isinstance (image , bytes ):
99+                 test_file_path  =  os .path .abspath (
100+                     os .path .join (self .test_output_dir , "test.jpeg" )
101+                 )
102+                 with  open (test_file_path , "wb" ) as  f :
103+                     f .write (image )
104+                     f .close ()
105+         if  isinstance (image , bytes ):
106+             response  =  self .ws .recv ()
107+             print (f"{ response = }  " , flush = True )
108+             format  =  json .loads (response )["result" ]["format" ]
109+             test_file_path  =  os .path .abspath (
121110                os .path .join (self .test_output_dir , f"test.{ format }  " )
122111            )
123-             os .replace (test_file_path , new_path )
124-             test_file_path  =  new_path 
112+             with  open (test_file_path , "wb" ) as  f :
113+                 f .write (image )
114+                 f .close ()
115+ 
116+             path_image  =  os .path .join (self .images_dir_path , filename )
125117
126-         path_image  =  os .path .join (self .images_dir_path , filename )
127-         return  self .images_diff (test_file_path , path_image , tolerance )
118+             return  self .images_diff (test_file_path , path_image ) ==  0.0 
128119
129120    def  _init_ws (self ):
130121        self .ws .send (
@@ -204,10 +195,10 @@ def configure_test_environment():
204195    os .environ ["TEST_DB_PATH" ] =  str (db_path )
205196
206197    yield 
207-     tmp_data_path  =  os .environ .get ("DATA_FOLDER_PATH" )
208-     if  tmp_data_path  and  "ogw_test_data_"  in  tmp_data_path :
209-         shutil .rmtree (tmp_data_path , ignore_errors = True )
210-         print (f"Cleaned up test data folder: { tmp_data_path }  " , flush = True )
198+     #  tmp_data_path = os.environ.get("DATA_FOLDER_PATH")
199+     #  if tmp_data_path and "ogw_test_data_" in tmp_data_path:
200+     #      shutil.rmtree(tmp_data_path, ignore_errors=True)
201+     #      print(f"Cleaned up test data folder: {tmp_data_path}", flush=True)
211202
212203
213204@pytest .fixture  
0 commit comments