-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
54 lines (35 loc) · 1013 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from labcoat import Specimen
# Some example objects
class Human:
legs = ['left', 'right']
def set_name(self, name):
self.name = name
class Furniture:
legs = ['a', 'b', 'c', 'd']
class Dog:
legs = ['front left', 'front right', 'back left', 'back right']
tail = True
fur_color = 'black'
def bark(self):
return 'Woof!'
def hump(self, obj):
if isinstance(obj, Human):
raise BadDog('Down boy!')
class BadDog(Exception):
pass
def test():
with Specimen(Dog) as rover:
rover.has.tail
rover.has(4).legs
rover.can.bark()
with Specimen(Furniture) as couch:
couch.has(4).or_more.legs
couch.lacks.tail
couch.cannot.bark()
rover.can.hump(couch)
with Specimen(Human) as owner:
owner.has(2).legs
owner.lacks.tail
rover.cannot.hump(owner).because(BadDog)
if __name__ == '__main__':
test()