Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint==2.15.*
pip install mock
pip install pylint==3.3.*
pip install requests==2.28.*
- name: Analysing the code with pylint
run: |
Expand Down
3 changes: 0 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ disable=line-too-long, duplicate-code
; [MASTER]
; init-hook='import sys; sys.path.append("/path/to/root")'
; init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"

[MASTER]
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
3 changes: 1 addition & 2 deletions conda_env/gdal-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ dependencies:
- python=3.10
- gdal=3.6.*
- requests=2.28.*
- pylint=2.15.*
- pylint=3.3.*
- geojson=2.5.*
- shapely=1.8.*
- osmium-tool=1.16.*
- bs4=4.11.*
- lxml=4.9.*
- matplotlib=3.4.3
- autopep8=2.0.*
- mock
- twine
- pip
- vulture
Expand Down
109 changes: 109 additions & 0 deletions tests/resources/tags-to-keep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"TAGS_TO_KEEP_UNIVERSAL": {
"access": "",
"area": "yes",
"bicycle": "",
"bridge": "",
"foot": [
"ft_yes",
"foot_designated"
],
"amenity": [
"fuel",
"cafe",
"drinking_water",
"shelter"
],
"shop": [
"bakery",
"bicycle"
],
"highway": [
"abandoned",
"bus_guideway",
"disused",
"bridleway",
"byway",
"construction",
"cycleway",
"footway",
"living_street",
"motorway",
"motorway_link",
"path",
"pedestrian",
"primary",
"primary_link",
"residential",
"road",
"secondary",
"secondary_link",
"service",
"steps",
"tertiary",
"tertiary_link",
"track",
"trunk",
"trunk_link",
"unclassified"
],
"natural": [
"coastline",
"nosea",
"sea",
"beach",
"land",
"scrub",
"water",
"wetland",
"wood"
],
"landuse": [
"forest",
"commercial",
"industrial",
"residential",
"retail"
],
"leisure": [
"park",
"nature_reserve"
],
"railway": [
"rail",
"tram",
"station",
"stop"
],
"surface": "",
"tracktype": "",
"tunnel": "",
"waterway": [
"canal",
"drain",
"river",
"riverbank",
"stream"
],
"wood": "deciduous",
"tourism": "alpine_hut"
},
"NAME_TAGS_TO_KEEP_UNIVERSAL": {
"admin_level": "2",
"area": "yes",
"mountain_pass": "",
"natural": "",
"place": [
"city",
"hamlet",
"island",
"isolated_dwelling",
"islet",
"locality",
"suburb",
"town",
"village",
"country"
]
}
}
7 changes: 4 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
tests for the python file
"""
import os
import sys
import unittest

# import custom python packages
Expand All @@ -17,7 +18,7 @@ def test_top_parser_help(self):
tests, if help of top parser can be called
"""

result = os.system("python -m wahoomc -h")
result = os.system(sys.executable + " -m wahoomc -h")

self.assertEqual(result, 0)

Expand All @@ -26,7 +27,7 @@ def test_cli_help(self):
tests, if CLI help can be called
"""

result = os.system("python -m wahoomc cli -h")
result = os.system(sys.executable + " -m wahoomc cli -h")

self.assertEqual(result, 0)

Expand All @@ -35,7 +36,7 @@ def test_gui_help(self):
tests, if GUI help can be called
"""

result = os.system("python -m wahoomc gui -h")
result = os.system(sys.executable + " -m wahoomc gui -h")

self.assertEqual(result, 0)

Expand Down
102 changes: 7 additions & 95 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,18 @@
"""
import os
import unittest
import mock


from wahoomc.constants_functions import translate_tags_to_keep, \
get_tag_wahoo_xml_path, TagWahooXmlNotFoundError
from wahoomc.constants import RESOURCES_DIR


tags_universal_simple = {"TAGS_TO_KEEP_UNIVERSAL": {
'access': '',
'area': 'yes'
}}

tags_universal_adv = {"TAGS_TO_KEEP_UNIVERSAL": {
'access': '',
'area': 'yes',
'bicycle': '',
'bridge': '',
'foot': ['ft_yes', 'foot_designated']
}}
from wahoomc.constants_functions import translate_tags_to_keep


class TestTranslateTags(unittest.TestCase):
"""
tests for translating tags-constants between the universal format and OS-specific formats
"""

@ mock.patch("wahoomc.file_directory_functions.json.load")
@ mock.patch("wahoomc.open")
def test_translate_tags_to_keep_simple_macos(self, mock_open, mock_json_load): # pylint: disable=unused-argument
"""
Test translating tags to keep from universal format to macOS
"""
tags = ['access', 'area=yes']
mock_json_load.return_value = tags_universal_simple

transl_tags = translate_tags_to_keep()
self.assertEqual(tags, transl_tags)

@ mock.patch("wahoomc.file_directory_functions.json.load")
@ mock.patch("wahoomc.open")
def test_translate_tags_to_keep_simple_win(self, mock_open, mock_json_load): # pylint: disable=unused-argument
"""
Test translating tags to keep from universal format to Windows
"""
tags_win = 'access= area=yes'
mock_json_load.return_value = tags_universal_simple

transl_tags = translate_tags_to_keep(sys_platform='Windows')
self.assertEqual(tags_win, transl_tags)

@ mock.patch("wahoomc.file_directory_functions.json.load")
@ mock.patch("wahoomc.open")
def test_translate_tags_to_keep_adv_macos(self, mock_open, mock_json_load): # pylint: disable=unused-argument
"""
Test translating tags to keep from universal format to macOS
"""
tags = ['access', 'area=yes', 'bicycle',
'bridge', 'foot=ft_yes, foot_designated']
mock_json_load.return_value = tags_universal_adv

transl_tags = translate_tags_to_keep()
self.assertEqual(tags, transl_tags)

@ mock.patch("wahoomc.file_directory_functions.json.load")
@ mock.patch("wahoomc.open")
def test_translate_tags_to_keep_adv_win(self, mock_open, mock_json_load): # pylint: disable=unused-argument
"""
Test translating tags to keep from universal format to Windows
"""
tags_win = 'access= area=yes bicycle= bridge= foot=ft_yes =foot_designated'
mock_json_load.return_value = tags_universal_adv

transl_tags = translate_tags_to_keep(sys_platform='Windows')
self.assertEqual(tags_win, transl_tags)
def setUp(self):
self.tags_to_keep = os.path.join(os.path.dirname(__file__), 'resources', 'tags-to-keep.json')

def test_translate_tags_to_keep_full_macos(self):
"""
Expand All @@ -91,7 +28,7 @@ def test_translate_tags_to_keep_full_macos(self):
'leisure=park, nature_reserve', 'railway=rail, tram, station, stop',
'surface', 'tracktype', 'tunnel', 'waterway=canal, drain, river, riverbank, stream', 'wood=deciduous', 'tourism=alpine_hut']

transl_tags = translate_tags_to_keep(use_repo=True)
transl_tags = translate_tags_to_keep(self.tags_to_keep)
self.assertEqual(tags, transl_tags)

def test_translate_tags_to_keep_full_win(self):
Expand All @@ -100,8 +37,7 @@ def test_translate_tags_to_keep_full_win(self):
"""
tags_win = 'access= area=yes bicycle= bridge= foot=ft_yes =foot_designated amenity=fuel =cafe =drinking_water =shelter shop=bakery =bicycle highway=abandoned =bus_guideway =disused =bridleway =byway =construction =cycleway =footway =living_street =motorway =motorway_link =path =pedestrian =primary =primary_link =residential =road =secondary =secondary_link =service =steps =tertiary =tertiary_link =track =trunk =trunk_link =unclassified natural=coastline =nosea =sea =beach =land =scrub =water =wetland =wood landuse=forest =commercial =industrial =residential =retail leisure=park =nature_reserve railway=rail =tram =station =stop surface= tracktype= tunnel= waterway=canal =drain =river =riverbank =stream wood=deciduous tourism=alpine_hut'

transl_tags = translate_tags_to_keep(
sys_platform='Windows', use_repo=True)
transl_tags = translate_tags_to_keep(self.tags_to_keep, osmium=False)
self.assertEqual(tags_win, transl_tags)

def test_translate_name_tags_to_keep_full_macos(self):
Expand All @@ -111,7 +47,7 @@ def test_translate_name_tags_to_keep_full_macos(self):
names_tags = ['admin_level=2', 'area=yes', 'mountain_pass', 'natural',
'place=city, hamlet, island, isolated_dwelling, islet, locality, suburb, town, village, country']

transl_tags = translate_tags_to_keep(name_tags=True, use_repo=True)
transl_tags = translate_tags_to_keep(self.tags_to_keep, name_tags=True)
self.assertEqual(names_tags, transl_tags)

def test_translate_name_tags_to_keep_full_win(self):
Expand All @@ -121,33 +57,9 @@ def test_translate_name_tags_to_keep_full_win(self):

names_tags_win = 'admin_level=2 area=yes mountain_pass= natural= place=city =hamlet =island =isolated_dwelling =islet =locality =suburb =town =village =country'

transl_tags = translate_tags_to_keep(
name_tags=True, sys_platform='Windows', use_repo=True)
transl_tags = translate_tags_to_keep(self.tags_to_keep, name_tags=True, osmium=False)
self.assertEqual(names_tags_win, transl_tags)


class TestTagWahooXML(unittest.TestCase):
"""
tests for tag-wahoo xml file
"""

def test_not_existing_tag_wahoo_xml(self):
"""
check if a non-existing tag-wahoo xml file issues an exception
"""
with self.assertRaises(TagWahooXmlNotFoundError):
get_tag_wahoo_xml_path("not_existing.xml")

def test_existing_tag_wahoo_xml(self):
"""
check if the correct path of an existing tag-wahoo xml file is returned
"""

expected_path = os.path.join(
RESOURCES_DIR, "tag_wahoo_adjusted", "tag-wahoo-poi.xml")
self.assertEqual(get_tag_wahoo_xml_path(
"tag-wahoo-poi.xml"), expected_path)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_download_macos_files(self):
"""
if platform.system() != "Windows":
path = os.path.join(str(constants.USER_DIR), '.openstreetmap', 'osmosis',
'plugins', 'mapsforge-map-writer-0.21.0-jar-with-dependencies.jar')
'plugins', 'mapsforge-map-writer-0.25.0-jar-with-dependencies.jar')

if os.path.exists(path):
os.remove(path)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_generated_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from os import walk
import platform
import shutil
import sys
import unittest
import subprocess

Expand Down Expand Up @@ -214,11 +215,11 @@ def run_wahoomapscreator_cli(self, country, hdd_mode=False):
if not hdd_mode:
# run processing of input-country via CLI in standard mode
result = os.system(
f'python -m wahoomc cli -co {country} -tag tag-wahoo.xml -fp -c -md 9999 -nbc')
f'{sys.executable} -m wahoomc cli -co {country} -tag tag-wahoo.xml -fp -c -md 9999 -nbc')
else:
# run processing of input-country via CLI in mapwriter hdd mode
result = os.system(
f'python -m wahoomc cli -co {country} -tag tag-wahoo.xml -fp -c -md 9999 -nbc -hd')
f'{sys.executable} -m wahoomc cli -co {country} -tag tag-wahoo.xml -fp -c -md 9999 -nbc -hdd')

# check if run was successful
self.assertEqual(result, 0)
Expand Down
Loading