From 74ff028751f0130197ede03bdd2b53c6faa4981d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 22 Sep 2026 04:14:00 +0000 Subject: [PATCH] test(nmea): add unit tests for print_response in znt.py --- src/nmea/znt.py | 3 ++- tests/test_nmea/test_znt.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/nmea/znt.py b/src/nmea/znt.py index 3993117..6b38002 100755 --- a/src/nmea/znt.py +++ b/src/nmea/znt.py @@ -15,6 +15,7 @@ except ImportError: ntplib = None +import datetime import functools import operator import optparse @@ -75,7 +76,7 @@ def print_response(response): ) print("Poll : %d" % response.poll) print("Mode : %s (%d)" % (ntplib.mode_to_text(response.mode), response.mode)) - print(f"Python time: {time.time():f}, {datetime.datetime.utcnow()!s}") + print(f"Python time: {time.time():f}, {datetime.datetime.now(datetime.UTC)!s}") print("Transmit timestamp : " + time.ctime(response.tx_time)) print("Reference timestamp : " + time.ctime(response.ref_time)) print("Original timestamp : " + time.ctime(response.orig_time)) diff --git a/tests/test_nmea/test_znt.py b/tests/test_nmea/test_znt.py index 074796c..69d89a8 100644 --- a/tests/test_nmea/test_znt.py +++ b/tests/test_nmea/test_znt.py @@ -195,3 +195,43 @@ def test_znt_logger_update_no_write(mock_znt_class): # Force write logger.update(force=True) assert mock_znt_class.called + + +def test_print_response(capsys): + response = MockNTPStats() + znt.print_response(response) + + captured = capsys.readouterr() + stdout = captured.out + + assert "Version number : 4" in stdout + assert "Offset : 0.000080" in stdout + assert "Stratum :" in stdout + assert "Precision : -20" in stdout + assert "Root delay : 0.117325" in stdout + assert "Root dispersion : 0.046249" in stdout + assert "Delay : 0.001000" in stdout + assert "Leap indicator :" in stdout + assert "Poll : 6" in stdout + assert "Mode :" in stdout + assert "Python time:" in stdout + assert "Transmit timestamp :" in stdout + assert "Reference timestamp :" in stdout + assert "Original timestamp :" in stdout + assert "Receive timestamp :" in stdout + assert "Destination timestamp :" in stdout + assert "Reference clock identifier :" in stdout + + +def test_print_response_stratum_1(capsys): + response = MockNTPStats() + response.stratum = 1 + response.ref_id = 1195725632 # 'GPS ' in 32-bit uint + znt.print_response(response) + + captured = capsys.readouterr() + stdout = captured.out + + assert "Stratum :" in stdout + assert "(1)" in stdout + assert "Reference clock identifier :" in stdout