From 2c937af347b4708a9a777bb20f1c4bf6d29472c9 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Tue, 19 Mar 2024 16:45:38 -0400 Subject: [PATCH] Address deprecation warnings in tests (#2252) --- examples/flask_example.py | 4 +++- examples/peewee_example.py | 2 +- tests/test_deserialization.py | 2 +- tests/test_schema.py | 2 +- tests/test_serialization.py | 8 ++++---- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/flask_example.py b/examples/flask_example.py index 0d8b9e8df..69a1520df 100644 --- a/examples/flask_example.py +++ b/examples/flask_example.py @@ -128,7 +128,9 @@ def new_quote(): db.session.add(author) # Create new quote quote = Quote( - content=data["content"], author=author, posted_at=datetime.datetime.utcnow() + content=data["content"], + author=author, + posted_at=datetime.datetime.now(datetime.UTC), ) db.session.add(quote) db.session.commit() diff --git a/examples/peewee_example.py b/examples/peewee_example.py index eda1647cf..0e99e5dbf 100644 --- a/examples/peewee_example.py +++ b/examples/peewee_example.py @@ -93,7 +93,7 @@ def make_object(self, data, **kwargs): return Todo( content=data["content"], is_done=data["is_done"], - posted_on=dt.datetime.utcnow(), + posted_on=dt.datetime.now(dt.timezone.utc), ) diff --git a/tests/test_deserialization.py b/tests/test_deserialization.py index 069c2f0c2..6c32feadb 100644 --- a/tests/test_deserialization.py +++ b/tests/test_deserialization.py @@ -1288,7 +1288,7 @@ def lowercase_name(self, value): assert MethodDeserializeOnly().load({"name": "ALEC"})["name"] == "alec" def test_datetime_list_field_deserialization(self): - dtimes = dt.datetime.now(), dt.datetime.now(), dt.datetime.utcnow() + dtimes = dt.datetime.now(), dt.datetime.now(), dt.datetime.now(dt.timezone.utc) dstrings = [each.isoformat() for each in dtimes] field = fields.List(fields.DateTime()) result = field.deserialize(dstrings) diff --git a/tests/test_schema.py b/tests/test_schema.py index 64d9144e2..443aa3004 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -85,7 +85,7 @@ class MySchema(Schema): schema = MySchema() input_data = { - "always_valid": dt.datetime.utcnow().isoformat(), + "always_valid": dt.datetime.now(dt.timezone.utc).isoformat(), "always_invalid": 24, } try: diff --git a/tests/test_serialization.py b/tests/test_serialization.py index bf3ccf729..fcb5a5e51 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -827,7 +827,7 @@ def test_timedelta_field(self, user): fields.TimeDelta(fields.TimeDelta.SECONDS, str) def test_datetime_list_field(self): - obj = DateTimeList([dt.datetime.utcnow(), dt.datetime.now()]) + obj = DateTimeList([dt.datetime.now(dt.timezone.utc), dt.datetime.now()]) field = fields.List(fields.DateTime) result = field.serialize("dtimes", obj) assert all(type(each) is str for each in result) @@ -839,7 +839,7 @@ def test_list_field_serialize_none_returns_none(self): def test_list_field_work_with_generator_single_value(self): def custom_generator(): - yield dt.datetime.utcnow() + yield dt.datetime.now(dt.timezone.utc) obj = DateTimeList(custom_generator()) field = fields.List(fields.DateTime) @@ -848,7 +848,7 @@ def custom_generator(): def test_list_field_work_with_generators_multiple_values(self): def custom_generator(): - yield from [dt.datetime.utcnow(), dt.datetime.now()] + yield from [dt.datetime.now(dt.timezone.utc), dt.datetime.now()] obj = DateTimeList(custom_generator()) field = fields.List(fields.DateTime) @@ -910,7 +910,7 @@ class ASchema(Schema): fields.List(ASchema) def test_datetime_integer_tuple_field(self): - obj = DateTimeIntegerTuple((dt.datetime.utcnow(), 42)) + obj = DateTimeIntegerTuple((dt.datetime.now(dt.timezone.utc), 42)) field = fields.Tuple([fields.DateTime, fields.Integer]) result = field.serialize("dtime_int", obj) assert type(result[0]) is str