def test_write(self): queue = image_transfer.BlockingQueue(10, 30) queue.put = mock.Mock() write_count = 10 for _ in range(0, write_count): queue.write([1]) exp_calls = [mock.call([1])] * write_count self.assertEqual(exp_calls, queue.put.call_args_list)
def test_read(self): max_size = 10 chunk_size = 10 max_transfer_size = 30 queue = image_transfer.BlockingQueue(max_size, max_transfer_size) def get_side_effect(): return [1] * chunk_size queue.get = mock.Mock(side_effect=get_side_effect) while True: data_item = queue.read(chunk_size) if not data_item: break self.assertEqual(max_transfer_size, queue._transferred) exp_calls = [mock.call()] * int(math.ceil(float(max_transfer_size) / chunk_size)) self.assertEqual(exp_calls, queue.get.call_args_list)
def test_tell(self): queue = image_transfer.BlockingQueue(10, 30) self.assertEqual(0, queue.tell()) queue.get = mock.Mock(return_value=[1] * 10) queue.read(10) self.assertEqual(10, queue.tell())
def test_seek(self): queue = image_transfer.BlockingQueue(10, 30) self.assertRaises(IOError, queue.seek, 5)
def test_tell(self): max_transfer_size = 30 queue = image_transfer.BlockingQueue(10, 30) self.assertEqual(max_transfer_size, queue.tell())