@@ -3048,33 +3048,43 @@ def test_formatdate_usegmt(self):
3048
3048
3049
3049
# parsedate and parsedate_tz will become deprecated interfaces someday
3050
3050
def test_parsedate_returns_None_for_invalid_strings (self ):
3051
- self .assertIsNone (utils .parsedate ('' ))
3052
- self .assertIsNone (utils .parsedate_tz ('' ))
3053
- self .assertIsNone (utils .parsedate (' ' ))
3054
- self .assertIsNone (utils .parsedate_tz (' ' ))
3055
- self .assertIsNone (utils .parsedate ('0' ))
3056
- self .assertIsNone (utils .parsedate_tz ('0' ))
3057
- self .assertIsNone (utils .parsedate ('A Complete Waste of Time' ))
3058
- self .assertIsNone (utils .parsedate_tz ('A Complete Waste of Time' ))
3059
- self .assertIsNone (utils .parsedate_tz ('Wed, 3 Apr 2002 12.34.56.78+0800' ))
3051
+ # See also test_parsedate_to_datetime_with_invalid_raises_valueerror
3052
+ # in test_utils.
3053
+ invalid_dates = [
3054
+ '' ,
3055
+ ' ' ,
3056
+ '0' ,
3057
+ 'A Complete Waste of Time' ,
3058
+ 'Wed, 3 Apr 2002 12.34.56.78+0800' ,
3059
+ '17 June , 2022' ,
3060
+ 'Friday, -Nov-82 16:14:55 EST' ,
3061
+ 'Friday, Nov--82 16:14:55 EST' ,
3062
+ 'Friday, 19-Nov- 16:14:55 EST' ,
3063
+ ]
3064
+ for dtstr in invalid_dates :
3065
+ with self .subTest (dtstr = dtstr ):
3066
+ self .assertIsNone (utils .parsedate (dtstr ))
3067
+ self .assertIsNone (utils .parsedate_tz (dtstr ))
3060
3068
# Not a part of the spec but, but this has historically worked:
3061
3069
self .assertIsNone (utils .parsedate (None ))
3062
3070
self .assertIsNone (utils .parsedate_tz (None ))
3063
3071
3064
3072
def test_parsedate_compact (self ):
3073
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58:26 +0800' ),
3074
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3065
3075
# The FWS after the comma is optional
3066
- self .assertEqual (utils .parsedate ('Wed,3 Apr 2002 14:58:26 +0800' ),
3067
- utils .parsedate ('Wed, 3 Apr 2002 14:58:26 +0800' ))
3076
+ self .assertEqual (utils .parsedate_tz ('Wed,3 Apr 2002 14:58:26 +0800' ),
3077
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3078
+ # The comma is optional
3079
+ self .assertEqual (utils .parsedate_tz ('Wed 3 Apr 2002 14:58:26 +0800' ),
3080
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3068
3081
3069
3082
def test_parsedate_no_dayofweek (self ):
3070
- eq = self .assertEqual
3071
- eq (utils .parsedate_tz ('25 Feb 2003 13:47:26 -0800' ),
3072
- (2003 , 2 , 25 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3073
-
3074
- def test_parsedate_compact_no_dayofweek (self ):
3075
3083
eq = self .assertEqual
3076
3084
eq (utils .parsedate_tz ('5 Feb 2003 13:47:26 -0800' ),
3077
3085
(2003 , 2 , 5 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3086
+ eq (utils .parsedate_tz ('February 5, 2003 13:47:26 -0800' ),
3087
+ (2003 , 2 , 5 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3078
3088
3079
3089
def test_parsedate_no_space_before_positive_offset (self ):
3080
3090
self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58:26+0800' ),
@@ -3085,14 +3095,27 @@ def test_parsedate_no_space_before_negative_offset(self):
3085
3095
self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58:26-0800' ),
3086
3096
(2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , - 28800 ))
3087
3097
3088
-
3089
3098
def test_parsedate_accepts_time_with_dots (self ):
3090
3099
eq = self .assertEqual
3091
3100
eq (utils .parsedate_tz ('5 Feb 2003 13.47.26 -0800' ),
3092
3101
(2003 , 2 , 5 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3093
3102
eq (utils .parsedate_tz ('5 Feb 2003 13.47 -0800' ),
3094
3103
(2003 , 2 , 5 , 13 , 47 , 0 , 0 , 1 , - 1 , - 28800 ))
3095
3104
3105
+ def test_parsedate_rfc_850 (self ):
3106
+ self .assertEqual (utils .parsedate_tz ('Friday, 19-Nov-82 16:14:55 EST' ),
3107
+ (1982 , 11 , 19 , 16 , 14 , 55 , 0 , 1 , - 1 , - 18000 ))
3108
+
3109
+ def test_parsedate_no_seconds (self ):
3110
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58 +0800' ),
3111
+ (2002 , 4 , 3 , 14 , 58 , 0 , 0 , 1 , - 1 , 28800 ))
3112
+
3113
+ def test_parsedate_dot_time_delimiter (self ):
3114
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14.58.26 +0800' ),
3115
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3116
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14.58 +0800' ),
3117
+ (2002 , 4 , 3 , 14 , 58 , 0 , 0 , 1 , - 1 , 28800 ))
3118
+
3096
3119
def test_parsedate_acceptable_to_time_functions (self ):
3097
3120
eq = self .assertEqual
3098
3121
timetup = utils .parsedate ('5 Feb 2003 13:47:26 -0800' )
0 commit comments