-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_hook.py
More file actions
50 lines (40 loc) · 1.36 KB
/
test_hook.py
File metadata and controls
50 lines (40 loc) · 1.36 KB
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
from testfixtures import ShouldRaise, compare
from twisted.internet.defer import inlineCallbacks, TimeoutError
from twisted.trial.unittest import TestCase
from carly import hook, cleanup
from carly.hook import UnconsumedCalls, Call
class Sample(object):
def method(self, foo):
return 'foo'
class TestHook(TestCase):
def testUnconsumedCalls(self):
hook(Sample, 'method')
obj = Sample()
obj.method('foo')
with ShouldRaise(UnconsumedCalls({
(Sample, 'method'): {obj: (Call(protocol=obj,
args=('foo',),
kw={},
result='foo'),)}
})):
cleanup()
def testUnconsumedstr(self):
compare(str(UnconsumedCalls({})), expected='\n{}')
@inlineCallbacks
def testMultipleExpectedBeforeCalls(self):
hook(Sample, 'method')
self.addCleanup(cleanup)
obj = Sample()
call1 = obj.method.called()
call2 = obj.method.called()
obj.method('foo')
obj.method('foo')
yield call2
yield call1
@inlineCallbacks
def testTimeout(self):
hook(Sample, 'method')
self.addCleanup(cleanup)
obj = Sample()
with ShouldRaise(TimeoutError):
yield obj.method.called(timeout=0.01)