8
8
import platform
9
9
import shutil
10
10
import unittest
11
+ import subprocess
11
12
12
13
13
14
# import custom python packages
@@ -148,22 +149,9 @@ def compare_dir_sub_test_resource_and_output(self, dir_to_compare, country):
148
149
calculated_output_file = os .path .join (
149
150
constants .USER_OUTPUT_DIR , dir_to_compare , directory , file )
150
151
151
- # is file equal?
152
- self .assertTrue (filecmp .cmp (given_output_file , calculated_output_file ,
153
- shallow = False ), f'not equal: { calculated_output_file } ' )
154
-
155
- # check files in given dir
156
- # for file in get_files_in_folder(path_to_dir):
157
- # if file == '.DS_Store':
158
- # continue
159
- # given_output_file = os.path.join(
160
- # path_to_dir, file)
161
- # calculated_output_file = os.path.join(
162
- # constants.USER_OUTPUT_DIR, dir_to_compare, file)
163
-
164
- # # is file equal?
165
- # self.assertTrue(filecmp.cmp(given_output_file, calculated_output_file,
166
- # shallow=False), f'not equal: {calculated_output_file}')
152
+ # are these two files equal?
153
+ self .compare_two_map_files (
154
+ given_output_file , calculated_output_file )
167
155
168
156
# check files in given dir - {country} folder. filtered_* files
169
157
for file in get_files_in_folder (os .path .join (path_to_dir , country )):
@@ -174,9 +162,36 @@ def compare_dir_sub_test_resource_and_output(self, dir_to_compare, country):
174
162
calculated_output_file = os .path .join (
175
163
constants .USER_OUTPUT_DIR , country , file )
176
164
177
- # is file equal?
178
- self .assertTrue (filecmp .cmp (given_output_file , calculated_output_file ,
179
- shallow = False ), f'not equal: { calculated_output_file } ' )
165
+ # are these two files equal?
166
+ self .compare_two_map_files (
167
+ given_output_file , calculated_output_file )
168
+
169
+ def compare_two_map_files (self , given_file , calculated_file ):
170
+ """
171
+ compare two given (map) files for equalness.
172
+ macOS / Linux:
173
+ - classic map files are compared using CLI command "osmium diff",
174
+ - the others are compared using "filecmp.cmp"
175
+ Windows:
176
+ - compare all files using "filecmp.cmp".
177
+ osmosis and osmconvert do not offer a possibility to compare with returning a errorcode
178
+ """
179
+
180
+ no_osmosis_file_extensions = ['shx' , 'shp' , 'prj' ]
181
+
182
+ # some file extensions can not be comapared using osmium
183
+ if given_file .split ('.' )[- 1 ] in no_osmosis_file_extensions or \
184
+ platform .system () == "Windows" :
185
+ self .assertTrue (filecmp .cmp (given_file , calculated_file ,
186
+ shallow = False ), f'not equal: { calculated_file } . Using filecmp.cmp.' )
187
+ # compare map files using osmium
188
+ else :
189
+ cmd = ['osmium' , 'diff' , '-q' ,
190
+ given_file , calculated_file ]
191
+ result = subprocess .run (cmd , check = False )
192
+
193
+ self .assertEqual (
194
+ 0 , result .returncode , f'not equal: { calculated_file } . Using osmium diff.' )
180
195
181
196
182
197
if __name__ == '__main__' :
0 commit comments