async def test_context_manager(self, r: aioredis.Redis): async with r.pubsub() as pubsub: await pubsub.subscribe("foo") assert pubsub.connection is not None assert pubsub.connection is None assert pubsub.channels == {} assert pubsub.patterns == {}
async def test_pattern_message_handler(self, r: aioredis.Redis): p = r.pubsub(ignore_subscribe_messages=True) await p.psubscribe(**{self.pattern: self.message_handler}) assert await wait_for_message(p) is None await r.publish(self.channel, self.data) assert await wait_for_message(p) is None assert self.message == self.make_message( "pmessage", self.channel, self.data, pattern=self.pattern ) # test that we reconnected to the correct pattern self.message = None await p.connection.disconnect() assert await wait_for_message(p) is None # should reconnect new_data = self.data + "new data" await r.publish(self.channel, new_data) assert await wait_for_message(p) is None assert self.message == self.make_message( "pmessage", self.channel, new_data, pattern=self.pattern )