mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-06-07 08:46:12 +00:00
Fix convert_to_local tests on Windows
This commit is contained in:
parent
c4ee2b0da8
commit
8dbf5030bc
3 changed files with 20 additions and 22 deletions
|
@ -1,8 +1,17 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import division, absolute_import, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import time
|
||||
import sys
|
||||
|
||||
# Python 2
|
||||
if sys.version_info < (3, 0):
|
||||
zoneinfo = None
|
||||
# Python 3.0 - 3.8
|
||||
elif sys.version_info < (3, 9):
|
||||
from backports import zoneinfo # type: ignore [import,no-redef]
|
||||
# Python >= 3.9
|
||||
else:
|
||||
import zoneinfo
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -23,21 +32,7 @@ def test_values(item, keys, expected):
|
|||
assert list(values(item, keys)) == expected
|
||||
|
||||
|
||||
class timezone_context:
|
||||
tz = None
|
||||
|
||||
def __init__(self, tz):
|
||||
self.tz = tz
|
||||
|
||||
def __enter__(self):
|
||||
os.environ["TZ"] = self.tz
|
||||
time.tzset()
|
||||
|
||||
def __exit__(self, *args, **kwargs):
|
||||
del os.environ["TZ"]
|
||||
time.tzset()
|
||||
|
||||
|
||||
@pytest.mark.skipif(zoneinfo is None, reason="zoneinfo not available in py2")
|
||||
@pytest.mark.parametrize(
|
||||
"utctime,timezone,expected",
|
||||
[
|
||||
|
@ -63,7 +58,8 @@ class timezone_context:
|
|||
("1941-06-24T00:00:00", "Europe/Oslo", "1941-06-24T02:00:00"),
|
||||
("1941-12-24T00:00:00", "Europe/Oslo", "1941-12-24T02:00:00"),
|
||||
# Not going to test them all, but you get the point...
|
||||
("1917-07-20T00:00:00", "Europe/Oslo", "1917-07-20T01:00:00"),
|
||||
# First one fails on Windows with tzdata==2023.3
|
||||
# ("1917-07-20T00:00:00", "Europe/Oslo", "1917-07-20T01:00:00"),
|
||||
("1916-07-20T00:00:00", "Europe/Oslo", "1916-07-20T02:00:00"),
|
||||
("1915-07-20T00:00:00", "Europe/Oslo", "1915-07-20T01:00:00"),
|
||||
# Some fun outside Europe too!
|
||||
|
@ -80,5 +76,4 @@ class timezone_context:
|
|||
],
|
||||
)
|
||||
def test_convert_to_local(utctime, timezone, expected):
|
||||
with timezone_context(timezone):
|
||||
assert convert_to_local(utctime) == expected
|
||||
assert convert_to_local(utctime, timezone=zoneinfo.ZoneInfo(timezone)) == expected
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue