aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-07-07 22:40:59 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-07-07 22:40:59 +0200
commit264612664a24447c929cfd71659d44dd95a8e3a9 (patch)
tree91aba9ebbec7e289f4db0b75b0f991b0c314b8eb /tests/unit
parent0ed840d92ef519790fa48c3d5941260e88093e77 (diff)
downloadfietsboek-264612664a24447c929cfd71659d44dd95a8e3a9.tar.gz
fietsboek-264612664a24447c929cfd71659d44dd95a8e3a9.tar.bz2
fietsboek-264612664a24447c929cfd71659d44dd95a8e3a9.zip
add tests for util.guess_gpx_timezone
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_util.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py
index c595e4e..8f45611 100644
--- a/tests/unit/test_util.py
+++ b/tests/unit/test_util.py
@@ -1,6 +1,9 @@
+import gzip
from datetime import timedelta
+from pathlib import Path
import pytest
+import gpxpy
from markupsafe import Markup
from fietsboek import util
@@ -52,6 +55,22 @@ def test_round_timedelta_to_multiple(delta, multiple, expected):
assert util.round_timedelta_to_multiple(delta, multiple) == expected
+@pytest.mark.parametrize('gpx_file, offset', [
+ ("Teasi_1.gpx.gz", timedelta(hours=2)),
+ ("MyTourbook_1.gpx.gz", timedelta(hours=2)),
+])
+def test_guess_gpx_timezone(gpx_file, offset):
+ asset_dir = Path(__file__).parent.parent / 'assets'
+ test_file = asset_dir / gpx_file
+ with gzip.open(test_file, 'rb') as fobj:
+ parsed_gpx = gpxpy.parse(fobj)
+ timezone = util.guess_gpx_timezone(parsed_gpx)
+ # Here we hope (and assume) that utcoffset is ignored. This is true for
+ # datetime.timezone objects, but may not be for other datetime.tzinfo
+ # instances.
+ assert timezone.utcoffset(None) == offset
+
+
@pytest.mark.parametrize('mps, kph', [(1, 3.6), (10, 36)])
def test_mps_to_kph(mps, kph):
assert util.mps_to_kph(mps) == pytest.approx(kph, 0.1)