diff --git a/brewtils/models.py b/brewtils/models.py index d0b967fa..a2c313f4 100644 --- a/brewtils/models.py +++ b/brewtils/models.py @@ -3,8 +3,8 @@ import copy from datetime import datetime from enum import Enum +from zoneinfo import ZoneInfo -import pytz # noqa # not in requirements file import six # noqa # not in requirements file from brewtils.errors import ModelError, _deprecate @@ -1273,9 +1273,10 @@ def scheduler_attributes(self): @property def scheduler_kwargs(self): - tz = pytz.timezone(self.timezone) - return {"timezone": tz, "run_date": tz.localize(self.run_date)} + tz = ZoneInfo(self.timezone.upper()) + + return {"timezone": tz, "run_date": self.run_date.replace(tzinfo=tz)} class IntervalTrigger(BaseModel): @@ -1332,14 +1333,16 @@ def scheduler_attributes(self): @property def scheduler_kwargs(self): - tz = pytz.timezone(self.timezone) + tz = ZoneInfo(self.timezone.upper()) kwargs = {key: getattr(self, key) for key in self.scheduler_attributes} kwargs.update( { "timezone": tz, - "start_date": tz.localize(self.start_date) if self.start_date else None, - "end_date": tz.localize(self.end_date) if self.end_date else None, + "start_date": ( + self.start_date.replace(tzinfo=tz) if self.start_date else None + ), + "end_date": self.end_date.replace(tzinfo=tz) if self.end_date else None, } ) @@ -1408,14 +1411,16 @@ def scheduler_attributes(self): @property def scheduler_kwargs(self): - tz = pytz.timezone(self.timezone) + tz = ZoneInfo(self.timezone.upper()) kwargs = {key: getattr(self, key) for key in self.scheduler_attributes} kwargs.update( { "timezone": tz, - "start_date": tz.localize(self.start_date) if self.start_date else None, - "end_date": tz.localize(self.end_date) if self.end_date else None, + "start_date": ( + self.start_date.replace(tzinfo=tz) if self.start_date else None + ), + "end_date": self.end_date.replace(tzinfo=tz) if self.end_date else None, } ) diff --git a/brewtils/test/fixtures.py b/brewtils/test/fixtures.py index 367335e7..4ff15853 100644 --- a/brewtils/test/fixtures.py +++ b/brewtils/test/fixtures.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- import copy -from datetime import datetime +from datetime import datetime, timezone +from zoneinfo import ZoneInfo import pytest -import pytz from brewtils.models import ( AliasUserMap, @@ -62,7 +62,7 @@ def ts_epoch(): @pytest.fixture def ts_dt_utc(ts_epoch): """Jan 1, 2016 UTC as timezone-aware datetime.""" - return datetime.fromtimestamp(ts_epoch / 1000, tz=pytz.utc) + return datetime.fromtimestamp(ts_epoch / 1000, tz=timezone.utc) @pytest.fixture @@ -74,7 +74,7 @@ def ts_epoch_eastern(): @pytest.fixture def ts_dt_eastern(): """Jan 1, 2016 US/Eastern as timezone-aware datetime.""" - return datetime(2016, 1, 1, tzinfo=pytz.timezone("US/Eastern")) + return datetime(2016, 1, 1, tzinfo=ZoneInfo("US/Eastern")) @pytest.fixture @@ -92,7 +92,7 @@ def ts_2_epoch(): @pytest.fixture def ts_2_dt_utc(ts_2_epoch): """Feb 2, 2017 UTC as timezone-aware datetime.""" - return datetime.fromtimestamp(ts_2_epoch / 1000, tz=pytz.utc) + return datetime.fromtimestamp(ts_2_epoch / 1000, tz=timezone.utc) @pytest.fixture diff --git a/setup.py b/setup.py index 20292885..9fb6dc87 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ def find_version(): "marshmallow-polyfield<6", "packaging", "pika<=1.4,>=1.0.1", - "pytz", "requests<3", "simplejson<4", "six<2", diff --git a/test/models_test.py b/test/models_test.py index 8bfa5443..cab6a494 100644 --- a/test/models_test.py +++ b/test/models_test.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- import warnings +from datetime import timezone +from zoneinfo import ZoneInfo import pytest -import pytz +from pytest_lazyfixture import lazy_fixture + from brewtils.errors import ModelError from brewtils.models import ( Choices, @@ -13,17 +16,16 @@ LoggingConfig, Parameter, PatchOperation, - User, Queue, Request, RequestFile, RequestTemplate, Role, - Subscriber, StatusInfo, + Subscriber, Topic, + User, ) -from pytest_lazyfixture import lazy_fixture @pytest.fixture @@ -567,7 +569,7 @@ def test_repr(self, role): class TestDateTrigger(object): def test_scheduler_kwargs(self, bg_date_trigger, ts_dt_utc): assert bg_date_trigger.scheduler_kwargs == { - "timezone": pytz.utc, + "timezone": ZoneInfo("UTC"), "run_date": ts_dt_utc, } @@ -595,7 +597,7 @@ def test_scheduler_kwargs_default(self): "seconds": None, "start_date": None, "end_date": None, - "timezone": pytz.utc, + "timezone": ZoneInfo("UTC"), "jitter": None, "reschedule_on_finish": None, } @@ -605,7 +607,11 @@ def test_scheduler_kwargs( ): expected = interval_trigger_dict expected.update( - {"timezone": pytz.utc, "start_date": ts_dt_utc, "end_date": ts_2_dt_utc} + { + "timezone": ZoneInfo("UTC"), + "start_date": ts_dt_utc, + "end_date": ts_2_dt_utc, + } ) assert bg_interval_trigger.scheduler_kwargs == expected @@ -623,7 +629,7 @@ def test_scheduler_kwargs_default(self): "second": None, "start_date": None, "end_date": None, - "timezone": pytz.utc, + "timezone": ZoneInfo("UTC"), "jitter": None, } @@ -632,7 +638,11 @@ def test_scheduler_kwargs( ): expected = cron_trigger_dict expected.update( - {"timezone": pytz.utc, "start_date": ts_dt_utc, "end_date": ts_2_dt_utc} + { + "timezone": ZoneInfo("UTC"), + "start_date": ts_dt_utc, + "end_date": ts_2_dt_utc, + } ) assert bg_cron_trigger.scheduler_kwargs == expected