Salome HOME
[For eval] add image comparison
[modules/paravis.git] / test / VisuPrs / ScalarMap / G2.py
index 5465eb55df1afd889b3205dd4037870e009e643e..2f4ea4dfc9cfae77471f6c0c54467c77374e7b31 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2015  CEA/DEN, EDF R&D
+# Copyright (C) 2010-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 
 import sys
 import os
-from paravistest import datadir, pictureext, get_picture_dir
-import pvserver as paravis
-from pvsimple import GetActiveSource, GetRenderView, Render
+from paravistest import datadir, pictureext, get_picture_dir, compare_view_to_ref_image
+from pvsimple import GetActiveSource, GetRenderView, Render, OpenDataFile
 from presentations import ScalarMapOnField, hide_all, EntityType, PrsTypeEnum,reset_view,process_prs_for_test
 
-
-# Create presentations
-myParavis = paravis.myParavis
-
 picturedir = get_picture_dir("ScalarMap/G2")
 
 theFileName = datadir +  "Bug829_resu_mode.med"
 print " --------------------------------- "
 print "file ", theFileName
 print " --------------------------------- "
-    
+
 """Build presentations of the given types for all fields of the given file."""
 #print "Import %s..." % theFileName.split('/')[-1],
 result = OpenDataFile(theFileName)
 proxy = GetActiveSource()
 if proxy is None:
-       raise RuntimeError, "Error: can't import file."
+        raise RuntimeError, "Error: can't import file."
 else: print "OK"
 # Get view
 aView = GetRenderView()
 
 
+import time
+
 aFieldEntity = EntityType.NODE
 aFieldName = "MODES___DEPL____________________"
-#create list to store picture files sizes
-sizes=[]
 #create Scalar Map presentations for 10 timestamps
 for i in range(1,11):
     hide_all(aView, True)
@@ -62,27 +57,21 @@ for i in range(1,11):
     #display only current scalar map
     aPrs.Visibility=1
     reset_view(aView)
-    Render(aView)    
-    
-    # Add path separator to the end of picture path if necessery
-    if not picturedir.endswith(os.sep):
-            picturedir += os.sep
+    Render(aView)
+
     prs_type = PrsTypeEnum.SCALARMAP
-            
+
     # Get name of presentation type
-    prs_name = PrsTypeEnum.get_name(prs_type)    
+    prs_name = PrsTypeEnum.get_name(prs_type)
     f_prs_type = prs_name.replace(' ', '').upper()
     # Construct image file name
-    pic_name = picturedir + aFieldName + "_" + str(i) + "_" + f_prs_type + "." + pictureext
-    
+    base_name = aFieldName + "_" + str(i) + "_" + f_prs_type + "." + pictureext
+    pic_name = os.path.join(picturedir, base_name)
+
     # Show and record the presentation
     process_prs_for_test(aPrs, aView, pic_name)
-    sizes.append(os.path.getsize(pic_name))
 
-# check sizes of pictures      
-if abs(max(sizes)-min(sizes)) > 0.01*max(sizes):
-    print "<b>WARNING!!! Pictures have different sizes!!!</b>"; 
-    for i in range(1,11):
-        picture_name = "time_stamp_"+str(i)+"."+pictureext
-        print "Picture: "+picture_name+"; size: "+str(sizes[i-1]) 
-    raise RuntimeError 
+    # Compare to baseline
+    current_dir = os.path.dirname(os.path.realpath(__file__))
+    baseline = os.path.join(current_dir, "_refs", base_name)
+    compare_view_to_ref_image(aView, baseline, threshold=1)