@@ -37,6 +37,62 @@ def test_strftime(self):
3737 except ValueError :
3838 self .fail ('conversion specifier: %r failed.' % format )
3939
40+ def test_strftime_bounds_checking (self ):
41+ # Make sure that strftime() checks the bounds of the various parts
42+ #of the time tuple.
43+
44+ # Check year
45+ self .assertRaises (ValueError , time .strftime , '' ,
46+ (1899 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
47+ if time .accept2dyear :
48+ self .assertRaises (ValueError , time .strftime , '' ,
49+ (- 1 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
50+ self .assertRaises (ValueError , time .strftime , '' ,
51+ (100 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
52+ # Check month
53+ self .assertRaises (ValueError , time .strftime , '' ,
54+ (1900 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
55+ self .assertRaises (ValueError , time .strftime , '' ,
56+ (1900 , 13 , 1 , 0 , 0 , 0 , 0 , 1 , - 1 ))
57+ # Check day of month
58+ self .assertRaises (ValueError , time .strftime , '' ,
59+ (1900 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , - 1 ))
60+ self .assertRaises (ValueError , time .strftime , '' ,
61+ (1900 , 1 , 32 , 0 , 0 , 0 , 0 , 1 , - 1 ))
62+ # Check hour
63+ self .assertRaises (ValueError , time .strftime , '' ,
64+ (1900 , 1 , 1 , - 1 , 0 , 0 , 0 , 1 , - 1 ))
65+ self .assertRaises (ValueError , time .strftime , '' ,
66+ (1900 , 1 , 1 , 24 , 0 , 0 , 0 , 1 , - 1 ))
67+ # Check minute
68+ self .assertRaises (ValueError , time .strftime , '' ,
69+ (1900 , 1 , 1 , 0 , - 1 , 0 , 0 , 1 , - 1 ))
70+ self .assertRaises (ValueError , time .strftime , '' ,
71+ (1900 , 1 , 1 , 0 , 60 , 0 , 0 , 1 , - 1 ))
72+ # Check second
73+ self .assertRaises (ValueError , time .strftime , '' ,
74+ (1900 , 1 , 1 , 0 , 0 , - 1 , 0 , 1 , - 1 ))
75+ # C99 only requires allowing for one leap second, but Python's docs say
76+ # allow two leap seconds (0..61)
77+ self .assertRaises (ValueError , time .strftime , '' ,
78+ (1900 , 1 , 1 , 0 , 0 , 62 , 0 , 1 , - 1 ))
79+ # No check for upper-bound day of week;
80+ # value forced into range by a ``% 7`` calculation.
81+ # Start check at -2 since gettmarg() increments value before taking
82+ # modulo.
83+ self .assertRaises (ValueError , time .strftime , '' ,
84+ (1900 , 1 , 1 , 0 , 0 , 0 , - 2 , 1 , - 1 ))
85+ # Check day of the year
86+ self .assertRaises (ValueError , time .strftime , '' ,
87+ (1900 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , - 1 ))
88+ self .assertRaises (ValueError , time .strftime , '' ,
89+ (1900 , 1 , 1 , 0 , 0 , 0 , 0 , 367 , - 1 ))
90+ # Check daylight savings flag
91+ self .assertRaises (ValueError , time .strftime , '' ,
92+ (1900 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , - 2 ))
93+ self .assertRaises (ValueError , time .strftime , '' ,
94+ (1900 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , 2 ))
95+
4096 def test_strptime (self ):
4197 tt = time .gmtime (self .t )
4298 for directive in ('a' , 'A' , 'b' , 'B' , 'c' , 'd' , 'H' , 'I' ,
0 commit comments