From 14b40ec77a4bf8605789cc3aff0eb87625510a41 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 29 Jul 2024 11:40:12 +0200 Subject: Adding upstream version 1.2+20240521. Signed-off-by: Daniel Baumann --- tests/test_timestamp.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/test_timestamp.py (limited to 'tests/test_timestamp.py') diff --git a/tests/test_timestamp.py b/tests/test_timestamp.py new file mode 100644 index 0000000..dd51420 --- /dev/null +++ b/tests/test_timestamp.py @@ -0,0 +1,27 @@ +from datetime import ( + datetime, + timezone, +) + +import pytest + +from aristaproto import _Timestamp + + +@pytest.mark.parametrize( + "dt", + [ + datetime(2023, 10, 11, 9, 41, 12, tzinfo=timezone.utc), + datetime.now(timezone.utc), + # potential issue with floating point precision: + datetime(2242, 12, 31, 23, 0, 0, 1, tzinfo=timezone.utc), + # potential issue with negative timestamps: + datetime(1969, 12, 31, 23, 0, 0, 1, tzinfo=timezone.utc), + ], +) +def test_timestamp_to_datetime_and_back(dt: datetime): + """ + Make sure converting a datetime to a protobuf timestamp message + and then back again ends up with the same datetime. + """ + assert _Timestamp.from_datetime(dt).to_datetime() == dt -- cgit v1.2.3