14
14
15
15
print 'CTEST_FULL_OUTPUT'
16
16
17
- from os import path , environ
17
+ import os
18
18
from shutil import copyfile
19
19
from math import sqrt
20
20
from subprocess import check_output
@@ -160,20 +160,20 @@ class TestQgsServerAccessControl(TestCase):
160
160
def setUp (self ):
161
161
self .testdata_path = unitTestDataPath ("qgis_server_accesscontrol" )
162
162
163
- dataFile = path .join (self .testdata_path , "helloworld.db" )
164
- self .assertTrue (path .isfile (dataFile ), 'Could not find data file "{}"' .format (dataFile ))
165
- copyfile (dataFile , path .join (self .testdata_path , "_helloworld.db" ))
163
+ dataFile = os . path .join (self .testdata_path , "helloworld.db" )
164
+ self .assertTrue (os . path .isfile (dataFile ), 'Could not find data file "{}"' .format (dataFile ))
165
+ copyfile (dataFile , os . path .join (self .testdata_path , "_helloworld.db" ))
166
166
167
167
for k in ["QUERY_STRING" , "QGIS_PROJECT_FILE" ]:
168
- if k in environ :
169
- del environ [k ]
168
+ if k in os . environ :
169
+ del os . environ [k ]
170
170
171
- self .projectPath = path .join (self .testdata_path , "project.qgs" )
172
- self .assertTrue (path .isfile (self .projectPath ), 'Could not find project file "{}"' .format (self .projectPath ))
171
+ self .projectPath = os . path .join (self .testdata_path , "project.qgs" )
172
+ self .assertTrue (os . path .isfile (self .projectPath ), 'Could not find project file "{}"' .format (self .projectPath ))
173
173
self .projectPath = urllib .quote (self .projectPath )
174
174
175
175
def tearDown (self ):
176
- copyfile (path .join (self .testdata_path , "_helloworld.db" ), path .join (self .testdata_path , "helloworld.db" ))
176
+ copyfile (os . path .join (self .testdata_path , "_helloworld.db" ), os . path .join (self .testdata_path , "helloworld.db" ))
177
177
178
178
# # WMS # # WMS # # WMS # #
179
179
@@ -997,39 +997,39 @@ def _result(self, data):
997
997
return data [1 ], headers
998
998
999
999
def _get_fullaccess (self , query_string ):
1000
- environ ["REQUEST_METHOD" ] = "GET"
1000
+ os . environ ["REQUEST_METHOD" ] = "GET"
1001
1001
result = self ._handle_request (False , query_string )
1002
- del environ ["REQUEST_METHOD" ]
1002
+ del os . environ ["REQUEST_METHOD" ]
1003
1003
return result
1004
1004
1005
1005
def _get_restricted (self , query_string ):
1006
- environ ["REQUEST_METHOD" ] = "GET"
1006
+ os . environ ["REQUEST_METHOD" ] = "GET"
1007
1007
result = self ._handle_request (True , query_string )
1008
- del environ ["REQUEST_METHOD" ]
1008
+ del os . environ ["REQUEST_METHOD" ]
1009
1009
return result
1010
1010
1011
1011
def _post_fullaccess (self , data , query_string = None ):
1012
- environ ["REQUEST_METHOD" ] = "POST"
1013
- environ ["REQUEST_BODY" ] = data
1014
- environ ["QGIS_PROJECT_FILE" ] = self .projectPath
1012
+ os . environ ["REQUEST_METHOD" ] = "POST"
1013
+ os . environ ["REQUEST_BODY" ] = data
1014
+ os . environ ["QGIS_PROJECT_FILE" ] = self .projectPath
1015
1015
result = self ._handle_request (False , query_string )
1016
- del environ ["REQUEST_METHOD" ]
1017
- del environ ["REQUEST_BODY" ]
1018
- del environ ["QGIS_PROJECT_FILE" ]
1016
+ del os . environ ["REQUEST_METHOD" ]
1017
+ del os . environ ["REQUEST_BODY" ]
1018
+ del os . environ ["QGIS_PROJECT_FILE" ]
1019
1019
return result
1020
1020
1021
1021
def _post_restricted (self , data , query_string = None ):
1022
- environ ["REQUEST_METHOD" ] = "POST"
1023
- environ ["REQUEST_BODY" ] = data
1024
- environ ["QGIS_PROJECT_FILE" ] = self .projectPath
1022
+ os . environ ["REQUEST_METHOD" ] = "POST"
1023
+ os . environ ["REQUEST_BODY" ] = data
1024
+ os . environ ["QGIS_PROJECT_FILE" ] = self .projectPath
1025
1025
result = self ._handle_request (True , query_string )
1026
- del environ ["REQUEST_METHOD" ]
1027
- del environ ["REQUEST_BODY" ]
1028
- del environ ["QGIS_PROJECT_FILE" ]
1026
+ del os . environ ["REQUEST_METHOD" ]
1027
+ del os . environ ["REQUEST_BODY" ]
1028
+ del os . environ ["QGIS_PROJECT_FILE" ]
1029
1029
return result
1030
1030
1031
1031
def _img_diff (self , image , control_image , max_diff , max_size_diff = QSize ()):
1032
- temp_image = path .join (tempfile .gettempdir (), "%s_result.png" % control_image )
1032
+ temp_image = os . path .join (tempfile .gettempdir (), "%s_result.png" % control_image )
1033
1033
1034
1034
with open (temp_image , "wb" ) as f :
1035
1035
f .write (image )
@@ -1048,13 +1048,13 @@ def _img_diff_error(self, response, headers, image, max_diff=10, max_size_diff=Q
1048
1048
"Content type is wrong: %s" % headers .get ("Content-Type" ))
1049
1049
test , report = self ._img_diff (response , image , max_diff , max_size_diff )
1050
1050
1051
- with open (path .join (tempfile .gettempdir (), image + "_result.png" ), "rb" ) as rendered_file :
1051
+ with open (os . path .join (tempfile .gettempdir (), image + "_result.png" ), "rb" ) as rendered_file :
1052
1052
encoded_rendered_file = base64 .b64encode (rendered_file .read ())
1053
1053
message = "Image is wrong\n %s\n Image:\n echo '%s' | base64 -d >%s/%s_result.png" % (
1054
1054
report , encoded_rendered_file .strip (), tempfile .gettempdir (), image
1055
1055
)
1056
1056
1057
- with open (path .join (tempfile .gettempdir (), image + "_result_diff.png" ), "rb" ) as diff_file :
1057
+ with open (os . path .join (tempfile .gettempdir (), image + "_result_diff.png" ), "rb" ) as diff_file :
1058
1058
encoded_diff_file = base64 .b64encode (diff_file .read ())
1059
1059
message += "\n Diff:\n echo '%s' | base64 -d > %s/%s_result_diff.png" % (
1060
1060
encoded_diff_file .strip (), tempfile .gettempdir (), image
@@ -1063,24 +1063,31 @@ def _img_diff_error(self, response, headers, image, max_diff=10, max_size_diff=Q
1063
1063
self .assertTrue (test , message )
1064
1064
1065
1065
def _geo_img_diff (self , image_1 , image_2 ):
1066
- with open (path .join (tempfile .gettempdir (), image_2 ), "wb" ) as f :
1066
+ if os .name == 'nt' :
1067
+ # Not supported on Windows due to #13061
1068
+ return 0
1069
+
1070
+ with open (os .path .join (tempfile .gettempdir (), image_2 ), "wb" ) as f :
1067
1071
f .write (image_1 )
1068
- image_1 = gdal .Open (path .join (tempfile .gettempdir (), image_2 ), GA_ReadOnly )
1072
+ image_1 = gdal .Open (os . path .join (tempfile .gettempdir (), image_2 ), GA_ReadOnly )
1069
1073
assert image_1 , "No output image written: " + image_2
1070
1074
1071
- image_2 = gdal .Open (path .join (self .testdata_path , "results" , image_2 ), GA_ReadOnly )
1075
+ image_2 = gdal .Open (os . path .join (self .testdata_path , "results" , image_2 ), GA_ReadOnly )
1072
1076
assert image_1 , "No expected image found:" + image_2
1073
1077
1074
- if image_1 .RasterXSize != image_2 .RasterXSize :
1075
- return 1000 # wrong size
1076
- if image_1 . RasterYSize != image_2 . RasterYSize :
1078
+ if image_1 .RasterXSize != image_2 .RasterXSize or image_1 . RasterYSize != image_2 . RasterYSize :
1079
+ image_1 = None
1080
+ image_2 = None
1077
1081
return 1000 # wrong size
1078
1082
1079
1083
square_sum = 0
1080
1084
for x in range (image_1 .RasterXSize ):
1081
1085
for y in range (image_1 .RasterYSize ):
1082
1086
square_sum += (image_1 .ReadAsArray ()[x ][y ] - image_2 .ReadAsArray ()[x ][y ]) ** 2
1083
1087
1088
+ # Explicitly close GDAL datasets
1089
+ image_1 = None
1090
+ image_2 = None
1084
1091
return sqrt (square_sum )
1085
1092
1086
1093
def _test_colors (self , colors ):
0 commit comments