Skip to content

Commit

Permalink
Fix a few missing DeprecationWarnings in tests
Browse files Browse the repository at this point in the history
In one test, we simply turn off DeprecationWarning rather than asserting
about it, because whether the error condition happens before or after
the warning seems to differ between the Python and C versions.
  • Loading branch information
pganssle committed Apr 29, 2023
1 parent 60bba43 commit 6759ba2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import re
import struct
import unittest
import warnings

from array import array

Expand Down Expand Up @@ -51,7 +52,6 @@
# mixed-type comparisons.
OTHERSTUFF = (10, 34.5, "abc", {}, [], ())


# XXX Copied from test_float.
INF = float("inf")
NAN = float("nan")
Expand Down Expand Up @@ -2649,9 +2649,10 @@ def test_utcfromtimestamp_limits(self):
for test_name, ts in test_cases:
with self.subTest(test_name, ts=ts):
with self.assertRaises((ValueError, OverflowError)):
# converting a Python int to C time_t can raise a
# OverflowError, especially on 32-bit platforms.
self.theclass.utcfromtimestamp(ts)
with self.assertWarns(DeprecationWarning):
# converting a Python int to C time_t can raise a
# OverflowError, especially on 32-bit platforms.
self.theclass.utcfromtimestamp(ts)

def test_insane_fromtimestamp(self):
# It's possible that some platform maps time_t to double,
Expand All @@ -2668,8 +2669,9 @@ def test_insane_utcfromtimestamp(self):
# exempt such platforms (provided they return reasonable
# results!).
for insane in -1e200, 1e200:
self.assertRaises(OverflowError, self.theclass.utcfromtimestamp,
insane)
with self.assertWarns(DeprecationWarning):
self.assertRaises(OverflowError, self.theclass.utcfromtimestamp,
insane)

@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
def test_negative_float_fromtimestamp(self):
Expand Down Expand Up @@ -3028,7 +3030,7 @@ def __new__(cls, *args, **kwargs):
for name, meth_name, kwargs in test_cases:
with self.subTest(name):
constr = getattr(DateTimeSubclass, meth_name)
if constr == "utcnow":
if meth_name == "utcnow":
with self.assertWarns(DeprecationWarning):
dt = constr(**kwargs)
else:
Expand Down Expand Up @@ -4756,8 +4758,10 @@ def test_tzinfo_utcfromtimestamp(self):
# Try with and without naming the keyword; for whatever reason,
# utcfromtimestamp() doesn't accept a tzinfo argument.
off42 = FixedOffset(42, "42")
self.assertRaises(TypeError, meth, ts, off42)
self.assertRaises(TypeError, meth, ts, tzinfo=off42)
with warnings.catch_warnings(category=DeprecationWarning):
warnings.simplefilter("ignore", category=DeprecationWarning)
self.assertRaises(TypeError, meth, ts, off42)
self.assertRaises(TypeError, meth, ts, tzinfo=off42)

def test_tzinfo_timetuple(self):
# TestDateTime tested most of this. datetime adds a twist to the
Expand Down

0 comments on commit 6759ba2

Please sign in to comment.