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 82ac549

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 6a94631 commit 82ac549
Copy full SHA for 82ac549

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
@@ -15,6 +15,7 @@
1515
import struct
1616
import sys
1717
import unittest
18+
import warnings
1819

1920
from array import array
2021

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

55-
5656
# XXX Copied from test_float.
5757
INF = float("inf")
5858
NAN = float("nan")
@@ -2645,9 +2645,10 @@ def test_utcfromtimestamp_limits(self):
26452645
for test_name, ts in test_cases:
26462646
with self.subTest(test_name, ts=ts):
26472647
with self.assertRaises((ValueError, OverflowError)):
2648-
# converting a Python int to C time_t can raise a
2649-
# OverflowError, especially on 32-bit platforms.
2650-
self.theclass.utcfromtimestamp(ts)
2648+
with self.assertWarns(DeprecationWarning):
2649+
# converting a Python int to C time_t can raise a
2650+
# OverflowError, especially on 32-bit platforms.
2651+
self.theclass.utcfromtimestamp(ts)
26512652

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

26702672
@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
26712673
def test_negative_float_fromtimestamp(self):
@@ -3024,7 +3026,7 @@ def __new__(cls, *args, **kwargs):
30243026
for name, meth_name, kwargs in test_cases:
30253027
with self.subTest(name):
30263028
constr = getattr(DateTimeSubclass, meth_name)
3027-
if constr == "utcnow":
3029+
if meth_name == "utcnow":
30283030
with self.assertWarns(DeprecationWarning):
30293031
dt = constr(**kwargs)
30303032
else:
@@ -4752,8 +4754,10 @@ def test_tzinfo_utcfromtimestamp(self):
47524754
# Try with and without naming the keyword; for whatever reason,
47534755
# utcfromtimestamp() doesn't accept a tzinfo argument.
47544756
off42 = FixedOffset(42, "42")
4755-
self.assertRaises(TypeError, meth, ts, off42)
4756-
self.assertRaises(TypeError, meth, ts, tzinfo=off42)
4757+
with warnings.catch_warnings(category=DeprecationWarning):
4758+
warnings.simplefilter("ignore", category=DeprecationWarning)
4759+
self.assertRaises(TypeError, meth, ts, off42)
4760+
self.assertRaises(TypeError, meth, ts, tzinfo=off42)
47574761

47584762
def test_tzinfo_timetuple(self):
47594763
# 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.