From 0b6a6b9453676fad654e747cdd90cdbfbaf9978b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 17 Sep 2026 23:24:02 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=AA=20Add=20unit=20tests=20for=20s?= =?UTF-8?q?rc/nmea/zda.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_nmea/test_zda.py | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/test_nmea/test_zda.py diff --git a/tests/test_nmea/test_zda.py b/tests/test_nmea/test_zda.py new file mode 100644 index 0000000..6e9138d --- /dev/null +++ b/tests/test_nmea/test_zda.py @@ -0,0 +1,88 @@ +import pytest +import calendar +from nmea.zda import zdaDecode, zdaEpochSeconds, ggaDecode, zdaDict2TIMESTAMP + +def test_zda_decode_valid(): + # Example from docstring + sentence = '$ZQZDA,110003.00,27,03,2006,-5,00*47' + result = zdaDecode(sentence) + expected = { + 'timekeeper': 'ZQ', + 'localzonehour': -5, + 'localzonemin': 0, + 'hour': 11, + 'min': 0, + 'hsec': 0, + 'sec': 3, + 'mon': 3, + 'year': 2006, + 'day': 27, + 'decimalsec': 3.0 + } + assert result == expected + +def test_zda_decode_invalid_length(): + with pytest.raises(AssertionError): + zdaDecode('$ZQZDA,110') + +def test_zda_decode_invalid_start(): + with pytest.raises(AssertionError): + zdaDecode('?ZQZDA,110003.00,27,03,2006,-5,00*47') + +def test_zda_decode_invalid_type(): + with pytest.raises(AssertionError): + zdaDecode('$ZQRMC,110003.00,27,03,2006,-5,00*47') + +def test_zda_epoch_seconds(): + sentence = '$ZQZDA,110003.00,27,03,2006,-5,00*47' + result = zdaEpochSeconds(sentence) + # Expected: calendar.timegm((2006, 3, 27, 11, 0, 3.0)) -> 1143457203 + expected = calendar.timegm((2006, 3, 27, 11, 0, 3.0)) + assert result == expected + +def test_gga_decode_valid(): + # Example from docstring + sentence = '$GPGGA,152009.00,3652.48059177,N,07620.02018248,W,1,11,0.8,3.669,M,-34.579,M,,*57' + result = ggaDecode(sentence) + assert result['hour'] == '15' + assert result['min'] == '20' + assert result['sec'] == '09' + assert result['hsec'] == '00' + assert result['lat'] > 36.0 + assert result['lon'] < -76.0 + assert result['qual'] == 1 + assert result['sats'] == 11 + assert result['horz_dilution'] == 0.8 + assert result['alt'] == 3.669 + assert result['alt_units'] == 'M' + assert result['geoidal_sep'] == -34.579 + assert result['geoidal_sep_units'] == 'M' + assert result['age'] is None + +def test_gga_decode_south_east(): + # Custom sentence to test S/E lat/lon and age + sentence = '$GPGGA,152009.00,3652.48059177,S,07620.02018248,E,1,11,0.8,3.669,M,-34.579,M,1.5,*57' + result = ggaDecode(sentence) + assert result['lat'] < -36.0 + assert result['lon'] > 76.0 + assert result['age'] == 1.5 + +def test_gga_decode_validate_true(): + # Validate=True requires len >= 71 and <= 78 + sentence = '$GPGGA,152009.00,3652.4800,N,07620.0200,W,1,11,0.8,3.669,M,-34.50,M,,*57' + assert 71 <= len(sentence) <= 78 + result = ggaDecode(sentence, validate=True) + assert result['qual'] == 1 + +def test_gga_decode_validate_length_fail(): + sentence = '$GPGGA,152009.00,3652.48059177,N,07620.02018248,W,1,11,0.8,3.669,M,-34.579,M,,*57' + with pytest.raises(AssertionError): + ggaDecode(sentence, validate=True) + +def test_zda_dict2timestamp(): + zda_dict = { + 'hour': 11, 'min': 0, 'hsec': 0, 'sec': 3, + 'mon': 3, 'year': 2006, 'day': 27 + } + result = zdaDict2TIMESTAMP(zda_dict) + assert result == '2006-03-27 11:00:03' From fb6d317670a0137eeb071289eedbe6be16bc36c0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 17 Sep 2026 23:27:08 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=AA=20Fix=20pre-commit=20ruff=20ch?= =?UTF-8?q?eck=20and=20format=20for=20test=5Fzda.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_nmea/test_zda.py | 105 +++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 43 deletions(-) diff --git a/tests/test_nmea/test_zda.py b/tests/test_nmea/test_zda.py index 6e9138d..f255ef7 100644 --- a/tests/test_nmea/test_zda.py +++ b/tests/test_nmea/test_zda.py @@ -1,88 +1,107 @@ -import pytest import calendar -from nmea.zda import zdaDecode, zdaEpochSeconds, ggaDecode, zdaDict2TIMESTAMP + +import pytest + +from nmea.zda import ggaDecode, zdaDecode, zdaDict2TIMESTAMP, zdaEpochSeconds + def test_zda_decode_valid(): # Example from docstring - sentence = '$ZQZDA,110003.00,27,03,2006,-5,00*47' + sentence = "$ZQZDA,110003.00,27,03,2006,-5,00*47" result = zdaDecode(sentence) expected = { - 'timekeeper': 'ZQ', - 'localzonehour': -5, - 'localzonemin': 0, - 'hour': 11, - 'min': 0, - 'hsec': 0, - 'sec': 3, - 'mon': 3, - 'year': 2006, - 'day': 27, - 'decimalsec': 3.0 + "timekeeper": "ZQ", + "localzonehour": -5, + "localzonemin": 0, + "hour": 11, + "min": 0, + "hsec": 0, + "sec": 3, + "mon": 3, + "year": 2006, + "day": 27, + "decimalsec": 3.0, } assert result == expected + def test_zda_decode_invalid_length(): with pytest.raises(AssertionError): - zdaDecode('$ZQZDA,110') + zdaDecode("$ZQZDA,110") + def test_zda_decode_invalid_start(): with pytest.raises(AssertionError): - zdaDecode('?ZQZDA,110003.00,27,03,2006,-5,00*47') + zdaDecode("?ZQZDA,110003.00,27,03,2006,-5,00*47") + def test_zda_decode_invalid_type(): with pytest.raises(AssertionError): - zdaDecode('$ZQRMC,110003.00,27,03,2006,-5,00*47') + zdaDecode("$ZQRMC,110003.00,27,03,2006,-5,00*47") + def test_zda_epoch_seconds(): - sentence = '$ZQZDA,110003.00,27,03,2006,-5,00*47' + sentence = "$ZQZDA,110003.00,27,03,2006,-5,00*47" result = zdaEpochSeconds(sentence) # Expected: calendar.timegm((2006, 3, 27, 11, 0, 3.0)) -> 1143457203 expected = calendar.timegm((2006, 3, 27, 11, 0, 3.0)) assert result == expected + def test_gga_decode_valid(): # Example from docstring - sentence = '$GPGGA,152009.00,3652.48059177,N,07620.02018248,W,1,11,0.8,3.669,M,-34.579,M,,*57' + sentence = "$GPGGA,152009.00,3652.48059177,N,07620.02018248,W,1,11,0.8,3.669,M,-34.579,M,,*57" result = ggaDecode(sentence) - assert result['hour'] == '15' - assert result['min'] == '20' - assert result['sec'] == '09' - assert result['hsec'] == '00' - assert result['lat'] > 36.0 - assert result['lon'] < -76.0 - assert result['qual'] == 1 - assert result['sats'] == 11 - assert result['horz_dilution'] == 0.8 - assert result['alt'] == 3.669 - assert result['alt_units'] == 'M' - assert result['geoidal_sep'] == -34.579 - assert result['geoidal_sep_units'] == 'M' - assert result['age'] is None + assert result["hour"] == "15" + assert result["min"] == "20" + assert result["sec"] == "09" + assert result["hsec"] == "00" + assert result["lat"] > 36.0 + assert result["lon"] < -76.0 + assert result["qual"] == 1 + assert result["sats"] == 11 + assert result["horz_dilution"] == 0.8 + assert result["alt"] == 3.669 + assert result["alt_units"] == "M" + assert result["geoidal_sep"] == -34.579 + assert result["geoidal_sep_units"] == "M" + assert result["age"] is None + def test_gga_decode_south_east(): # Custom sentence to test S/E lat/lon and age - sentence = '$GPGGA,152009.00,3652.48059177,S,07620.02018248,E,1,11,0.8,3.669,M,-34.579,M,1.5,*57' + sentence = "$GPGGA,152009.00,3652.48059177,S,07620.02018248,E,1,11,0.8,3.669,M,-34.579,M,1.5,*57" result = ggaDecode(sentence) - assert result['lat'] < -36.0 - assert result['lon'] > 76.0 - assert result['age'] == 1.5 + assert result["lat"] < -36.0 + assert result["lon"] > 76.0 + assert result["age"] == 1.5 + def test_gga_decode_validate_true(): # Validate=True requires len >= 71 and <= 78 - sentence = '$GPGGA,152009.00,3652.4800,N,07620.0200,W,1,11,0.8,3.669,M,-34.50,M,,*57' + sentence = ( + "$GPGGA,152009.00,3652.4800,N,07620.0200,W,1,11,0.8,3.669,M,-34.50,M,,*57" + ) assert 71 <= len(sentence) <= 78 result = ggaDecode(sentence, validate=True) - assert result['qual'] == 1 + assert result["qual"] == 1 + def test_gga_decode_validate_length_fail(): - sentence = '$GPGGA,152009.00,3652.48059177,N,07620.02018248,W,1,11,0.8,3.669,M,-34.579,M,,*57' + sentence = "$GPGGA,152009.00,3652.48059177,N,07620.02018248,W,1,11,0.8,3.669,M,-34.579,M,,*57" with pytest.raises(AssertionError): ggaDecode(sentence, validate=True) + def test_zda_dict2timestamp(): zda_dict = { - 'hour': 11, 'min': 0, 'hsec': 0, 'sec': 3, - 'mon': 3, 'year': 2006, 'day': 27 + "hour": 11, + "min": 0, + "hsec": 0, + "sec": 3, + "mon": 3, + "year": 2006, + "day": 27, } result = zdaDict2TIMESTAMP(zda_dict) - assert result == '2006-03-27 11:00:03' + assert result == "2006-03-27 11:00:03"