From 48c52c8bbb90065c1663eebc8524e3145d3ab9c7 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 11 Jul 2023 16:49:11 +0300 Subject: [PATCH] Fixed tests execution with Python 2.7 --- modules/python/src2/cv2_util.hpp | 2 +- modules/python/test/test_misc.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/python/src2/cv2_util.hpp b/modules/python/src2/cv2_util.hpp index c15fcac486..a7deb5b575 100644 --- a/modules/python/src2/cv2_util.hpp +++ b/modules/python/src2/cv2_util.hpp @@ -71,7 +71,7 @@ public: } operator bool() { - return static_cast(obj_); + return obj_ != nullptr; } PyObject* release() diff --git a/modules/python/test/test_misc.py b/modules/python/test/test_misc.py index ed13d66b93..afe3fcc5db 100644 --- a/modules/python/test/test_misc.py +++ b/modules/python/test/test_misc.py @@ -223,9 +223,14 @@ class Arguments(NewOpenCVTests): for dtype in (object, str, np.complex128): test_array = np.zeros((4, 4, 3), dtype=dtype) msg = ".*type = {} is not supported".format(test_array.dtype) - self.assertRaisesRegex( - Exception, msg, cv.utils.dumpInputArray, test_array - ) + if sys.version_info[0] < 3: + self.assertRaisesRegexp( + Exception, msg, cv.utils.dumpInputArray, test_array + ) + else: + self.assertRaisesRegex( + Exception, msg, cv.utils.dumpInputArray, test_array + ) def test_20968(self): pixel = np.uint8([[[40, 50, 200]]])