1414import re
1515import struct
1616import unittest
17+ import warnings
1718
1819from array import array
1920
5152# mixed-type comparisons.
5253OTHERSTUFF = (10 , 34.5 , "abc" , {}, [], ())
5354
54-
5555# XXX Copied from test_float.
5656INF = float ("inf" )
5757NAN = 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