Skip to content

Commit 493b0d2

Browse files
committed
ch25: sentinel metaclass example
1 parent 8d882d9 commit 493b0d2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

25-class-metaprog/sentinel/sentinel_test.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pickle
2+
13
from sentinel import Sentinel
24

35
class PlainSentinel(Sentinel): pass
@@ -12,12 +14,17 @@ def test_repr():
1214

1315

1416
def test_pickle():
15-
from pickle import dumps, loads
16-
s = dumps(PlainSentinel)
17-
ps = loads(s)
17+
s = pickle.dumps(PlainSentinel)
18+
ps = pickle.loads(s)
1819
assert ps is PlainSentinel
1920

2021

2122
def test_custom_repr():
2223
assert repr(SentinelCustomRepr) == '***SentinelRepr***'
23-
24+
25+
26+
def test_sentinel_comes_ready_to_use():
27+
assert repr(Sentinel) == 'Sentinel'
28+
s = pickle.dumps(Sentinel)
29+
ps = pickle.loads(s)
30+
assert ps is Sentinel

0 commit comments

Comments
 (0)