Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
764eb1b
Update error messages to be the same in datetime
donBarbos Nov 27, 2024
2bf419f
Add NEWS.d/next
donBarbos Nov 27, 2024
4363e9e
fixed syntax errors
donBarbos Nov 27, 2024
9da0dfc
Move Py_DECREF after PyErr_Format
donBarbos Nov 29, 2024
179423d
Add more info in message error in _pydatetime impl
donBarbos Nov 29, 2024
f691251
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
d8973cf
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
5eea62f
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
79543cc
Update Modules/_datetimemodule.c for optimisation
donBarbos Nov 29, 2024
d174497
Revert last update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
498c4ba
Update Modules/_datetimemodule.c
donBarbos Nov 29, 2024
216d0fe
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
c409fec
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
3f454f6
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
a2b8f7a
Update Misc/NEWS.d message
donBarbos Nov 29, 2024
209c338
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
0777aa5
Update Misc/NEWS.d/next/Library/2024-11-27-23-29-05.gh-issue-109798.O…
donBarbos Nov 30, 2024
4d31d33
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
f05ebba
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
f840105
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
61c95a5
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
2ab77b3
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
b1e272a
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
7a35bd4
Update Lib/_pydatetime.py
donBarbos Nov 30, 2024
cfd18cb
Add tests
donBarbos Nov 30, 2024
2827514
Update _pydatetime.py
donBarbos Dec 1, 2024
cd3bdc1
Update _pydatetime.py
donBarbos Dec 1, 2024
9915dfe
Change but got to not
donBarbos Dec 1, 2024
1da5a3a
Correct line break
donBarbos Dec 1, 2024
610f067
Update 2024-11-27-23-29-05.gh-issue-109798.OPj1CT.rst
pganssle Feb 12, 2025
410e0ce
Merge branch 'main' into issue-109798
pganssle Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
donBarbos committed Nov 30, 2024
commit cfd18cb4685be2ae1b1a31d5a95beff41fb0b4b8
70 changes: 70 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,23 @@ def test_backdoor_resistance(self):
# blow up because other fields are insane.
self.theclass(base[:2] + bytes([ord_byte]) + base[3:])

def test_valuerror_messages(self):
pattern = re.compile(
r"(year|month|day) must be in \d+\.\.\d+, but got \d+"
)
test_cases = [
(2009, 1, 32), # Day out of range
(2009, 2, 31), # Day out of range
(2009, 13, 1), # Month out of range
(2009, 0, 1), # Month out of range
(10000, 12, 31), # Year out of range
(0, 12, 31), # Year out of range
]
for case in test_cases:
with self.subTest(case):
with self.assertRaisesRegex(ValueError, pattern):
self.theclass(*case)

def test_fromisoformat(self):
# Test that isoformat() is reversible
base_dates = [
Expand Down Expand Up @@ -3212,6 +3229,24 @@ class DateTimeSubclass(self.theclass):
self.assertEqual(res.year, 2013)
self.assertEqual(res.fold, fold)

def test_valuerror_messages(self):
pattern = re.compile(
r"(year|month|day|hour|minute|second) must "
r"be in \d+\.\.\d+, but got \d+"
)
test_cases = [
(2009, 4, 1, 12, 30, 90), # Second out of range
(2009, 4, 1, 12, 90, 45), # Minute out of range
(2009, 4, 1, 25, 30, 45), # Hour out of range
(2009, 4, 32, 24, 0, 0), # Day out of range
(2009, 13, 1, 24, 0, 0), # Month out of range
(9999, 12, 31, 24, 0, 0), # Year out of range
]
for case in test_cases:
with self.subTest(case):
with self.assertRaisesRegex(ValueError, pattern):
self.theclass(*case)

def test_fromisoformat_datetime(self):
# Test that isoformat() is reversible
base_dates = [
Expand Down Expand Up @@ -3505,6 +3540,25 @@ def test_fromisoformat_fails_datetime(self):
with self.assertRaises(ValueError):
self.theclass.fromisoformat(bad_str)

def test_fromisoformat_fails_datetime_valueerror(self):
pattern = re.compile(
r"(year|month|day|hour|minute|second) must "
r"be in \d+\.\.\d+, but got \d+"
)
bad_strs = [
"2009-04-01T12:30:90", # Second out of range
"2009-04-01T12:90:45", # Minute out of range
"2009-04-01T25:30:45", # Hour out of range
"2009-04-32T24:00:00", # Day out of range
"2009-13-01T24:00:00", # Month out of range
"9999-12-31T24:00:00", # Year out of range
]

for bad_str in bad_strs:
with self.subTest(bad_str=bad_str):
with self.assertRaisesRegex(ValueError, pattern):
self.theclass.fromisoformat(bad_str)

def test_fromisoformat_fails_surrogate(self):
# Test that when fromisoformat() fails with a surrogate character as
# the separator, the error message contains the original string
Expand Down Expand Up @@ -4481,6 +4535,22 @@ def utcoffset(self, t):
t2 = t2.replace(tzinfo=Varies())
self.assertTrue(t1 < t2) # t1's offset counter still going up

def test_valuerror_messages(self):
pattern = re.compile(
r"(hour|minute|second|microsecond) must "
r"be in \d+\.\.\d+, but got \d+"
)
test_cases = [
(12, 30, 90, 9999991), # Microsecond out of range
(12, 30, 90, 000000), # Second out of range
(25, 30, 45, 000000), # Hour out of range
(12, 90, 45, 000000), # Minute out of range
]
for case in test_cases:
with self.subTest(case):
with self.assertRaisesRegex(ValueError, pattern):
self.theclass(*case)

def test_fromisoformat(self):
time_examples = [
(0, 0, 0, 0),
Expand Down
Loading