Skip to content

Commit

Permalink
Address deprecation warnings in tests (#2252)
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria authored Mar 19, 2024
1 parent f511f5d commit 2c937af
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion examples/flask_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/peewee_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c937af

Please sign in to comment.