From e1bde919923ff1f9d1d197f64ea43b976f034062 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Tue, 17 Nov 2020 16:55:55 -0500 Subject: test_persistence: add VersionIsPoppedFromState test (#673) --- cloudinit/tests/test_persistence.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'cloudinit') diff --git a/cloudinit/tests/test_persistence.py b/cloudinit/tests/test_persistence.py index 7b64ced9..3e5eaa8d 100644 --- a/cloudinit/tests/test_persistence.py +++ b/cloudinit/tests/test_persistence.py @@ -99,6 +99,16 @@ class VersionDefaultsToZero(CloudInitPickleMixin, metaclass=_Collector): assert 0 == ci_pkl_version +class VersionIsPoppedFromState(CloudInitPickleMixin, metaclass=_Collector): + """Test _ci_pkl_version is popped from state before being restored.""" + + def _unpickle(self, ci_pkl_version: int) -> None: + # `self._ci_pkl_version` returns the type's _ci_pkl_version if it isn't + # in instance state, so we need to explicitly check self.__dict__. + sentinel = mock.sentinel.default + assert self.__dict__.get("_ci_pkl_version", sentinel) == sentinel + + class TestPickleMixin: def test_unpickle_called(self): """Test that self._unpickle is called on unpickle.""" -- cgit v1.2.3