Fix bug roundtripping datetime.time objects after midnight in eastern hemisphere timezones (#2417) (#2438)

* Fix bug roundtripping datetime.time objects after midnight in eastern hemisphere timezones (#2417)

* tests: check more timezones

* Fix review remarks: remove useless comment and skip setting TZ environment variable on Windows
This commit is contained in:
Yannick Jadoul
2020-08-28 15:21:43 +02:00
committed by GitHub
parent 1abc4a9de5
commit 6a192781fc
3 changed files with 40 additions and 7 deletions

View File

@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from pybind11_tests import chrono as m
import datetime
import pytest
import env # noqa: F401
def test_chrono_system_clock():
@@ -70,8 +73,30 @@ def test_chrono_system_clock_roundtrip_date():
assert time2.microsecond == 0
def test_chrono_system_clock_roundtrip_time():
time1 = datetime.datetime.today().time()
SKIP_TZ_ENV_ON_WIN = pytest.mark.skipif(
"env.WIN", reason="TZ environment variable only supported on POSIX"
)
@pytest.mark.parametrize("time1", [
datetime.datetime.today().time(),
datetime.time(0, 0, 0),
datetime.time(0, 0, 0, 1),
datetime.time(0, 28, 45, 109827),
datetime.time(0, 59, 59, 999999),
datetime.time(1, 0, 0),
datetime.time(5, 59, 59, 0),
datetime.time(5, 59, 59, 1),
])
@pytest.mark.parametrize("tz", [
None,
pytest.param("Europe/Brussels", marks=SKIP_TZ_ENV_ON_WIN),
pytest.param("Asia/Pyongyang", marks=SKIP_TZ_ENV_ON_WIN),
pytest.param("America/New_York", marks=SKIP_TZ_ENV_ON_WIN),
])
def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch):
if tz is not None:
monkeypatch.setenv("TZ", "/usr/share/zoneinfo/{}".format(tz))
# Roundtrip the time
datetime2 = m.test_chrono2(time1)