Skip to content

Commit 2906a56

Browse files
authored
[DEV] macOS: Check .osm.pbf files in unittests with osmium diff (due to osmium-tool upgrade) (#176)
* compare osm filetypes using "osmium diff" in unittests corrects changes due to osmium-tool v1.15.0. Most probably just this change in the .osm.pbf files: "generator=osmium/1.15.0" * keep existing behavior for Windows * PR review changes
1 parent 008e0b5 commit 2906a56

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

tests/test_generated_files.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import platform
99
import shutil
1010
import unittest
11+
import subprocess
1112

1213

1314
# import custom python packages
@@ -148,22 +149,9 @@ def compare_dir_sub_test_resource_and_output(self, dir_to_compare, country):
148149
calculated_output_file = os.path.join(
149150
constants.USER_OUTPUT_DIR, dir_to_compare, directory, file)
150151

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)
167155

168156
# check files in given dir - {country} folder. filtered_* files
169157
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):
174162
calculated_output_file = os.path.join(
175163
constants.USER_OUTPUT_DIR, country, file)
176164

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.')
180195

181196

182197
if __name__ == '__main__':

0 commit comments

Comments
 (0)