File: test_timestamp.py

package info (click to toggle)
python-aristaproto 1.2%2Breally0.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,600 kB
  • sloc: python: 6,521; java: 106; xml: 84; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 753 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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