mirror of
https://github.com/thelsing/knx.git
synced 2026-02-23 13:50:35 +01:00
update pybind11
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from pybind11_tests import chrono as m
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
import env # noqa: F401
|
||||
from pybind11_tests import chrono as m
|
||||
|
||||
|
||||
def test_chrono_system_clock():
|
||||
|
||||
# Get the time from both c++ and datetime
|
||||
date0 = datetime.datetime.today()
|
||||
date1 = m.test_chrono1()
|
||||
@@ -39,9 +40,7 @@ def test_chrono_system_clock_roundtrip():
|
||||
|
||||
# They should be identical (no information lost on roundtrip)
|
||||
diff = abs(date1 - date2)
|
||||
assert diff.days == 0
|
||||
assert diff.seconds == 0
|
||||
assert diff.microseconds == 0
|
||||
assert diff == datetime.timedelta(0)
|
||||
|
||||
|
||||
def test_chrono_system_clock_roundtrip_date():
|
||||
@@ -64,9 +63,7 @@ def test_chrono_system_clock_roundtrip_date():
|
||||
assert diff.microseconds == 0
|
||||
|
||||
# Year, Month & Day should be the same after the round trip
|
||||
assert date1.year == date2.year
|
||||
assert date1.month == date2.month
|
||||
assert date1.day == date2.day
|
||||
assert date1 == date2
|
||||
|
||||
# There should be no time information
|
||||
assert time2.hour == 0
|
||||
@@ -104,7 +101,7 @@ SKIP_TZ_ENV_ON_WIN = pytest.mark.skipif(
|
||||
)
|
||||
def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch):
|
||||
if tz is not None:
|
||||
monkeypatch.setenv("TZ", "/usr/share/zoneinfo/{}".format(tz))
|
||||
monkeypatch.setenv("TZ", f"/usr/share/zoneinfo/{tz}")
|
||||
|
||||
# Roundtrip the time
|
||||
datetime2 = m.test_chrono2(time1)
|
||||
@@ -117,10 +114,7 @@ def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch):
|
||||
assert isinstance(time2, datetime.time)
|
||||
|
||||
# Hour, Minute, Second & Microsecond should be the same after the round trip
|
||||
assert time1.hour == time2.hour
|
||||
assert time1.minute == time2.minute
|
||||
assert time1.second == time2.second
|
||||
assert time1.microsecond == time2.microsecond
|
||||
assert time1 == time2
|
||||
|
||||
# There should be no date information (i.e. date = python base date)
|
||||
assert date2.year == 1970
|
||||
@@ -129,7 +123,6 @@ def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch):
|
||||
|
||||
|
||||
def test_chrono_duration_roundtrip():
|
||||
|
||||
# Get the difference between two times (a timedelta)
|
||||
date1 = datetime.datetime.today()
|
||||
date2 = datetime.datetime.today()
|
||||
@@ -140,35 +133,33 @@ def test_chrono_duration_roundtrip():
|
||||
|
||||
cpp_diff = m.test_chrono3(diff)
|
||||
|
||||
assert cpp_diff.days == diff.days
|
||||
assert cpp_diff.seconds == diff.seconds
|
||||
assert cpp_diff.microseconds == diff.microseconds
|
||||
assert cpp_diff == diff
|
||||
|
||||
# Negative timedelta roundtrip
|
||||
diff = datetime.timedelta(microseconds=-1)
|
||||
cpp_diff = m.test_chrono3(diff)
|
||||
|
||||
assert cpp_diff == diff
|
||||
|
||||
|
||||
def test_chrono_duration_subtraction_equivalence():
|
||||
|
||||
date1 = datetime.datetime.today()
|
||||
date2 = datetime.datetime.today()
|
||||
|
||||
diff = date2 - date1
|
||||
cpp_diff = m.test_chrono4(date2, date1)
|
||||
|
||||
assert cpp_diff.days == diff.days
|
||||
assert cpp_diff.seconds == diff.seconds
|
||||
assert cpp_diff.microseconds == diff.microseconds
|
||||
assert cpp_diff == diff
|
||||
|
||||
|
||||
def test_chrono_duration_subtraction_equivalence_date():
|
||||
|
||||
date1 = datetime.date.today()
|
||||
date2 = datetime.date.today()
|
||||
|
||||
diff = date2 - date1
|
||||
cpp_diff = m.test_chrono4(date2, date1)
|
||||
|
||||
assert cpp_diff.days == diff.days
|
||||
assert cpp_diff.seconds == diff.seconds
|
||||
assert cpp_diff.microseconds == diff.microseconds
|
||||
assert cpp_diff == diff
|
||||
|
||||
|
||||
def test_chrono_steady_clock():
|
||||
@@ -183,9 +174,7 @@ def test_chrono_steady_clock_roundtrip():
|
||||
assert isinstance(time2, datetime.timedelta)
|
||||
|
||||
# They should be identical (no information lost on roundtrip)
|
||||
assert time1.days == time2.days
|
||||
assert time1.seconds == time2.seconds
|
||||
assert time1.microseconds == time2.microseconds
|
||||
assert time1 == time2
|
||||
|
||||
|
||||
def test_floating_point_duration():
|
||||
|
||||
Reference in New Issue
Block a user