1515import struct
1616import sys
1717import unittest
18+ import warnings
1819
1920from array import array
2021
5253# mixed-type comparisons.
5354OTHERSTUFF = (10 , 34.5 , "abc" , {}, [], ())
5455
55-
5656# XXX Copied from test_float.
5757INF = float ("inf" )
5858NAN = 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