Skip to content

Commit

Permalink
Refs #33173 -- Fixed test_dateparse tests on Python 3.11+.
Browse files Browse the repository at this point in the history
date/datetime/time.fromisoformat() support any valid ISO 8601 format
in Python 3.11+, see python/cpython#80010.
  • Loading branch information
felixxm authored and jribbens committed May 25, 2023
1 parent 59b87c7 commit fb6cd05
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/utils_tests/test_dateparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
parse_time,
)
from django.utils.timezone import get_fixed_timezone
from django.utils.version import PY311


class DateParseTests(unittest.TestCase):
def test_parse_date(self):
# Valid inputs
self.assertEqual(parse_date("2012-04-23"), date(2012, 4, 23))
self.assertEqual(parse_date("2012-4-9"), date(2012, 4, 9))
if PY311:
self.assertEqual(parse_date("20120423"), date(2012, 4, 23))
# Invalid inputs
self.assertIsNone(parse_date("20120423"))
self.assertIsNone(parse_date("2012423"))
with self.assertRaises(ValueError):
parse_date("2012-04-56")

def test_parse_time(self):
# Valid inputs
self.assertEqual(parse_time("09:15:00"), time(9, 15))
if PY311:
self.assertEqual(parse_time("091500"), time(9, 15))
self.assertEqual(parse_time("10:10"), time(10, 10))
self.assertEqual(parse_time("10:20:30.400"), time(10, 20, 30, 400000))
self.assertEqual(parse_time("10:20:30,400"), time(10, 20, 30, 400000))
Expand All @@ -35,7 +40,7 @@ def test_parse_time(self):
self.assertIsNone(parse_time("00:05:23+"))
self.assertIsNone(parse_time("00:05:23+25:00"))
self.assertIsNone(parse_time("4:18:101"))
self.assertIsNone(parse_time("091500"))
self.assertIsNone(parse_time("91500"))
with self.assertRaises(ValueError):
parse_time("09:15:90")

Expand Down

0 comments on commit fb6cd05

Please sign in to comment.