lbry-sdk/tests/unit/wallet/test_stream_controller.py

30 lines
911 B
Python
Raw Normal View History

from lbry.wallet.stream import StreamController
from lbry.wallet.tasks import TaskGroup
2019-12-31 15:30:13 -05:00
from lbry.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")
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")
self.assertListEqual(events, ["yo"])
2019-12-11 19:31:45 -03:00
class TaskGroupTestCase(AsyncioTestCase):
async def test_cancel_sets_it_done(self):
2019-12-11 19:31:45 -03:00
group = TaskGroup()
group.cancel()
2019-12-11 23:33:34 -03:00
self.assertTrue(group.done.is_set())