Test that fold isn't mutated when no change is necessary. The underlying C API is capable of mutating datetime objects, and may rely on the fact that addition of a datetime object returns a new datetime; this test ensures that the input datetime to fromutc is not mut
(self)
| 450 | inspect.Signature.from_callable(method) |
| 451 | |
| 452 | def test_fold_mutate(self): |
| 453 | """Test that fold isn't mutated when no change is necessary. |
| 454 | |
| 455 | The underlying C API is capable of mutating datetime objects, and |
| 456 | may rely on the fact that addition of a datetime object returns a |
| 457 | new datetime; this test ensures that the input datetime to fromutc |
| 458 | is not mutated. |
| 459 | """ |
| 460 | |
| 461 | def to_subclass(dt): |
| 462 | class SameAddSubclass(type(dt)): |
| 463 | def __add__(self, other): |
| 464 | if other == timedelta(0): |
| 465 | return self |
| 466 | |
| 467 | return super().__add__(other) # pragma: nocover |
| 468 | |
| 469 | return SameAddSubclass( |
| 470 | dt.year, |
| 471 | dt.month, |
| 472 | dt.day, |
| 473 | dt.hour, |
| 474 | dt.minute, |
| 475 | dt.second, |
| 476 | dt.microsecond, |
| 477 | fold=dt.fold, |
| 478 | tzinfo=dt.tzinfo, |
| 479 | ) |
| 480 | |
| 481 | subclass = [False, True] |
| 482 | |
| 483 | key = "Europe/London" |
| 484 | zi = self.zone_from_key(key) |
| 485 | for zt in self.load_transition_examples(key): |
| 486 | if zt.fold and zt.offset_after.utcoffset == ZERO: |
| 487 | example = zt.transition_utc.replace(tzinfo=zi) |
| 488 | break |
| 489 | |
| 490 | for subclass in [False, True]: |
| 491 | if subclass: |
| 492 | dt = to_subclass(example) |
| 493 | else: |
| 494 | dt = example |
| 495 | |
| 496 | with self.subTest(subclass=subclass): |
| 497 | dt_fromutc = zi.fromutc(dt) |
| 498 | |
| 499 | self.assertEqual(dt_fromutc.fold, 1) |
| 500 | self.assertEqual(dt.fold, 0) |
| 501 | |
| 502 | |
| 503 | class ZoneInfoDatetimeSubclassTest(DatetimeSubclassMixin, ZoneInfoTest): |
nothing calls this directly
no test coverage detected