@@ -66,3 +66,39 @@ def test_format_rfc3339(self):
6666 format_rfc3339 (datetime (2017 , 7 , 25 , 4 , 44 , 21 , 0 ,
6767 TimezoneInfo (- 2 , 30 ))),
6868 "2017-07-25T07:14:21Z" )
69+
70+ def test_parse_rfc3339_invalid_formats (self ):
71+ """Test that invalid RFC3339 formats raise ValueError"""
72+ invalid_inputs = [
73+ "2025-13-02T13:37:00Z" , # Invalid month
74+ "2025-12-32T13:37:00Z" , # Invalid day
75+ "2025-12-02T25:00:00Z" , # Invalid hour
76+ "2025-12-02T13:60:00Z" , # Invalid minute
77+ "2025-12-02T13:37:60Z" , # Invalid second
78+ "not-a-valid-date" , # Completely invalid
79+ "" , # Empty string
80+ "2025-12-02Z13:37:00" , # Timezone before time
81+ ]
82+
83+ for invalid_input in invalid_inputs :
84+ with self .assertRaises (ValueError ):
85+ parse_rfc3339 (invalid_input )
86+
87+
88+
89+ def test_parse_rfc3339_with_whitespace (self ):
90+ """Test that leading/trailing whitespace is handled"""
91+ actual = parse_rfc3339 (" 2017-07-25T04:44:21Z " )
92+ expected = datetime (2017 , 7 , 25 , 4 , 44 , 21 , 0 , UTC )
93+ self .assertEqual (expected , actual )
94+
95+ def test_parse_rfc3339_error_message_clarity (self ):
96+ """Test that error messages are clear and helpful"""
97+ try :
98+ parse_rfc3339 ("invalid-date-format" )
99+ except ValueError as e :
100+ error_msg = str (e )
101+ # Verify error message contains helpful information
102+ self .assertIn ("Invalid RFC3339" , error_msg )
103+ self .assertIn ("YYYY-MM-DD" , error_msg )
104+ self .assertIn ("expected" , error_msg )
0 commit comments