test_async.py 951 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import numpy as np
  4. import cv2 as cv
  5. from tests_common import NewOpenCVTests
  6. class AsyncTest(NewOpenCVTests):
  7. def test_async_simple(self):
  8. m = np.array([[1,2],[3,4],[5,6]])
  9. async_result = cv.utils.testAsyncArray(m)
  10. self.assertTrue(async_result.valid())
  11. ret, result = async_result.get(timeoutNs=10**6) # 1ms
  12. self.assertTrue(ret)
  13. self.assertFalse(async_result.valid())
  14. self.assertEqual(cv.norm(m, result, cv.NORM_INF), 0)
  15. def test_async_exception(self):
  16. async_result = cv.utils.testAsyncException()
  17. self.assertTrue(async_result.valid())
  18. try:
  19. _ret, _result = async_result.get(timeoutNs=10**6) # 1ms
  20. self.fail("Exception expected")
  21. except cv.error as e:
  22. self.assertEqual(cv.Error.StsOk, e.code)
  23. if __name__ == '__main__':
  24. NewOpenCVTests.bootstrap()