async def test_get_before_put(self):
     channel = AsyncChannel()
     get, put = await asyncio.gather(
             anext(channel),
             momentarily(1, channel.put('foo')))
     self.assertIsNone(put)
     self.assertEqual(get, 'foo')
Exemple #2
0
    async def test_abort_with_pending_get(self):
        channel = AsyncChannel()
        with self.assertRaises(MadeUpError):
            get, abort = await asyncio.gather(
                anext(channel), momentarily(1, channel.abort(MadeUpError())))

        with self.assertRaises(MadeUpError):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
Exemple #3
0
    async def test_close_with_pending_get(self):
        channel = AsyncChannel()
        with self.assertRaises(StopAsyncIteration):
            get, close = await asyncio.gather(anext(channel),
                                              momentarily(1, channel.close()))

        with self.assertRaises(StopAsyncIteration):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
    async def test_abort_with_pending_get(self):
        channel = AsyncChannel()
        with self.assertRaises(MadeUpError):
            get, abort = await asyncio.gather(
                    anext(channel),
                    momentarily(1, channel.abort(MadeUpError())))

        with self.assertRaises(MadeUpError):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
    async def test_close_with_pending_get(self):
        channel = AsyncChannel()
        with self.assertRaises(StopAsyncIteration):
            get, close = await asyncio.gather(
                    anext(channel),
                    momentarily(1, channel.close()))

        with self.assertRaises(StopAsyncIteration):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
Exemple #6
0
    async def test_abort_with_pending_put(self):
        channel = AsyncChannel()
        put, abort, get = await asyncio.gather(
            channel.put('foo'), momentarily(1, channel.abort(MadeUpError())),
            momentarily(2, anext(channel)))
        self.assertIsNone(put)
        self.assertIsNone(abort)
        self.assertEqual(get, 'foo')

        with self.assertRaises(MadeUpError):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
Exemple #7
0
    async def test_close_with_pending_put(self):
        channel = AsyncChannel()
        put, close, get = await asyncio.gather(channel.put('foo'),
                                               momentarily(1, channel.close()),
                                               momentarily(2, anext(channel)))
        self.assertIsNone(put)
        self.assertIsNone(close)
        self.assertEqual(get, 'foo')

        with self.assertRaises(StopAsyncIteration):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
    async def test_close_with_pending_put(self):
        channel = AsyncChannel()
        put, close, get = await asyncio.gather(
                channel.put('foo'),
                momentarily(1, channel.close()),
                momentarily(2, anext(channel)))
        self.assertIsNone(put)
        self.assertIsNone(close)
        self.assertEqual(get, 'foo')

        with self.assertRaises(StopAsyncIteration):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
    async def test_abort_with_pending_put(self):
        channel = AsyncChannel()
        put, abort, get = await asyncio.gather(
                channel.put('foo'),
                momentarily(1, channel.abort(MadeUpError())),
                momentarily(2, anext(channel)))
        self.assertIsNone(put)
        self.assertIsNone(abort)
        self.assertEqual(get, 'foo')

        with self.assertRaises(MadeUpError):
            await anext(channel)
        with self.assertRaises(ValueError):
            await channel.put('foo')
Exemple #10
0
 async def test_get_before_put(self):
     channel = AsyncChannel()
     get, put = await asyncio.gather(anext(channel),
                                     momentarily(1, channel.put('foo')))
     self.assertIsNone(put)
     self.assertEqual(get, 'foo')