Skip to content

Commit 683a1d4

Browse files
committed
gh-154892: Move regression test to ZoneInfoTest
1 parent f8bbeac commit 683a1d4

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,37 @@ def test_unambiguous(self):
316316
self.assertEqual(dt.utcoffset(), offset.utcoffset, dt)
317317
self.assertEqual(dt.dst(), offset.dst, dt)
318318

319+
def test_datetime_subclass_negative_components(self):
320+
"""Regression test for gh-154892.
321+
322+
Datetime subclasses may return -1 for time components. The C
323+
accelerator should treat -1 as a valid PyLong_AsLong() result unless
324+
an exception is set, matching the pure-Python implementation.
325+
"""
326+
class MinusOneDateTime(datetime):
327+
@property
328+
def hour(self):
329+
return -1
330+
331+
@property
332+
def minute(self):
333+
return -1
334+
335+
@property
336+
def second(self):
337+
return -1
338+
339+
zi = self.zone_from_key("UTC")
340+
dt = MinusOneDateTime(2024, 1, 1, tzinfo=zi)
341+
342+
self.assertEqual(dt.utcoffset(), ZERO)
343+
self.assertEqual(dt.dst(), ZERO)
344+
self.assertEqual(dt.tzname(), "UTC")
345+
self.assertEqual(
346+
zi.fromutc(dt),
347+
datetime(2024, 1, 1, tzinfo=zi),
348+
)
349+
319350
def test_folds_and_gaps(self):
320351
test_cases = []
321352
for key in self.zones():
@@ -499,37 +530,6 @@ def __add__(self, other):
499530
self.assertEqual(dt_fromutc.fold, 1)
500531
self.assertEqual(dt.fold, 0)
501532

502-
def test_datetime_subclass_negative_components(self):
503-
"""Regression test for gh-154892.
504-
505-
Datetime subclasses may return -1 for time components. The C
506-
accelerator should treat -1 as a valid PyLong_AsLong() result unless
507-
an exception is set, matching the pure-Python implementation.
508-
"""
509-
class MinusOneDateTime(datetime):
510-
@property
511-
def hour(self):
512-
return -1
513-
514-
@property
515-
def minute(self):
516-
return -1
517-
518-
@property
519-
def second(self):
520-
return -1
521-
522-
zi = self.zone_from_key("UTC")
523-
dt = MinusOneDateTime(2024, 1, 1, tzinfo=zi)
524-
525-
self.assertEqual(dt.utcoffset(), ZERO)
526-
self.assertEqual(dt.dst(), ZERO)
527-
self.assertEqual(dt.tzname(), "UTC")
528-
self.assertEqual(
529-
zi.fromutc(dt),
530-
datetime(2024, 1, 1, tzinfo=zi),
531-
)
532-
533533

534534
class ZoneInfoDatetimeSubclassTest(DatetimeSubclassMixin, ZoneInfoTest):
535535
pass

0 commit comments

Comments
 (0)