MCPcopy Create free account
hub / github.com/dateutil/dateutil / test_pickle_subclass_attributes

Function test_pickle_subclass_attributes

tests/test_tzfile.py:2600–2623  ·  view source on GitHub ↗

Pickling preserves attributes added by subclasses.

(protocol)

Source from the content-addressed store, hash-verified

2598
2599@pytest.mark.parametrize("protocol", range(0, pickle.HIGHEST_PROTOCOL + 1))
2600def test_pickle_subclass_attributes(protocol):
2601 """Pickling preserves attributes added by subclasses."""
2602 STD = ZoneOffset("STD", -5 * ONE_H)
2603 DST = ZoneOffset("DST", -4 * ONE_H, ONE_H)
2604 transitions = [
2605 ZoneTransition(datetime(2020, 3, 8, 2), STD, DST),
2606 ZoneTransition(datetime(2020, 11, 1, 2), DST, STD),
2607 ]
2608 zone = _DescribedTzfile(
2609 construct_zone(transitions, "STD5DST,M3.2.0,M11.1.0"),
2610 "Somewhere in the eastern US",
2611 key="Fictional/Eastern",
2612 )
2613
2614 unpickled = pickle.loads(pickle.dumps(zone, protocol=protocol))
2615
2616 assert type(unpickled) is _DescribedTzfile
2617 assert unpickled == zone
2618 assert unpickled.key == "Fictional/Eastern"
2619 assert unpickled.description == "Somewhere in the eastern US"
2620 assert (
2621 datetime(2020, 7, 1, tzinfo=unpickled).utcoffset()
2622 == datetime(2020, 7, 1, tzinfo=zone).utcoffset()
2623 )
2624
2625
2626@pytest.mark.parametrize("key", ["America/New_York", "UTC", None])

Callers

nothing calls this directly

Calls 5

ZoneOffsetClass · 0.85
ZoneTransitionClass · 0.85
_DescribedTzfileClass · 0.85
construct_zoneFunction · 0.85
utcoffsetMethod · 0.45

Tested by

no test coverage detected