|
| 1 | +import sys |
1 | 2 | from datetime import date, datetime, timedelta, timezone |
2 | 3 | from unittest.mock import Mock |
3 | 4 |
|
4 | 5 | import pytest |
5 | | -import pytz |
6 | 6 |
|
7 | 7 | from dirty_equals import IsDate, IsDatetime, IsNow, IsToday |
8 | 8 |
|
9 | | -try: |
| 9 | +if sys.version_info >= (3, 9): |
10 | 10 | from zoneinfo import ZoneInfo |
11 | | -except ImportError: |
12 | | - ZoneInfo = None |
| 11 | +else: |
| 12 | + # This code block is due to a typing issue with backports.zoneinfo package: |
| 13 | + # https://github.com/pganssle/zoneinfo/issues/125 |
| 14 | + from backports.zoneinfo._zoneinfo import ZoneInfo |
13 | 15 |
|
14 | 16 |
|
15 | 17 | @pytest.mark.parametrize( |
|
61 | 63 | id='tz-1-hour', |
62 | 64 | ), |
63 | 65 | pytest.param( |
64 | | - pytz.timezone('Europe/London').localize(datetime(2022, 2, 15, 15, 15)), |
65 | | - IsDatetime( |
66 | | - approx=pytz.timezone('America/New_York').localize(datetime(2022, 2, 15, 10, 15)), enforce_tz=False |
67 | | - ), |
| 66 | + datetime(2022, 2, 15, 15, 15, tzinfo=ZoneInfo('Europe/London')), |
| 67 | + IsDatetime(approx=datetime(2022, 2, 15, 10, 15, tzinfo=ZoneInfo('America/New_York')), enforce_tz=False), |
68 | 68 | True, |
69 | 69 | id='tz-both-tz', |
70 | 70 | ), |
71 | 71 | pytest.param( |
72 | | - pytz.timezone('Europe/London').localize(datetime(2022, 2, 15, 15, 15)), |
73 | | - IsDatetime(approx=pytz.timezone('America/New_York').localize(datetime(2022, 2, 15, 10, 15))), |
| 72 | + datetime(2022, 2, 15, 15, 15, tzinfo=ZoneInfo('Europe/London')), |
| 73 | + IsDatetime(approx=datetime(2022, 2, 15, 10, 15, tzinfo=ZoneInfo('America/New_York'))), |
74 | 74 | False, |
75 | 75 | id='tz-both-tz-different', |
76 | 76 | ), |
|
0 commit comments