ch25: sentinel metaclass example
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import pickle
|
||||||
|
|
||||||
from sentinel import Sentinel
|
from sentinel import Sentinel
|
||||||
|
|
||||||
class PlainSentinel(Sentinel): pass
|
class PlainSentinel(Sentinel): pass
|
||||||
@@ -12,12 +14,17 @@ def test_repr():
|
|||||||
|
|
||||||
|
|
||||||
def test_pickle():
|
def test_pickle():
|
||||||
from pickle import dumps, loads
|
s = pickle.dumps(PlainSentinel)
|
||||||
s = dumps(PlainSentinel)
|
ps = pickle.loads(s)
|
||||||
ps = loads(s)
|
|
||||||
assert ps is PlainSentinel
|
assert ps is PlainSentinel
|
||||||
|
|
||||||
|
|
||||||
def test_custom_repr():
|
def test_custom_repr():
|
||||||
assert repr(SentinelCustomRepr) == '***SentinelRepr***'
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user