27
27
from PyQt4 .QtCore import QSize
28
28
import tempfile
29
29
import urllib
30
+ import base64
30
31
31
32
32
33
XML_NS = \
@@ -1029,7 +1030,8 @@ def _post_restricted(self, data, query_string=None):
1029
1030
1030
1031
def _img_diff (self , image , control_image , max_diff , max_size_diff = QSize ()):
1031
1032
temp_image = path .join (tempfile .gettempdir (), "%s_result.png" % control_image )
1032
- with open (temp_image , "w" ) as f :
1033
+
1034
+ with open (temp_image , "wb" ) as f :
1033
1035
f .write (image )
1034
1036
1035
1037
control = QgsRenderChecker ()
@@ -1046,21 +1048,22 @@ def _img_diff_error(self, response, headers, image, max_diff=10, max_size_diff=Q
1046
1048
"Content type is wrong: %s" % headers .get ("Content-Type" ))
1047
1049
test , report = self ._img_diff (response , image , max_diff , max_size_diff )
1048
1050
1049
- result_img = check_output (["base64" , path .join (tempfile .gettempdir (), image + "_result.png" )])
1050
- message = "Image is wrong\n %s\n Image:\n echo '%s' | base64 -d >%s/%s_result.png" % (
1051
- report , result_img .strip (), tempfile .gettempdir (), image
1052
- )
1051
+ with open (path .join (tempfile .gettempdir (), image + "_result.png" ), "rb" ) as rendered_file :
1052
+ encoded_rendered_file = base64 .b64encode (rendered_file .read ())
1053
+ message = "Image is wrong\n %s\n Image:\n echo '%s' | base64 -d >%s/%s_result.png" % (
1054
+ report , encoded_rendered_file .strip (), tempfile .gettempdir (), image
1055
+ )
1053
1056
1054
- if path . isfile (path .join (tempfile .gettempdir (), image + "_result_diff.png" )) :
1055
- diff_img = check_output ([ " base64" , path . join ( tempfile . gettempdir (), image + "_result_diff.png" )] )
1057
+ with open (path .join (tempfile .gettempdir (), image + "_result_diff.png" ), "rb" ) as diff_file :
1058
+ encoded_diff_file = base64 . b64encode ( diff_file . read () )
1056
1059
message += "\n Diff:\n echo '%s' | base64 -d > %s/%s_result_diff.png" % (
1057
- diff_img .strip (), tempfile .gettempdir (), image
1060
+ encoded_diff_file .strip (), tempfile .gettempdir (), image
1058
1061
)
1062
+
1059
1063
self .assertTrue (test , message )
1060
1064
1061
1065
def _geo_img_diff (self , image_1 , image_2 ):
1062
-
1063
- with open (path .join (tempfile .gettempdir (), image_2 ), "w" ) as f :
1066
+ with open (path .join (tempfile .gettempdir (), image_2 ), "wb" ) as f :
1064
1067
f .write (image_1 )
1065
1068
image_1 = gdal .Open (path .join (tempfile .gettempdir (), image_2 ), GA_ReadOnly )
1066
1069
assert image_1 , "No output image written: " + image_2
0 commit comments