Skip to content

Commit cdb363c

Browse files
committed
doctests para Singleton e Borg
1 parent 51476cb commit cdb363c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Martelli/borg.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
"""
2+
>>> b1 = Borg()
3+
>>> b2 = Borg()
4+
>>> b1 is b2
5+
False
6+
>>> b1.i_know_kung_fu = True
7+
>>> b2.i_know_kung_fu
8+
True
9+
>>> del b2.i_know_kung_fu
10+
>>> b1.i_know_kung_fu
11+
Traceback (most recent call last):
12+
...
13+
AttributeError: 'Borg' object has no attribute 'i_know_kung_fu'
14+
"""
15+
16+
117
class Borg:
218

319
_estado_compartilhado = {}

Martelli/singleton.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
>>> t1 = Treco()
3+
>>> t2 = Treco()
4+
>>> t1 is t2
5+
False
6+
>>> s1 = Singleton()
7+
>>> s2 = Singleton()
8+
>>> s1 is s2
9+
True
10+
>>> id(s1), id(s2)
11+
12+
"""
13+
114

215
class Singleton:
316

@@ -6,3 +19,6 @@ def __new__(cls, *args, **kwargs):
619
cls._a_instancia = super().__new__(cls, *args, **kwargs)
720
return cls._a_instancia
821

22+
23+
class Treco:
24+
pass

0 commit comments

Comments
 (0)