15
15
import struct
16
16
import sys
17
17
import unittest
18
+ import warnings
18
19
19
20
from array import array
20
21
52
53
# mixed-type comparisons.
53
54
OTHERSTUFF = (10 , 34.5 , "abc" , {}, [], ())
54
55
55
-
56
56
# XXX Copied from test_float.
57
57
INF = float ("inf" )
58
58
NAN = float ("nan" )
@@ -2645,9 +2645,10 @@ def test_utcfromtimestamp_limits(self):
2645
2645
for test_name , ts in test_cases :
2646
2646
with self .subTest (test_name , ts = ts ):
2647
2647
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 )
2651
2652
2652
2653
def test_insane_fromtimestamp (self ):
2653
2654
# It's possible that some platform maps time_t to double,
@@ -2664,8 +2665,9 @@ def test_insane_utcfromtimestamp(self):
2664
2665
# exempt such platforms (provided they return reasonable
2665
2666
# results!).
2666
2667
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 )
2669
2671
2670
2672
@unittest .skipIf (sys .platform == "win32" , "Windows doesn't accept negative timestamps" )
2671
2673
def test_negative_float_fromtimestamp (self ):
@@ -3024,7 +3026,7 @@ def __new__(cls, *args, **kwargs):
3024
3026
for name , meth_name , kwargs in test_cases :
3025
3027
with self .subTest (name ):
3026
3028
constr = getattr (DateTimeSubclass , meth_name )
3027
- if constr == "utcnow" :
3029
+ if meth_name == "utcnow" :
3028
3030
with self .assertWarns (DeprecationWarning ):
3029
3031
dt = constr (** kwargs )
3030
3032
else :
@@ -4752,8 +4754,10 @@ def test_tzinfo_utcfromtimestamp(self):
4752
4754
# Try with and without naming the keyword; for whatever reason,
4753
4755
# utcfromtimestamp() doesn't accept a tzinfo argument.
4754
4756
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 )
4757
4761
4758
4762
def test_tzinfo_timetuple (self ):
4759
4763
# TestDateTime tested most of this. datetime adds a twist to the
0 commit comments