Pickling preserves attributes added by subclasses.
(protocol)
| 2598 | |
| 2599 | @pytest.mark.parametrize("protocol", range(0, pickle.HIGHEST_PROTOCOL + 1)) |
| 2600 | def 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]) |
nothing calls this directly
no test coverage detected