@@ -37,57 +37,60 @@ def test_strftime(self):
3737 except ValueError :
3838 self .fail ('conversion specifier: %r failed.' % format )
3939
40- def test_strftime_bounds_checking (self ):
40+ def _bounds_checking (self , func = time . strftime ):
4141 # Make sure that strftime() checks the bounds of the various parts
4242 #of the time tuple (0 is valid for *all* values).
4343
4444 # Check year [1900, max(int)]
45- self .assertRaises (ValueError , time . strftime , '' ,
45+ self .assertRaises (ValueError , func ,
4646 (1899 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
4747 if time .accept2dyear :
48- self .assertRaises (ValueError , time . strftime , '' ,
48+ self .assertRaises (ValueError , func ,
4949 (- 1 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
50- self .assertRaises (ValueError , time . strftime , '' ,
50+ self .assertRaises (ValueError , func ,
5151 (100 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
5252 # Check month [1, 12] + zero support
53- self .assertRaises (ValueError , time . strftime , '' ,
53+ self .assertRaises (ValueError , func ,
5454 (1900 , - 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
55- self .assertRaises (ValueError , time . strftime , '' ,
55+ self .assertRaises (ValueError , func ,
5656 (1900 , 13 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
5757 # Check day of month [1, 31] + zero support
58- self .assertRaises (ValueError , time . strftime , '' ,
58+ self .assertRaises (ValueError , func ,
5959 (1900 , 1 , - 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
60- self .assertRaises (ValueError , time . strftime , '' ,
60+ self .assertRaises (ValueError , func ,
6161 (1900 , 1 , 32 , 0 , 0 , 0 , 0 , 1 , - 1 ))
6262 # Check hour [0, 23]
63- self .assertRaises (ValueError , time . strftime , '' ,
63+ self .assertRaises (ValueError , func ,
6464 (1900 , 1 , 1 , - 1 , 0 , 0 , 0 , 1 , - 1 ))
65- self .assertRaises (ValueError , time . strftime , '' ,
65+ self .assertRaises (ValueError , func ,
6666 (1900 , 1 , 1 , 24 , 0 , 0 , 0 , 1 , - 1 ))
6767 # Check minute [0, 59]
68- self .assertRaises (ValueError , time . strftime , '' ,
68+ self .assertRaises (ValueError , func ,
6969 (1900 , 1 , 1 , 0 , - 1 , 0 , 0 , 1 , - 1 ))
70- self .assertRaises (ValueError , time . strftime , '' ,
70+ self .assertRaises (ValueError , func ,
7171 (1900 , 1 , 1 , 0 , 60 , 0 , 0 , 1 , - 1 ))
7272 # Check second [0, 61]
73- self .assertRaises (ValueError , time . strftime , '' ,
73+ self .assertRaises (ValueError , func ,
7474 (1900 , 1 , 1 , 0 , 0 , - 1 , 0 , 1 , - 1 ))
7575 # C99 only requires allowing for one leap second, but Python's docs say
7676 # allow two leap seconds (0..61)
77- self .assertRaises (ValueError , time . strftime , '' ,
77+ self .assertRaises (ValueError , func ,
7878 (1900 , 1 , 1 , 0 , 0 , 62 , 0 , 1 , - 1 ))
7979 # No check for upper-bound day of week;
8080 # value forced into range by a ``% 7`` calculation.
8181 # Start check at -2 since gettmarg() increments value before taking
8282 # modulo.
83- self .assertRaises (ValueError , time . strftime , '' ,
83+ self .assertRaises (ValueError , func ,
8484 (1900 , 1 , 1 , 0 , 0 , 0 , - 2 , 1 , - 1 ))
8585 # Check day of the year [1, 366] + zero support
86- self .assertRaises (ValueError , time . strftime , '' ,
86+ self .assertRaises (ValueError , func ,
8787 (1900 , 1 , 1 , 0 , 0 , 0 , 0 , - 1 , - 1 ))
88- self .assertRaises (ValueError , time . strftime , '' ,
88+ self .assertRaises (ValueError , func ,
8989 (1900 , 1 , 1 , 0 , 0 , 0 , 0 , 367 , - 1 ))
9090
91+ def test_strftime_bounding_check (self ):
92+ self ._bounds_checking (lambda tup : time .strftime ('' , tup ))
93+
9194 def test_default_values_for_zero (self ):
9295 # Make sure that using all zeros uses the proper default values.
9396 # No test for daylight savings since strftime() does not change output
@@ -120,6 +123,9 @@ def test_asctime(self):
120123 time .asctime (time .gmtime (self .t ))
121124 self .assertRaises (TypeError , time .asctime , 0 )
122125
126+ def test_asctime_bounding_check (self ):
127+ self ._bounds_checking (time .asctime )
128+
123129 def test_tzset (self ):
124130 if not hasattr (time , "tzset" ):
125131 return # Can't test this; don't want the test suite to fail
0 commit comments