Skip to content

Commit 999067b

Browse files
refactor: Use enums for GPX examples (#105)
1 parent 586a800 commit 999067b

16 files changed

+150
-51
lines changed

pretty_gpx/common/data/examples.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/python3
2+
"""GPX examples."""
3+
import os
4+
from enum import auto
5+
from enum import Enum
6+
7+
from pretty_gpx.common.utils.paths import EXAMPLES_DIR
8+
9+
10+
class CyclingGpx(Enum):
11+
"""Cycling GPX examples."""
12+
AMBERIEU = auto()
13+
ANCIZAN_PEYRESOURDE_AZET_ASPIN = auto()
14+
COUILLOLE = auto()
15+
HAWAII = auto()
16+
MARMOTTE = auto()
17+
SOULOR_AUBISQUE_SPANDELLES = auto()
18+
VENTOUX = auto()
19+
20+
@staticmethod
21+
def folder() -> str:
22+
"""Return the folder where cycling GPX examples are stored."""
23+
return os.path.join(EXAMPLES_DIR, 'cycling')
24+
25+
@property
26+
def path(self) -> str:
27+
"""Path to the GPX file."""
28+
return os.path.join(self.folder(), f'{self.name.lower()}.gpx')
29+
30+
31+
class HikingGpx(Enum):
32+
"""Hiking GPX examples."""
33+
ARAILLE = auto()
34+
CABALIROS = auto()
35+
DIAGONALE_DES_FOUS = auto()
36+
UTMB = auto()
37+
VANOISE = auto()
38+
VANOISE_1 = auto()
39+
VANOISE_2 = auto()
40+
VANOISE_3 = auto()
41+
42+
@staticmethod
43+
def folder() -> str:
44+
"""Return the folder where hiking GPX examples are stored."""
45+
return os.path.join(EXAMPLES_DIR, 'hiking')
46+
47+
@property
48+
def path(self) -> str:
49+
"""Path to the GPX file."""
50+
return os.path.join(self.folder(), f'{self.name.lower()}.gpx')
51+
52+
53+
class RunningGpx(Enum):
54+
"""Running GPX examples."""
55+
HALF_MARATHON_DEAUVILLE = auto()
56+
MARATHON_BERLIN = auto()
57+
MARATHON_BORDEAUX = auto()
58+
MARATHON_CHICAGO = auto()
59+
MARATHON_LONDON = auto()
60+
MARATHON_NEW_YORK = auto()
61+
MARATHON_NICE_CANNES = auto()
62+
MARATHON_PARIS = auto()
63+
MARATHON_RENNES = auto()
64+
PARIS_VERSAILLES = auto()
65+
ROUTE_4_CHATEAUX = auto()
66+
TEN_K_PARIS = auto()
67+
68+
@staticmethod
69+
def folder() -> str:
70+
"""Return the folder where running GPX examples are stored."""
71+
return os.path.join(EXAMPLES_DIR, 'running')
72+
73+
@property
74+
def path(self) -> str:
75+
"""Path to the GPX file."""
76+
return os.path.join(self.folder(), f'{self.name.lower()}.gpx')

pretty_gpx/common/utils/paths.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
COLOR_EXPLORATION_DIR = os.path.join(DATA_DIR, 'color_exploration')
1010

1111
EXAMPLES_DIR = os.path.join(MAIN_DIR, 'examples')
12-
CYCLING_DIR = os.path.join(EXAMPLES_DIR, 'cycling')
13-
HIKING_DIR = os.path.join(EXAMPLES_DIR, 'hiking')
14-
RUNNING_DIR = os.path.join(EXAMPLES_DIR, 'running')
1512

1613
ASSETS_DIR = os.path.join(MAIN_DIR, 'assets')
1714
ICONS_DIR = os.path.join(ASSETS_DIR, 'icons')

pretty_gpx/test/test_bridges.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#!/usr/bin/python3
22
"""Test Bridges."""
3-
import os
43

4+
from pretty_gpx.common.data.examples import RunningGpx
55
from pretty_gpx.common.gpx.gpx_track import GpxTrack
66
from pretty_gpx.common.request.overpass_request import OverpassQuery
77
from pretty_gpx.common.utils.asserts import assert_same_keys
8-
from pretty_gpx.common.utils.paths import RUNNING_DIR
98
from pretty_gpx.rendering_modes.city.data.bridges import prepare_download_city_bridges
109
from pretty_gpx.rendering_modes.city.data.bridges import process_city_bridges
1110

1211

13-
def __core_test_bridges(path: str, gt_names: set[str]) -> None:
12+
def __core_test_bridges(scene: RunningGpx, gt_names: set[str]) -> None:
1413
"""Test Bridges."""
1514
# GIVEN
16-
gpx = GpxTrack.load(path)
15+
gpx = GpxTrack.load(scene.path)
1716

1817
# WHEN
1918
query = OverpassQuery()
@@ -26,7 +25,7 @@ def __core_test_bridges(path: str, gt_names: set[str]) -> None:
2625

2726
def test_chicago_bridges() -> None:
2827
"""Test Chicago Bridges."""
29-
__core_test_bridges(os.path.join(RUNNING_DIR, "marathon_chicago.gpx"),
28+
__core_test_bridges(RunningGpx.MARATHON_CHICAGO,
3029
{'William P. Fahey Bridge',
3130
'State Street Bridge (Chicago)',
3231
'Marshall Suloway Bridge',
@@ -37,14 +36,14 @@ def test_chicago_bridges() -> None:
3736

3837
def test_paris_bridges() -> None:
3938
"""Test Paris Bridges."""
40-
__core_test_bridges(os.path.join(RUNNING_DIR, "10k_paris.gpx"),
39+
__core_test_bridges(RunningGpx.TEN_K_PARIS,
4140
{'Pont des Invalides',
4241
'Pont du Carrousel'})
4342

4443

4544
def test_new_york_bridges() -> None:
4645
"""Test New York Bridges."""
47-
__core_test_bridges(os.path.join(RUNNING_DIR, "marathon_new_york.gpx"),
46+
__core_test_bridges(RunningGpx.MARATHON_NEW_YORK,
4847
{"Madison Avenue Bridge",
4948
"Pulaski Bridge",
5049
"Willis Avenue Bridge",
@@ -54,7 +53,7 @@ def test_new_york_bridges() -> None:
5453

5554
def test_berlin_bridges() -> None:
5655
"""Test Berlin Bridges."""
57-
__core_test_bridges(os.path.join(RUNNING_DIR, "marathon_berlin.gpx"),
56+
__core_test_bridges(RunningGpx.MARATHON_BERLIN,
5857
{"Charlottenburger Brücke",
5958
"Kronprinzenbrücke",
6059
"Marchbrücke",
@@ -67,12 +66,12 @@ def test_berlin_bridges() -> None:
6766

6867
def test_london_bridges() -> None:
6968
"""Test London Bridges."""
70-
__core_test_bridges(os.path.join(RUNNING_DIR, "marathon_london.gpx"),
69+
__core_test_bridges(RunningGpx.MARATHON_LONDON,
7170
{"Tower Bridge"})
7271

7372

7473
def test_bordeaux_bridges() -> None:
7574
"""Test Bordeaux Bridges."""
76-
__core_test_bridges(os.path.join(RUNNING_DIR, "marathon_bordeaux.gpx"),
75+
__core_test_bridges(RunningGpx.MARATHON_BORDEAUX,
7776
{"Pont de Pierre",
7877
"Pont Jacques Chaban-Delmas"})
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#!/usr/bin/python3
22
"""Test City Drawer."""
3-
import os
43

54
import matplotlib.pyplot as plt
65

6+
from pretty_gpx.common.data.examples import RunningGpx
77
from pretty_gpx.common.layout.paper_size import PAPER_SIZES
8-
from pretty_gpx.common.utils.paths import RUNNING_DIR
98
from pretty_gpx.rendering_modes.city.drawing.city_drawer import CityDrawer
109
from pretty_gpx.rendering_modes.city.drawing.city_params import CityParams
1110

1211

13-
def __core_test_city_drawer(path: str) -> None:
12+
def __core_test_city_drawer(scene: RunningGpx) -> None:
1413
"""Test City Drawer."""
1514
drawer = CityDrawer(params=CityParams.default(), top_ratio=0.18, bot_ratio=0.22, margin_ratio=0.1)
16-
drawer.change_gpx(path, PAPER_SIZES["A4"])
15+
drawer.change_gpx(scene.path, PAPER_SIZES["A4"])
1716
for paper_size in [PAPER_SIZES["32x32"], PAPER_SIZES["A4"], PAPER_SIZES["40x30"]]:
1817
drawer.change_papersize(paper_size)
1918
fig, ax = plt.subplots()
@@ -22,4 +21,4 @@ def __core_test_city_drawer(path: str) -> None:
2221

2322
def test_10k_paris_city_drawer() -> None:
2423
"""Test 10k Paris City Drawer."""
25-
__core_test_city_drawer(os.path.join(RUNNING_DIR, "10k_paris.gpx"))
24+
__core_test_city_drawer(RunningGpx.TEN_K_PARIS)

0 commit comments

Comments
 (0)