Skip to content

Commit

Permalink
Test: Migrated from uing pytz to using zoneinfo/tzdata
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Jun 8, 2024
1 parent f372a2f commit d053749
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 42 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ Released: not yet
* Document the input parameters for the integer cim types (Uint8, etc.)
including the use of 'x' as either a keyword or positional input parameter.

* Test: Migrated from 'pytz' to 'zoneinfo'/'tzdata' for the tests that use it.
(issue #3191)

**Known issues:**

* See `list of open issues`_.
Expand Down
6 changes: 4 additions & 2 deletions minimum-constraints-develop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ yagot==0.5.0

importlib-metadata==4.8.3

pytz==2016.10; python_version <= '3.9'
pytz==2019.1; python_version >= '3.10'
# zoneinfo is part of Python starting with Python 3.9
backports.zoneinfo==0.2.1; python_version == '3.8'
# tzdata is needed by zoneinfo on systems with no timezone database (e.g. Windows)
tzdata==2024.1; sys_platform == 'win32'

# Unit test (indirect dependencies):
pluggy==0.13.0
Expand Down
7 changes: 4 additions & 3 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ yagot>=0.5.0

importlib-metadata>=4.8.3

# pytz before 2019.1 fails on Python 3.10 because it uses collections.Mapping
pytz>=2016.10; python_version <= '3.9'
pytz>=2019.1; python_version >= '3.10'
# zoneinfo is part of Python starting with Python 3.9
backports.zoneinfo>=0.2.1; python_version == '3.8'
# tzdata is needed by zoneinfo on systems with no timezone database (e.g. Windows)
tzdata>=2024.1; sys_platform == 'win32'

# Unit test (indirect dependencies):

Expand Down
47 changes: 10 additions & 37 deletions tests/unittest/pywbem/test_cim_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import re
from datetime import timedelta, datetime

import pytz
try:
import zoneinfo
except ImportError:
from backports import zoneinfo
import pytest

from ..utils.pytest_extensions import simplified_test_function
Expand Down Expand Up @@ -1021,24 +1024,14 @@ def test_MinutesFromUTC_init(testcase, args, kwargs, exp_offset):
None, None, True
),
(
"Test with UTC offset 150 and datetime with tzinfo for EST (ignored)",
"Test with UTC offset 150 and datetime with tzinfo",
dict(
offset=150,
dt=datetime.now(pytz.timezone('US/Eastern')),
dt=datetime.now(tz=zoneinfo.ZoneInfo('US/Eastern')),
exp_utc_offset=150,
),
None, None, True
),
(
"Test with UTC offset -150 and datetime with tzinfo for EDT (ignored)",
dict(
offset=-150,
dt=pytz.timezone('US/Eastern').
localize(datetime.now(), is_dst=True),
exp_utc_offset=-150,
),
None, None, True
),
]


Expand Down Expand Up @@ -1097,20 +1090,10 @@ def test_MinutesFromUTC_utcoffset(testcase, offset, dt, exp_utc_offset):
None, None, True
),
(
"Test with UTC offset 150 and datetime with tzinfo for EST (ignored)",
"Test with UTC offset 150 and datetime with tzinfo",
dict(
offset=150,
dt=datetime.now(pytz.timezone('US/Eastern')),
exp_dst_offset=0,
),
None, None, True
),
(
"Test with UTC offset -150 and datetime with tzinfo for EDT (ignored)",
dict(
offset=-150,
dt=pytz.timezone('US/Eastern').
localize(datetime.now(), is_dst=True),
dt=datetime.now(tz=zoneinfo.ZoneInfo('US/Eastern')),
exp_dst_offset=0,
),
None, None, True
Expand Down Expand Up @@ -1243,24 +1226,14 @@ def test_MinutesFromUTC_dst(testcase, offset, dt, exp_dst_offset):
None, None, True
),
(
"Test with UTC offset 150 and datetime with tzinfo for EST (ignored)",
"Test with UTC offset 150 and datetime with tzinfo",
dict(
offset=150,
dt=datetime.now(pytz.timezone('US/Eastern')),
dt=datetime.now(tz=zoneinfo.ZoneInfo('US/Eastern')),
exp_tzname='02:30',
),
None, None, True
),
(
"Test with UTC offset -150 and datetime with tzinfo for EDT (ignored)",
dict(
offset=-150,
dt=pytz.timezone('US/Eastern').
localize(datetime.now(), is_dst=True),
exp_tzname='-02:30',
),
None, None, True
),
]


Expand Down

0 comments on commit d053749

Please sign in to comment.