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