Skip to content

Commit e31eaee

Browse files
tangy5tangy5pre-commit-ci[bot]
authored
Add a test case when opencv is installed, enable both scenario (#1740)
* Add a test case when opencv is installed, enable both scenario Signed-off-by: tangy5 <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: tangy5 <[email protected]> Co-authored-by: tangy5 <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6b7d315 commit e31eaee

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tests/unit/transform/test_post.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
1111

12+
import importlib.util
1213
import os
1314
import tempfile
1415
import unittest
@@ -56,14 +57,22 @@
5657
(1, 6, 6),
5758
]
5859

59-
FINDCONTOURSD_DATA = [
60+
FINDCONTOURSD_DATA_NO_OPENCV = [
6061
{"keys": "pred", "labels": "Other", "min_positive": 4, "min_poly_area": 1},
6162
{
6263
"pred": np.array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]),
6364
},
6465
[[[3, 4], [1, 4], [0, 3], [0, 1], [1, 0], [3, 0], [4, 1], [4, 3], [3, 4]]],
6566
]
6667

68+
FINDCONTOURSD_DATA_OPENCV = [
69+
{"keys": "pred", "labels": "Other", "min_positive": 4, "min_poly_area": 1},
70+
{
71+
"pred": np.array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]),
72+
},
73+
[[[1, 2], [2, 1], [3, 2], [2, 3]], [[1, 1], [1, 3], [3, 3], [3, 1]]],
74+
]
75+
6776
DUMPIMAGEPREDICTION2DD_DATA = [
6877
{
6978
"image": np.random.rand(1, 3, 5, 5),
@@ -114,8 +123,12 @@ def test_result(self, args, input_data, expected_shape):
114123
self.assertEqual(res["pred"].shape, expected_shape)
115124

116125

126+
def is_opencv_installed():
127+
return importlib.util.find_spec("cv2") is not None
128+
129+
117130
class TestFindContoursd(unittest.TestCase):
118-
@parameterized.expand([FINDCONTOURSD_DATA])
131+
@parameterized.expand([FINDCONTOURSD_DATA_OPENCV if is_opencv_installed() else FINDCONTOURSD_DATA_NO_OPENCV])
119132
def test_result(self, args, input_data, expected_output):
120133
res = FindContoursd(**args)(input_data)
121134
self.assertEqual(res["result"]["annotation"]["elements"][0]["contours"], expected_output)

0 commit comments

Comments
 (0)