Skip to content

Commit

Permalink
test: coordinates import (GPX, IOF XML, CSV)
Browse files Browse the repository at this point in the history
  • Loading branch information
sembruk committed Dec 9, 2024
1 parent faa1b0f commit afcab90
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/data/course.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
start, 0, 0,
31, 100, -359,
32, -214, -462,
33, -574, -309,
34, -482, 82,
finish, -194, 177,
24 changes: 24 additions & 0 deletions tests/data/course.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="http://nakarte.me" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1">
<metadata>
<time>2024-12-09T11:18:14.987Z</time>
</metadata>
<wpt lat="55.753317" lon="37.621758">
<name>start</name>
</wpt>
<wpt lat="55.750110" lon="37.623464">
<name>31</name>
</wpt>
<wpt lat="55.749132" lon="37.618496">
<name>32</name>
</wpt>
<wpt lat="55.750440" lon="37.612719">
<name>33</name>
</wpt>
<wpt lat="55.753975" lon="37.614060">
<name>34</name>
</wpt>
<wpt lat="55.754874" lon="37.618614">
<name>finish</name>
</wpt>
</gpx>
53 changes: 53 additions & 0 deletions tests/data/course.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<CourseData xmlns="http://www.orienteering.org/datastandard/3.0" iofVersion="3.0" creator="OpenOrienteering Mapper 0.9.6" createTime="2024-12-09T16:01:14">
<Event>
<Name>Test event</Name>
</Event>
<RaceCourseData>
<Control>
<Id>S1</Id>
<Position lng="37.621758" lat="55.753317"/>
</Control>
<Control>
<Id>31</Id>
<Position lng="37.623464" lat="55.75011"/>
</Control>
<Control>
<Id>32</Id>
<Position lng="37.6184959" lat="55.749132"/>
</Control>
<Control>
<Id>33</Id>
<Position lng="37.6127191" lat="55.75044"/>
</Control>
<Control>
<Id>34</Id>
<Position lng="37.61406" lat="55.753975"/>
</Control>
<Control>
<Id>F1</Id>
<Position lng="37.6186141" lat="55.754874"/>
</Control>
<Course>
<Name>Test course</Name>
<CourseControl type="Start">
<Control>S1</Control>
</CourseControl>
<CourseControl type="Control">
<Control>31</Control>
</CourseControl>
<CourseControl type="Control">
<Control>32</Control>
</CourseControl>
<CourseControl type="Control">
<Control>33</Control>
</CourseControl>
<CourseControl type="Control">
<Control>34</Control>
</CourseControl>
<CourseControl type="Finish">
<Control>F1</Control>
</CourseControl>
</Course>
</RaceCourseData>
</CourseData>
37 changes: 37 additions & 0 deletions tests/test_coords_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest

from sportorg.models.memory import race
from sportorg.modules.coordinates.coordinates import import_coordinates_from_gpx, import_coordinates_from_iof_xml, import_coordinates_from_csv

@pytest.mark.parametrize(
'file_name, function',
[
('course.gpx', import_coordinates_from_gpx),
('course.xml', import_coordinates_from_iof_xml),
('course.csv', import_coordinates_from_csv),
]
)

def test_import_coordinates_from_gpx(file_name, function):
cur_race = race()
cur_race.control_points = [] # Clear control points to ensure test isolation

function('tests/data/' + file_name)
assert len(cur_race.control_points) == 6

expected = [
('31', 3, 100, -359),
('32', 3, -214, -462),
('33', 3, -574, -309),
('34', 3, -482, 82),
('finish', 0, -194, 177),
('start', 0, 0, 0),
]

for i, (code, score, x, y) in enumerate(expected):
cp = cur_race.control_points[i]
assert cp.code == code
assert cp.score == score
assert cp.x == x
assert cp.y == y

0 comments on commit afcab90

Please sign in to comment.