@@ -3016,33 +3016,43 @@ def test_formatdate_usegmt(self):
3016
3016
3017
3017
# parsedate and parsedate_tz will become deprecated interfaces someday
3018
3018
def test_parsedate_returns_None_for_invalid_strings (self ):
3019
- self .assertIsNone (utils .parsedate ('' ))
3020
- self .assertIsNone (utils .parsedate_tz ('' ))
3021
- self .assertIsNone (utils .parsedate (' ' ))
3022
- self .assertIsNone (utils .parsedate_tz (' ' ))
3023
- self .assertIsNone (utils .parsedate ('0' ))
3024
- self .assertIsNone (utils .parsedate_tz ('0' ))
3025
- self .assertIsNone (utils .parsedate ('A Complete Waste of Time' ))
3026
- self .assertIsNone (utils .parsedate_tz ('A Complete Waste of Time' ))
3027
- self .assertIsNone (utils .parsedate_tz ('Wed, 3 Apr 2002 12.34.56.78+0800' ))
3019
+ # See also test_parsedate_to_datetime_with_invalid_raises_valueerror
3020
+ # in test_utils.
3021
+ invalid_dates = [
3022
+ '' ,
3023
+ ' ' ,
3024
+ '0' ,
3025
+ 'A Complete Waste of Time' ,
3026
+ 'Wed, 3 Apr 2002 12.34.56.78+0800' ,
3027
+ '17 June , 2022' ,
3028
+ 'Friday, -Nov-82 16:14:55 EST' ,
3029
+ 'Friday, Nov--82 16:14:55 EST' ,
3030
+ 'Friday, 19-Nov- 16:14:55 EST' ,
3031
+ ]
3032
+ for dtstr in invalid_dates :
3033
+ with self .subTest (dtstr = dtstr ):
3034
+ self .assertIsNone (utils .parsedate (dtstr ))
3035
+ self .assertIsNone (utils .parsedate_tz (dtstr ))
3028
3036
# Not a part of the spec but, but this has historically worked:
3029
3037
self .assertIsNone (utils .parsedate (None ))
3030
3038
self .assertIsNone (utils .parsedate_tz (None ))
3031
3039
3032
3040
def test_parsedate_compact (self ):
3041
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58:26 +0800' ),
3042
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3033
3043
# The FWS after the comma is optional
3034
- self .assertEqual (utils .parsedate ('Wed,3 Apr 2002 14:58:26 +0800' ),
3035
- utils .parsedate ('Wed, 3 Apr 2002 14:58:26 +0800' ))
3044
+ self .assertEqual (utils .parsedate_tz ('Wed,3 Apr 2002 14:58:26 +0800' ),
3045
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3046
+ # The comma is optional
3047
+ self .assertEqual (utils .parsedate_tz ('Wed 3 Apr 2002 14:58:26 +0800' ),
3048
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3036
3049
3037
3050
def test_parsedate_no_dayofweek (self ):
3038
- eq = self .assertEqual
3039
- eq (utils .parsedate_tz ('25 Feb 2003 13:47:26 -0800' ),
3040
- (2003 , 2 , 25 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3041
-
3042
- def test_parsedate_compact_no_dayofweek (self ):
3043
3051
eq = self .assertEqual
3044
3052
eq (utils .parsedate_tz ('5 Feb 2003 13:47:26 -0800' ),
3045
3053
(2003 , 2 , 5 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3054
+ eq (utils .parsedate_tz ('February 5, 2003 13:47:26 -0800' ),
3055
+ (2003 , 2 , 5 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3046
3056
3047
3057
def test_parsedate_no_space_before_positive_offset (self ):
3048
3058
self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58:26+0800' ),
@@ -3053,14 +3063,27 @@ def test_parsedate_no_space_before_negative_offset(self):
3053
3063
self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58:26-0800' ),
3054
3064
(2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , - 28800 ))
3055
3065
3056
-
3057
3066
def test_parsedate_accepts_time_with_dots (self ):
3058
3067
eq = self .assertEqual
3059
3068
eq (utils .parsedate_tz ('5 Feb 2003 13.47.26 -0800' ),
3060
3069
(2003 , 2 , 5 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
3061
3070
eq (utils .parsedate_tz ('5 Feb 2003 13.47 -0800' ),
3062
3071
(2003 , 2 , 5 , 13 , 47 , 0 , 0 , 1 , - 1 , - 28800 ))
3063
3072
3073
+ def test_parsedate_rfc_850 (self ):
3074
+ self .assertEqual (utils .parsedate_tz ('Friday, 19-Nov-82 16:14:55 EST' ),
3075
+ (1982 , 11 , 19 , 16 , 14 , 55 , 0 , 1 , - 1 , - 18000 ))
3076
+
3077
+ def test_parsedate_no_seconds (self ):
3078
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58 +0800' ),
3079
+ (2002 , 4 , 3 , 14 , 58 , 0 , 0 , 1 , - 1 , 28800 ))
3080
+
3081
+ def test_parsedate_dot_time_delimiter (self ):
3082
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14.58.26 +0800' ),
3083
+ (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , 28800 ))
3084
+ self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14.58 +0800' ),
3085
+ (2002 , 4 , 3 , 14 , 58 , 0 , 0 , 1 , - 1 , 28800 ))
3086
+
3064
3087
def test_parsedate_acceptable_to_time_functions (self ):
3065
3088
eq = self .assertEqual
3066
3089
timetup = utils .parsedate ('5 Feb 2003 13:47:26 -0800' )
0 commit comments