From 264612664a24447c929cfd71659d44dd95a8e3a9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 7 Jul 2022 22:40:59 +0200 Subject: add tests for util.guess_gpx_timezone --- tests/unit/test_util.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/unit/test_util.py') 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) -- cgit v1.2.3