-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from camptocamp/public_broadcast
Made the broadcast API public
- Loading branch information
Showing
10 changed files
with
89 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
c2cwsgiutils/_broadcast/local.py → c2cwsgiutils/broadcast/local.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,59 @@ | ||
from c2cwsgiutils._broadcast import local | ||
from c2cwsgiutils import _broadcast | ||
import pytest | ||
|
||
from c2cwsgiutils.broadcast import local | ||
from c2cwsgiutils import broadcast | ||
|
||
def test_local(): | ||
_broadcast._broadcaster = local.LocalBroadcaster() # pylint: disable=W0212 | ||
|
||
@pytest.yield_fixture() | ||
def local_broadcaster(): | ||
broadcast._broadcaster = local.LocalBroadcaster() # pylint: disable=W0212 | ||
try: | ||
cb_calls = [0, 0] | ||
yield | ||
finally: | ||
broadcast._broadcaster = None # pylint: disable=W0212 | ||
|
||
def cb1(data): | ||
cb_calls[0] += 1 | ||
return data + 1 | ||
|
||
def cb2(data): | ||
cb_calls[1] += 1 | ||
def test_local(local_broadcaster): | ||
cb_calls = [0, 0] | ||
|
||
assert _broadcast.broadcast("test1", {'data': 1}, expect_answers=True) == [] # pylint: disable=W0212 | ||
assert cb_calls == [0, 0] | ||
def cb1(data): | ||
cb_calls[0] += 1 | ||
return data + 1 | ||
|
||
_broadcast.subscribe("test1", cb1) | ||
_broadcast.subscribe("test2", cb2) | ||
assert cb_calls == [0, 0] | ||
def cb2(data): | ||
cb_calls[1] += 1 | ||
|
||
assert _broadcast.broadcast("test1", {'data': 1}) is None | ||
assert cb_calls == [1, 0] | ||
assert broadcast.broadcast("test1", {'data': 1}, expect_answers=True) == [] | ||
assert cb_calls == [0, 0] | ||
|
||
assert _broadcast.broadcast("test2", {'data': 1}) is None | ||
assert cb_calls == [1, 1] | ||
broadcast.subscribe("test1", cb1) | ||
broadcast.subscribe("test2", cb2) | ||
assert cb_calls == [0, 0] | ||
|
||
assert _broadcast.broadcast("test1", {'data': 12}, expect_answers=True) == [13] | ||
assert cb_calls == [2, 1] | ||
assert broadcast.broadcast("test1", {'data': 1}) is None | ||
assert cb_calls == [1, 0] | ||
|
||
finally: | ||
_broadcast._broadcaster = None # pylint: disable=W0212 | ||
assert broadcast.broadcast("test2", {'data': 1}) is None | ||
assert cb_calls == [1, 1] | ||
|
||
assert broadcast.broadcast("test1", {'data': 12}, expect_answers=True) == [13] | ||
assert cb_calls == [2, 1] | ||
|
||
|
||
def test_decorator(local_broadcaster): | ||
cb_calls = [0, 0] | ||
|
||
@broadcast.decorator(expect_answers=True) | ||
def cb1(value): | ||
cb_calls[0] += 1 | ||
return value + 1 | ||
|
||
@broadcast.decorator() | ||
def cb2(): | ||
cb_calls[1] += 1 | ||
|
||
assert cb1(value=12) == [13] | ||
assert cb_calls == [1, 0] | ||
|
||
assert cb2() is None | ||
assert cb_calls == [1, 1] |