@@ -3048,33 +3048,43 @@ def test_formatdate_usegmt(self):
30483048
30493049 # parsedate and parsedate_tz will become deprecated interfaces someday
30503050 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 ))
30603068 # Not a part of the spec but, but this has historically worked:
30613069 self .assertIsNone (utils .parsedate (None ))
30623070 self .assertIsNone (utils .parsedate_tz (None ))
30633071
30643072 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 ))
30653075 # 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 ))
30683081
30693082 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 ):
30753083 eq = self .assertEqual
30763084 eq (utils .parsedate_tz ('5 Feb 2003 13:47:26 -0800' ),
30773085 (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 ))
30783088
30793089 def test_parsedate_no_space_before_positive_offset (self ):
30803090 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):
30853095 self .assertEqual (utils .parsedate_tz ('Wed, 3 Apr 2002 14:58:26-0800' ),
30863096 (2002 , 4 , 3 , 14 , 58 , 26 , 0 , 1 , - 1 , - 28800 ))
30873097
3088-
30893098 def test_parsedate_accepts_time_with_dots (self ):
30903099 eq = self .assertEqual
30913100 eq (utils .parsedate_tz ('5 Feb 2003 13.47.26 -0800' ),
30923101 (2003 , 2 , 5 , 13 , 47 , 26 , 0 , 1 , - 1 , - 28800 ))
30933102 eq (utils .parsedate_tz ('5 Feb 2003 13.47 -0800' ),
30943103 (2003 , 2 , 5 , 13 , 47 , 0 , 0 , 1 , - 1 , - 28800 ))
30953104
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+
30963119 def test_parsedate_acceptable_to_time_functions (self ):
30973120 eq = self .assertEqual
30983121 timetup = utils .parsedate ('5 Feb 2003 13:47:26 -0800' )
0 commit comments