ch25: sentinel metaclass example

This commit is contained in:
Luciano Ramalho committed 2021-05-23 22:30:40 -03:00
1 parent 8d882d9560
commit 493b0d2a56
1 file changed
+11 -4
+11 -4
View File
@@ -1,3 +1,5 @@
import pickle
from sentinel import Sentinel
class PlainSentinel(Sentinel): pass
@@ -12,12 +14,17 @@ def test_repr():
def test_pickle():
from pickle import dumps, loads
s = dumps(PlainSentinel)
ps = loads(s)
s = pickle.dumps(PlainSentinel)
ps = pickle.loads(s)
assert ps is PlainSentinel
def test_custom_repr():
assert repr(SentinelCustomRepr) == '***SentinelRepr***'
def test_sentinel_comes_ready_to_use():
assert repr(Sentinel) == 'Sentinel'
s = pickle.dumps(Sentinel)
ps = pickle.loads(s)
assert ps is Sentinel