Skip to content

Commit

Permalink
[DEV] Correct unittests of generated files for v3.0.0 changes (#163)
Browse files Browse the repository at this point in the history
* correct unittests for generated files

- to correctly check the X/Y files
- the other ones Y.map, Y.map.lzma are different each run it seams...

* add country folders to comparison

* add macOS files

* add Windows files

* workaround for pylint finding
  • Loading branch information
treee111 authored Oct 31, 2022
1 parent 9157286 commit 4aaf161
Show file tree
Hide file tree
Showing 31 changed files with 50 additions and 19 deletions.
Binary file modified tests/resources/macos/134/89.map
Binary file not shown.
Binary file modified tests/resources/macos/134/89.map.lzma
Binary file not shown.
File renamed without changes.
Binary file modified tests/resources/macos/138/100.map
Binary file not shown.
Binary file modified tests/resources/macos/138/100.map.lzma
Binary file not shown.
File renamed without changes.
Binary file removed tests/resources/macos/filtered-malta.o5m.pbf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/resources/macos/malta/filtered.o5m.pbf
Binary file not shown.
Binary file not shown.
Binary file modified tests/resources/windows/134/89.map
Binary file not shown.
Binary file modified tests/resources/windows/134/89.map.lzma
Binary file not shown.
File renamed without changes.
Binary file modified tests/resources/windows/134/89/merged.osm.pbf
Binary file not shown.
Binary file modified tests/resources/windows/134/89/split-liechtenstein-names.osm.pbf
Binary file not shown.
Binary file modified tests/resources/windows/134/89/split-liechtenstein.osm.pbf
Binary file not shown.
Binary file modified tests/resources/windows/138/100.map
Binary file not shown.
Binary file modified tests/resources/windows/138/100.map.lzma
Binary file not shown.
File renamed without changes.
Binary file modified tests/resources/windows/138/100/merged.osm.pbf
Binary file not shown.
Binary file modified tests/resources/windows/138/100/split-malta-names.osm.pbf
Binary file not shown.
Binary file modified tests/resources/windows/138/100/split-malta.osm.pbf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/resources/windows/liechtenstein/outFile.o5m
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/resources/windows/malta/outFile.o5m
Binary file not shown.
Binary file not shown.
69 changes: 50 additions & 19 deletions tests/test_generated_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# import custom python packages
from wahoomc import constants
from wahoomc.file_directory_functions import get_files_in_folder

dirname_of_file = os.path.dirname(__file__)

Expand Down Expand Up @@ -80,8 +81,7 @@ def test_calc_output_malta_and_compare(self):
self.run_wahoomapscreator_cli('malta')

# compare generated given merged.osm.pbf-file with reference-file
self.compare_dir_sub_test_resource_and_output(
os.path.join('138', '100'))
self.compare_dir_sub_test_resource_and_output('138', 'malta')

def test_calc_output_liechtenstein_and_compare(self):
"""
Expand All @@ -92,8 +92,7 @@ def test_calc_output_liechtenstein_and_compare(self):
self.run_wahoomapscreator_cli('liechtenstein')

# compare generated given merged.osm.pbf-file with reference-file
self.compare_dir_sub_test_resource_and_output(
os.path.join('134', '89'))
self.compare_dir_sub_test_resource_and_output('134', 'liechtenstein')

def run_wahoomapscreator_cli(self, country):
"""
Expand All @@ -107,25 +106,43 @@ def run_wahoomapscreator_cli(self, country):
# check if run was successful
self.assertEqual(result, 0)

def compare_dir_sub_test_resource_and_output(self, dir_to_compare):
def test_malta_compare(self):
"""
compare output of malta
- of malta
"""
# compare generated X/Y files with reference-file
self.compare_dir_sub_test_resource_and_output('138', 'malta')

def test_liechtenstein_compare(self):
"""
compare output of malta
- of liechtenstein
"""
# compare generated X/Y files with reference-file
self.compare_dir_sub_test_resource_and_output('134', 'liechtenstein')

def compare_dir_sub_test_resource_and_output(self, dir_to_compare, country):
"""
compare files from given directory and subdirectories for equalness.
check the files which are in test/resources folder
"""

if platform.system() == "Windows":
path_to_dir = os.path.join(
dirname_of_file, 'resources', 'windows', dir_to_compare)
dirname_of_file, 'resources', 'windows')
else:
path_to_dir = os.path.join(
dirname_of_file, 'resources', 'macos', dir_to_compare)
dirname_of_file, 'resources', 'macos')

# check files in subdir of given dir
for (dirpath, dirnames, filenames) in walk(path_to_dir):
# check files in subdir of given dir (i.e. the X/Y directory)
for (dirpath, dirnames, filenames) in walk(os.path.join(path_to_dir, dir_to_compare)): # pylint: disable=unused-variable
for directory in dirnames:
for (dirpath_2, dirnames_2, filenames_2) in walk(os.path.join( # pylint: disable=unused-variable
dirpath, directory)):
for file in filenames_2:
if file == '.DS_Store':
continue
given_output_file = os.path.join(
dirpath_2, file)
calculated_output_file = os.path.join(
Expand All @@ -136,16 +153,30 @@ def compare_dir_sub_test_resource_and_output(self, dir_to_compare):
shallow=False), f'not equal: {calculated_output_file}')

# check files in given dir
for (dirpath, dirnames, filenames) in walk(path_to_dir):
for file in filenames:
given_output_file = os.path.join(
dirpath, file)
calculated_output_file = os.path.join(
constants.USER_OUTPUT_DIR, dir_to_compare, file)

# is file equal?
self.assertTrue(filecmp.cmp(given_output_file, calculated_output_file,
shallow=False), f'not equal: {calculated_output_file}')
# for file in get_files_in_folder(path_to_dir):
# if file == '.DS_Store':
# continue
# given_output_file = os.path.join(
# path_to_dir, file)
# calculated_output_file = os.path.join(
# constants.USER_OUTPUT_DIR, dir_to_compare, file)

# # is file equal?
# self.assertTrue(filecmp.cmp(given_output_file, calculated_output_file,
# shallow=False), f'not equal: {calculated_output_file}')

# check files in given dir - {country} folder. filtered_* files
for file in get_files_in_folder(os.path.join(path_to_dir, country)):
if file == '.DS_Store':
continue
given_output_file = os.path.join(
path_to_dir, country, file)
calculated_output_file = os.path.join(
constants.USER_OUTPUT_DIR, country, file)

# is file equal?
self.assertTrue(filecmp.cmp(given_output_file, calculated_output_file,
shallow=False), f'not equal: {calculated_output_file}')


if __name__ == '__main__':
Expand Down

0 comments on commit 4aaf161

Please sign in to comment.