Example #1
0
    async def test_empty_file(self):
        queue = []
        async_queue = FakeAsyncQueue(queue)
        file = File(ByteArrayFile(bytearray(b"")), queue=async_queue)

        data = file.data()

        with self.assertRaises(StopAsyncIteration):
            await data.__anext__()
Example #2
0
    async def test_read_without_consuming_queue(self):
        queue = []
        async_queue = FakeAsyncQueue(queue)
        file = File(ByteArrayFile(bytearray(b"\x01\x02\x03\x04\x05")),
                    queue=async_queue,
                    read_buffer_size=1,
                    queue_item_size=1)

        result = [bytearray([i + 1]) for i in range(5)]
        result.extend([None, None])

        await file.read()
        self.assertEqual(async_queue.how_many_tasks_done(), 0)

        async for item in file.data():
            pass
        self.assertEqual(async_queue.how_many_tasks_done(), 6)

        self.assertEqual(queue, result)
Example #3
0
    async def test_file_size_lt_read_buffer_size_lt_queue_item_size(self):
        queue = []
        async_queue = FakeAsyncQueue(queue)
        file = File(ByteArrayFile(bytearray(b"\x01\x02\x03\x04\x05")),
                    queue=async_queue,
                    read_buffer_size=6,
                    queue_item_size=7)
        items = []
        async for item in file.data():
            items.append(item)

        self.assertTrue(items == [bytearray(b"\x01\x02\x03\x04\x05")])
Example #4
0
    async def test_queue_item_size_eq_read_buffer_size_lt_file_size(self):
        queue = []
        async_queue = FakeAsyncQueue(queue)
        file = File(ByteArrayFile(bytearray(b"\x01\x02\x03\x04\x05")),
                    queue=async_queue,
                    read_buffer_size=1,
                    queue_item_size=1)
        result = [bytearray([i + 1]) for i in range(5)]
        items = []
        async for item in file.data():
            items.append(item)

        self.assertTrue(items == result)