Files
example-code-2e/25-class-metaprog/sentinel/sentinel_test.py
2021-05-23 22:30:40 -03:00

31 lines
584 B
Python

import pickle
from sentinel import Sentinel
class PlainSentinel(Sentinel): pass
class SentinelCustomRepr(Sentinel):
repr = '***SentinelRepr***'
def test_repr():
assert repr(PlainSentinel) == 'PlainSentinel'
def test_pickle():
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