Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6759ba2

Browse filesBrowse files
committed
Fix a few missing DeprecationWarnings in tests
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.
1 parent 60bba43 commit 6759ba2
Copy full SHA for 6759ba2

File tree

Expand file treeCollapse file tree

1 file changed

+13
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-9
lines changed

‎Lib/test/datetimetester.py

Copy file name to clipboardExpand all lines: Lib/test/datetimetester.py
+13-9Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import re
1515
import struct
1616
import unittest
17+
import warnings
1718

1819
from array import array
1920

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

54-
5555
# XXX Copied from test_float.
5656
INF = float("inf")
5757
NAN = float("nan")
@@ -2649,9 +2649,10 @@ def test_utcfromtimestamp_limits(self):
26492649
for test_name, ts in test_cases:
26502650
with self.subTest(test_name, ts=ts):
26512651
with self.assertRaises((ValueError, OverflowError)):
2652-
# converting a Python int to C time_t can raise a
2653-
# OverflowError, especially on 32-bit platforms.
2654-
self.theclass.utcfromtimestamp(ts)
2652+
with self.assertWarns(DeprecationWarning):
2653+
# converting a Python int to C time_t can raise a
2654+
# OverflowError, especially on 32-bit platforms.
2655+
self.theclass.utcfromtimestamp(ts)
26552656

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

26742676
@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
26752677
def test_negative_float_fromtimestamp(self):
@@ -3028,7 +3030,7 @@ def __new__(cls, *args, **kwargs):
30283030
for name, meth_name, kwargs in test_cases:
30293031
with self.subTest(name):
30303032
constr = getattr(DateTimeSubclass, meth_name)
3031-
if constr == "utcnow":
3033+
if meth_name == "utcnow":
30323034
with self.assertWarns(DeprecationWarning):
30333035
dt = constr(**kwargs)
30343036
else:
@@ -4756,8 +4758,10 @@ def test_tzinfo_utcfromtimestamp(self):
47564758
# Try with and without naming the keyword; for whatever reason,
47574759
# utcfromtimestamp() doesn't accept a tzinfo argument.
47584760
off42 = FixedOffset(42, "42")
4759-
self.assertRaises(TypeError, meth, ts, off42)
4760-
self.assertRaises(TypeError, meth, ts, tzinfo=off42)
4761+
with warnings.catch_warnings(category=DeprecationWarning):
4762+
warnings.simplefilter("ignore", category=DeprecationWarning)
4763+
self.assertRaises(TypeError, meth, ts, off42)
4764+
self.assertRaises(TypeError, meth, ts, tzinfo=off42)
47614765

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.