2019-08-07 02:48:40 -03:00
|
|
|
from torba.stream import StreamController
|
2019-08-07 11:27:25 -03:00
|
|
|
from torba.testcase import AsyncioTestCase
|
2019-08-07 02:48:40 -03:00
|
|
|
|
2019-08-07 11:27:25 -03:00
|
|
|
|
|
|
|
class StreamControllerTestCase(AsyncioTestCase):
|
2019-08-07 02:48:40 -03:00
|
|
|
def test_non_unique_events(self):
|
|
|
|
events = []
|
|
|
|
controller = StreamController()
|
|
|
|
controller.stream.listen(on_data=events.append)
|
|
|
|
controller.add("yo")
|
|
|
|
controller.add("yo")
|
2019-10-06 00:12:01 +03:00
|
|
|
self.assertListEqual(events, ["yo", "yo"])
|
2019-08-07 02:48:40 -03:00
|
|
|
|
|
|
|
def test_unique_events(self):
|
|
|
|
events = []
|
|
|
|
controller = StreamController(merge_repeated_events=True)
|
|
|
|
controller.stream.listen(on_data=events.append)
|
|
|
|
controller.add("yo")
|
|
|
|
controller.add("yo")
|
2019-10-06 00:12:01 +03:00
|
|
|
self.assertListEqual(events, ["yo"])
|