Skip to content

Commit

Permalink
[DEV] Fix unittests (#222)
Browse files Browse the repository at this point in the history
* update static unittest files macOS

- due to changes in included OSM elements from #206 b8f4d16 and #201 f6a4b99

* Adjust test_constants to match the new tags added to tags-to-keep.json

* update static unittest files Windows

- plus adding 100/137 as this was not inclued before in Windows, but in macOS
- due to changes in included OSM elements from #206 b8f4d16 and #201 f6a4b99

* integrate unittests into CONTRIBUTING.md

- incl. refactoing the file & link to land-poligons
- remove not needed headlines

---------

Co-authored-by: Alf Høgemark <alf@i100.no>
  • Loading branch information
treee111 and alfh authored Nov 4, 2023
1 parent 4b53962 commit 04f09ac
Show file tree
Hide file tree
Showing 43 changed files with 8,567 additions and 17 deletions.
42 changes: 29 additions & 13 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#### Table of contents <!-- omit in toc -->
- [How to Contribute](#how-to-contribute)
- [Developer Anaconda environment](#developer-anaconda-environment)
- [Developer Anaconda environment](#developer-anaconda-environment)
- [Pylint](#pylint)
- [Unittests](#unittests)
- [Structure of the repository](#structure-of-the-repository)
- [User directory](#user-directory)
- [Git Guidelines](#git-guidelines)
Expand All @@ -15,20 +17,22 @@
- [Release](#release)
- [Automatic CHANGELOG creation](#automatic-changelog-creation)
- [PyPI commands](#pypi-commands)
- [Other command](#other-command)

## How to Contribute
1. Create a Anaconda environment for developers
- 👉 [Developer Anaconda environment](#developer-anaconda-environment)
2. Create a branch by forking the repository and apply your change.
3. Commit and push your change on that branch.
4. Create a pull request.
4. Run Pylint with 10.00/10
5. Run unittests successfully
6. Create a pull request.
- 👉 **Please follow the [Git Guidlines](#Git-Guidelines).**
5. Wait for our code review and approval, possibly enhancing your change on request.
7. Wait for our code review and approval, possibly enhancing your change on request.
- Note that the wahooMapsCreator maintainers have many duties. So, depending on the required effort for reviewing, testing, and clarification, this may take a while.
6. Once the change has been approved and merged, we will inform you in a comment.
7. Celebrate! 🎉
8. Once the change has been approved and merged, we will inform you in a comment.
9. Celebrate! 🎉

## Developer Anaconda environment
### Developer Anaconda environment
- /conda_env/gdal-user.yml is for creating Anaconda environment for users
- /conda_env/gdal-dev.yml is for creating Anaconda environment for developers

Expand All @@ -50,6 +54,24 @@ The .yml files with only the installed packages were created via
conda env export > environment.yml --from-history
```

### Pylint
Run pylint for all relevant directories/files
```
pylint -j 0 ./wahoomc ./tests
```

### Unittests
Python unittests are defined in the directory `tests`.
They can be started via "Testing" pane from VSCode or via terminal in the root of the repo with
```
python -m unittest
```

For the `test_generated_files.py` unittests to run successful, static land-poligons-file and static country files are needed to ensure equal results. The country files are included in the repo in `tests/resources`, the land-poligons-file needs to be downloaded from https://1drv.ms/u/s!AnpNcYd7Zz7TnXorg_zZuvsbMGsJ?e=fL6zvM and extracted to `~/wahooMapsCreatorData/_unittest/` like this:
<img src="./pictures/unittest-land-poligons.png" alt="land-poligons extracted for unittests" width=50%>

More information about Python unittest can be read here: https://docs.python.org/3/library/unittest.html.

## Structure of the repository
There is one python coding base for both Windows and for macOS.
Differences between the different OS are the used programs.
Expand Down Expand Up @@ -125,9 +147,3 @@ py -m build
```
twine upload dist\*
```

## Other command
Run pylint for all relevant directories/files
```
pylint -j 0 ./wahoomc ./tests
```
2 changes: 1 addition & 1 deletion docs/COPY_TO_WAHOO.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Copy the the whole content of the country- or X/Y folder or just the content of

After copying, it should look like that:

<img src="./pictures/maps-file-structure.png" alt="filestructure on device" width=30%>
<img src="./pictures/maps-file-structure.png" alt="filestructure on device" width=50%>

For another way of explanation, see [here](FAQ.md#where-on-my-wahoo-do-i-have-to-copy-the-maps)

Expand Down
Binary file added docs/pictures/unittest-land-poligons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Binary file modified tests/resources/macos/134/89/merged.osm.pbf
Binary file not shown.
Binary file modified tests/resources/macos/134/89/split-liechtenstein-names.osm.pbf
Binary file not shown.
Binary file modified tests/resources/macos/134/89/split-liechtenstein.osm.pbf
Binary file not shown.
Binary file modified tests/resources/macos/137/100.map
Binary file not shown.
Binary file modified tests/resources/macos/137/100.map.lzma
Binary file not shown.
Binary file modified tests/resources/macos/137/100/split-malta-names.osm.pbf
Binary file not shown.
Binary file modified tests/resources/macos/137/100/split-malta.osm.pbf
Binary file not shown.
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.
Binary file modified tests/resources/macos/138/100/merged.osm.pbf
Binary file not shown.
Binary file modified tests/resources/macos/138/100/split-malta-names.osm.pbf
Binary file not shown.
Binary file modified tests/resources/macos/138/100/split-malta.osm.pbf
Binary file not shown.
Binary file modified tests/resources/macos/liechtenstein/filtered.o5m.pbf
Binary file not shown.
Binary file modified tests/resources/macos/malta/filtered.o5m.pbf
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.
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 added tests/resources/windows/137/100.map
Binary file not shown.
Binary file added tests/resources/windows/137/100.map.lzma
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions tests/resources/windows/137/100/land.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file added tests/resources/windows/137/100/land.shp
Binary file not shown.
Binary file added tests/resources/windows/137/100/land.shx
Binary file not shown.
8,516 changes: 8,516 additions & 0 deletions tests/resources/windows/137/100/land1.osm

Large diffs are not rendered by default.

Binary file added tests/resources/windows/137/100/merged.osm.pbf
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/resources/windows/137/100/sea.osm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6">
<node timestamp="1969-12-31T23:59:59Z" changeset="-1" id="32951459320" version="1" lon="12.556250" lat="35.360670" />
<node timestamp="1969-12-31T23:59:59Z" changeset="-1" id="32951459321" version="1" lon="12.556250" lat="36.697889" />
<node timestamp="1969-12-31T23:59:59Z" changeset="-1" id="32951459322" version="1" lon="14.162500" lat="36.697889" />
<node timestamp="1969-12-31T23:59:59Z" changeset="-1" id="32951459323" version="1" lon="14.162500" lat="35.360670" />
<way timestamp="1969-12-31T23:59:59Z" changeset="-1" id="32951623372" version="1">
<nd ref="32951459320" />
<nd ref="32951459321" />
<nd ref="32951459322" />
<nd ref="32951459323" />
<nd ref="32951459320" />
<tag k="area" v="yes" />
<tag k="layer" v="-5" />
<tag k="natural" v="sea" />
</way>
</osm>
Binary file not shown.
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.
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 modified tests/resources/windows/liechtenstein/filtered.o5m
Binary file not shown.
Binary file modified tests/resources/windows/malta/filtered.o5m
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ def test_translate_tags_to_keep_full_macos(self):
Test translating tags to keep from universal format to macOS // all "tags to keep"
"""
tags = ['access', 'area=yes', 'bicycle', 'bridge', 'foot=ft_yes, foot_designated',
'amenity=fuel, cafe, drinking_water', 'shop=bakery, bicycle',
'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', 'wood=deciduous']
'surface', 'tracktype', 'tunnel', 'waterway=canal, drain, river, riverbank, stream', 'wood=deciduous', 'tourism=alpine_hut']

transl_tags = translate_tags_to_keep(use_repo=True)
self.assertEqual(tags, transl_tags)
Expand All @@ -98,7 +98,7 @@ def test_translate_tags_to_keep_full_win(self):
"""
Test translating tags to keep from universal format to Windows // all "tags to keep"
"""
tags_win = 'access= area=yes bicycle= bridge= foot=ft_yes =foot_designated amenity=fuel =cafe =drinking_water 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 wood=deciduous'
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)
Expand Down

0 comments on commit 04f09ac

Please sign in to comment.