blob: 7521ac3c5432d602d86dbac5ade7f408662667f1 (
plain)
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
55
56
|
from __future__ import with_statement
from blinker import Signal
def test_temp_connection():
sig = Signal()
canary = []
receiver = lambda sender: canary.append(sender)
sig.send(1)
with sig.connected_to(receiver):
sig.send(2)
sig.send(3)
assert canary == [2]
assert not sig.receivers
def test_temp_connection_for_sender():
sig = Signal()
canary = []
receiver = lambda sender: canary.append(sender)
with sig.connected_to(receiver, sender=2):
sig.send(1)
sig.send(2)
assert canary == [2]
assert not sig.receivers
def test_temp_connection_failure():
sig = Signal()
canary = []
receiver = lambda sender: canary.append(sender)
class Failure(Exception):
pass
try:
sig.send(1)
with sig.connected_to(receiver):
sig.send(2)
raise Failure
sig.send(3)
except Failure:
pass
else:
raise AssertionError("Context manager did not propagate.")
assert canary == [2]
assert not sig.receivers
|