MCPcopy Index your code
hub / github.com/python/cpython / test_fromisoformat_fails_datetime

Method test_fromisoformat_fails_datetime

Lib/test/datetimetester.py:3706–3755  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3704 self.assertEqual(actual, expected)
3705
3706 def test_fromisoformat_fails_datetime(self):
3707 # Test that fromisoformat() fails on invalid values
3708 bad_strs = [
3709 '', # Empty string
3710 '\ud800', # bpo-34454: Surrogate code point
3711 '2009.04-19T03', # Wrong first separator
3712 '2009-04.19T03', # Wrong second separator
3713 '2009-04-19T0a', # Invalid hours
3714 '2009-04-19T03:1a:45', # Invalid minutes
3715 '2009-04-19T03:15:4a', # Invalid seconds
3716 '2009-04-19T03;15:45', # Bad first time separator
3717 '2009-04-19T03:15;45', # Bad second time separator
3718 '2009-04-19T03:15:4500:00', # Bad time zone separator
3719 '2009-04-19T03:15:45.123456+24:30', # Invalid time zone offset
3720 '2009-04-19T03:15:45.123456-24:30', # Invalid negative offset
3721 '2009-04-10ᛇᛇᛇᛇᛇ12:15', # Unicode chars
3722 '2009-04\ud80010T12:15', # Surrogate char in date
3723 '2009-04-10T12\ud80015', # Surrogate char in time
3724 '2009-04-19T1', # Incomplete hours
3725 '2009-04-19T12:3', # Incomplete minutes
3726 '2009-04-19T12:30:4', # Incomplete seconds
3727 '2009-04-19T12:', # Ends with time separator
3728 '2009-04-19T12:30:', # Ends with time separator
3729 '2009-04-19T12:30:45.', # Ends with time separator
3730 '2009-04-19T12:30:45.123456+', # Ends with timezone separator
3731 '2009-04-19T12:30:45.123456-', # Ends with timezone separator
3732 '2009-04-19T12:30:45.123456-05:00a', # Extra text
3733 '2009-04-19T12:30:45.123-05:00a', # Extra text
3734 '2009-04-19T12:30:45-05:00a', # Extra text
3735 '2009-04-19T24:00:00.000001', # Has non-zero microseconds on 24:00
3736 '2009-04-19T24:00:01.000000', # Has non-zero seconds on 24:00
3737 '2009-04-19T24:01:00.000000', # Has non-zero minutes on 24:00
3738 '2009-04-32T24:00:00.000000', # Day is invalid before wrapping due to 24:00
3739 '2009-13-01T24:00:00.000000', # Month is invalid before wrapping due to 24:00
3740 '9999-12-31T24:00:00.000000', # Year is invalid after wrapping due to 24:00
3741 '2009-04-19T12:30Z12:00', # Extra time zone info after Z
3742 '2009-04-19T12:30:45:334034', # Invalid microsecond separator
3743 '2009-04-19T12:30:45.400 +02:30', # Space between ms and timezone (gh-130959)
3744 '2009-04-19T12:30:45.400 ', # Trailing space (gh-130959)
3745 '2009-04-19T12:30:45. 400', # Space before fraction (gh-130959)
3746 '2009-04-19T12:30:45+00:90:00', # Time zone field out from range
3747 '2009-04-19T12:30:45+00:00:90', # Time zone field out from range
3748 '2009-04-19T12:30:45-00:90:00', # Time zone field out from range
3749 '2009-04-19T12:30:45-00:00:90', # Time zone field out from range
3750 ]
3751
3752 for bad_str in bad_strs:
3753 with self.subTest(bad_str=bad_str):
3754 with self.assertRaises(ValueError):
3755 self.theclass.fromisoformat(bad_str)
3756
3757 def test_fromisoformat_fails_datetime_valueerror(self):
3758 pattern = re.compile(

Callers

nothing calls this directly

Calls 3

subTestMethod · 0.45
assertRaisesMethod · 0.45
fromisoformatMethod · 0.45

Tested by

no test coverage detected