diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-29 09:40:12 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-29 09:40:12 +0000 |
commit | 14b40ec77a4bf8605789cc3aff0eb87625510a41 (patch) | |
tree | 4064d27144d6deaabfcd96df01bd996baa8b51a0 /tests/test_timestamp.py | |
parent | Initial commit. (diff) | |
download | python-aristaproto-14b40ec77a4bf8605789cc3aff0eb87625510a41.tar.xz python-aristaproto-14b40ec77a4bf8605789cc3aff0eb87625510a41.zip |
Adding upstream version 1.2+20240521.upstream/1.2+20240521upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_timestamp.py')
-rw-r--r-- | tests/test_timestamp.py | 27 |
1 files changed, 27 insertions, 0 deletions
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 |