diff --git a/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py b/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py index 5187ca71c2b..c896f8b0ae2 100644 --- a/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py +++ b/tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py @@ -5,7 +5,7 @@ import unittest from argparse import Namespace import numpy as np -from generator import generate, generator +import pytest from openvino.tools.mo.back.MatMulNormalizer import SmartReshape_HC_Reshape_MatMul, PullTransposeThroughFQUp from openvino.tools.mo.ops.MatMul import MatMul @@ -19,10 +19,9 @@ from unit_tests.utils.graph import build_graph, regular_op_with_shaped_data, val from unit_tests.utils.graph import regular_op_with_empty_data as op_with_empty_data -@generator -class SmartReshape_HC_Reshape_MatMulTest(unittest.TestCase): - @generate( - *[ +class TestSmartReshape_HC_Reshape_MatMulTest(): + @pytest.mark.parametrize("in1_shape, in2_shape, reshape_pattern, transpose_a, transpose_b, updated_pattern", + [ ([1, 20, 30], [30, 40], [20, -1], False, False, [-1, 30]), ([1, 20, 30], [40, 30], [20, -1], False, True, [-1, 30]), ([1, 30, 20], [30, 40], [-1, 20], True, False, [30, -1]), @@ -59,9 +58,9 @@ class SmartReshape_HC_Reshape_MatMulTest(unittest.TestCase): graph_ref.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[ + @pytest.mark.parametrize("in1_shape, in2_shape, reshape_pattern, transpose_a, transpose_b, updated_pattern",[ ([20, 30], [1, 30, 40], [-1, 40], False, False, [30, -1]), ([20, 30], [1, 40, 30], [40, -1], False, True, [-1, 30]), ([30, 20], [1, 30, 40], [-1, 40], True, False, [30, -1]), @@ -97,7 +96,7 @@ class SmartReshape_HC_Reshape_MatMulTest(unittest.TestCase): graph_ref.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp class FQTransposePullerTest(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py b/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py index 681ea349c8d..ff4aaf8b189 100644 --- a/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py +++ b/tools/mo/unit_tests/mo/back/ShuffleChannelPatternOptimization_test.py @@ -1,10 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest from argparse import Namespace - -from generator import generate, generator +import pytest from openvino.tools.mo.back.ShuffleChannelPatternOptimization import ShuffleChannelFusion, DepthToSpaceFusion from openvino.tools.mo.ops.depth_to_space import DepthToSpaceOp @@ -18,8 +16,7 @@ from unit_tests.utils.graph import build_graph, result, regular_op_with_shaped_d valued_const_with_data, connect, regular_op_with_empty_data -@generator -class ShuffleChannelFusionTest(unittest.TestCase): +class TestShuffleChannelFusionTest(): @staticmethod def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, group): nodes = { @@ -67,7 +64,7 @@ class ShuffleChannelFusionTest(unittest.TestCase): return graph, graph_ref - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[ ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2), ([2, 512, 7, 6], [2, 2, 256, 7, 6], [0, 2, 1, 3, 4], [2, 512, 7, 6], 2), ([1, 200, 200, 200], [1, 50, 4, 200, 200], [0, 2, 1, 3, 4], [1, 200, 200, 200], 50), @@ -77,11 +74,11 @@ class ShuffleChannelFusionTest(unittest.TestCase): ShuffleChannelFusion().find_and_replace_pattern(graph) graph.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) - self.assertTrue(len(graph.get_op_nodes(name='final_reshape')) == 1 and - graph.get_op_nodes(name='final_reshape')[0].op == 'ShuffleChannels') + assert flag, resp + assert len(graph.get_op_nodes(name='final_reshape')) == 1 and \ + graph.get_op_nodes(name='final_reshape')[0].op == 'ShuffleChannels' - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[ ([1, 512, 7, 6], [0, 2, 256, 7, 6], [0, 2, 1, 3, 4], [1, 512, 7, 6], 2), ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 4, 3], [1, 512, 7, 6], 2), ([1, 512, 7, 6], [1, 2, 256, 7, 6], [0, 2, 1, 3, 4], [-1, 512, 7, 6], 2), @@ -91,11 +88,10 @@ class ShuffleChannelFusionTest(unittest.TestCase): graph_ref = graph.copy() ShuffleChannelFusion().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) + assert flag, resp -@generator -class DepthToSpaceFusionTest(unittest.TestCase): +class TestDepthToSpaceFusionTest(): @staticmethod def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, block_size): nodes = { @@ -145,7 +141,7 @@ class DepthToSpaceFusionTest(unittest.TestCase): return graph, graph_ref - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, block_size",[ ([1, 512, 7, 6], [1, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2), ([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [2, 128, 14, 12], 2), ([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 5, 3], [1, 50, 400, 400], 2), @@ -155,11 +151,11 @@ class DepthToSpaceFusionTest(unittest.TestCase): DepthToSpaceFusion().find_and_replace_pattern(graph) graph.clean_up() (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) - self.assertTrue(len(graph.get_op_nodes(name='final_reshape')) == 1 and - graph.get_op_nodes(name='final_reshape')[0].op == 'DepthToSpace') + assert flag, resp + assert len(graph.get_op_nodes(name='final_reshape')) == 1 and \ + graph.get_op_nodes(name='final_reshape')[0].op == 'DepthToSpace' - @generate(*[ + @pytest.mark.parametrize("input_shape, reshape_0_pattern, order, reshape_1_pattern, group",[ ([1, 512, 7, 6], [0, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [1, 128, 14, 12], 2), ([2, 512, 7, 6], [2, 2, 2, 128, 7, 6], [0, 1, 4, 2, 5, 3], [-1, 128, 14, 12], 2), ([1, 200, 200, 200], [1, 2, 2, 50, 200, 200], [0, 1, 4, 2, 3, 5], [1, 50, 400, 400], 2), @@ -169,4 +165,4 @@ class DepthToSpaceFusionTest(unittest.TestCase): graph_ref = graph.copy() DepthToSpaceFusion().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'output') - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/convert/import_from_mo_test.py b/tools/mo/unit_tests/mo/convert/import_from_mo_test.py index 603ff6eeb4b..a0565fbb0f7 100644 --- a/tools/mo/unit_tests/mo/convert/import_from_mo_test.py +++ b/tools/mo/unit_tests/mo/convert/import_from_mo_test.py @@ -5,18 +5,16 @@ import os import tempfile from pathlib import Path -from generator import generator, generate +import pytest from openvino.runtime import serialize from openvino.tools.mo import InputCutInfo, LayoutMap from openvino.tools.mo.utils.ir_engine.ir_engine import IREngine -from unit_tests.mo.unit_test_with_mocked_telemetry import UnitTestWithMockedTelemetry from unit_tests.utils.graph import build_graph from utils import create_onnx_model, save_to_onnx -@generator -class ConvertImportMOTest(UnitTestWithMockedTelemetry): +class TestConvertImportMOTest(): test_directory = os.path.dirname(os.path.realpath(__file__)) @staticmethod @@ -79,7 +77,7 @@ class ConvertImportMOTest(UnitTestWithMockedTelemetry): ]) return ref_graph - @generate(*[ + @pytest.mark.parametrize("params",[ ({}), ({'input': InputCutInfo(name='LeakyRelu_out', shape=None, type=None, value=None)}), ({'layout': {'input': LayoutMap(source_layout='NCHW', target_layout='NHWC')}}), diff --git a/tools/mo/unit_tests/mo/convert/meta_data_test.py b/tools/mo/unit_tests/mo/convert/meta_data_test.py index b5e78a15b0f..515dfd28ea5 100644 --- a/tools/mo/unit_tests/mo/convert/meta_data_test.py +++ b/tools/mo/unit_tests/mo/convert/meta_data_test.py @@ -5,7 +5,6 @@ import os import tempfile from pathlib import Path -from generator import generator from openvino.runtime import get_version as get_rt_version from openvino.runtime import serialize @@ -18,7 +17,6 @@ from utils import save_to_onnx from openvino.tools.mo.utils.ir_reader.restore_graph import restore_graph_from_ir, save_restored_graph -@generator class MetaDataTest(UnitTestWithMockedTelemetry): test_directory = os.path.dirname(os.path.realpath(__file__)) diff --git a/tools/mo/unit_tests/mo/front/Pack_test.py b/tools/mo/unit_tests/mo/front/Pack_test.py index efa9a45b517..73ab96db5fc 100644 --- a/tools/mo/unit_tests/mo/front/Pack_test.py +++ b/tools/mo/unit_tests/mo/front/Pack_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.Pack import Pack from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -34,10 +33,10 @@ nodes_attributes = { } -@generator -class PackTest(unittest.TestCase): +class TestPackTest(): - @generate(*[(2, 2, 0), (3, 3, 0), (4, 4, 0), (4, 4, 1), (4, 1, 0), (4, 1, 1)]) + @pytest.mark.parametrize("num_inputs, num_placeholders, axis", [(2, 2, 0), (3, 3, 0), (4, 4, 0), + (4, 4, 1), (4, 1, 0), (4, 1, 1)]) def test_pack_test_all(self, num_inputs: int, num_placeholders: int, axis: list): graph_edges = [] @@ -79,4 +78,4 @@ class PackTest(unittest.TestCase): replacer.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'last', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py b/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py index a8d8347a050..20edc563d21 100644 --- a/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py +++ b/tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.front.common.partial_infer.concat import concat_infer from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors @@ -20,9 +19,9 @@ nodes_attributes = {'node_1': {'kind': 'data', 'value': None}, } -@generator -class TestConcatPartialInfer(unittest.TestCase): - @generate(*[([1, 3, 227, 227], [1, 3, 220, 227], [1, 3, 447, 227], 2), +class TestConcatPartialInfer(): + @pytest.mark.parametrize("shape1, shape2, output_shape, axis",[([1, 3, 227, 227], [1, 3, 220, 227], + [1, 3, 447, 227], 2), ([1, 3, 227, 227], [1, 3, 227, 220], [1, 3, 227, 447], -1), ([1, 3, dynamic_dimension_value, 227], [1, dynamic_dimension_value, 227, 220], [1, 3, 227, 447], -1), ([1, 3, 10, 227], [1, 3, 10, dynamic_dimension_value], [1, 3, 10, dynamic_dimension_value], -1), @@ -43,9 +42,10 @@ class TestConcatPartialInfer(unittest.TestCase): concat_node = Node(graph, 'concat') concat_infer(concat_node) res_shape = graph.node['node_3']['shape'] - self.assertTrue(strict_compare_tensors(output_shape, res_shape)) + assert strict_compare_tensors(output_shape, res_shape) - @generate(*[(shape_array([1]), shape_array([4]), shape_array([1, 4]), 0), + @pytest.mark.parametrize("value1, value2, output_value, axis",[(shape_array([1]), + shape_array([4]), shape_array([1, 4]), 0), (shape_array([dynamic_dimension_value]), shape_array([4]), shape_array([dynamic_dimension_value, 4]), -1), ]) @@ -65,7 +65,7 @@ class TestConcatPartialInfer(unittest.TestCase): concat_node = Node(graph, 'concat') concat_infer(concat_node) res_value = graph.node['node_3']['value'] - self.assertTrue(strict_compare_tensors(output_value, res_value)) + assert strict_compare_tensors(output_value, res_value) def test_concat_infer_not_match(self): graph = build_graph(nodes_attributes, @@ -81,7 +81,7 @@ class TestConcatPartialInfer(unittest.TestCase): }) concat_node = Node(graph, 'concat') - with self.assertRaisesRegex(Error, "Concat input shapes do not match for node*"): + with pytest.raises(Error, match="Concat input shapes do not match for node*"): concat_infer(concat_node) def test_concat_infer_no_shape(self): @@ -98,5 +98,5 @@ class TestConcatPartialInfer(unittest.TestCase): }) concat_node = Node(graph, 'concat') - with self.assertRaisesRegex(Error, "One of the input shapes is not defined for node *"): + with pytest.raises(Error, match="One of the input shapes is not defined for node *"): concat_infer(concat_node) diff --git a/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py b/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py index 7e4bedf454e..1a352dfb19c 100644 --- a/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py +++ b/tools/mo/unit_tests/mo/front/common/partial_infer/eltwise_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.eltwise import eltwise_infer, eltwise_reverse_infer from openvino.tools.mo.front.common.partial_infer.utils import shape_array, strict_compare_tensors, \ @@ -24,9 +24,9 @@ nodes_attributes = {'node_1': {'value': 2, 'kind': 'data'}, } -@generator -class TestEltwiseInfer(unittest.TestCase): - @generate(*[ + +class TestEltwiseInfer(): + @pytest.mark.parametrize("value1, shape1, value2, shape2, shape_infer, exp_value, exp_shape",[ (np.array(2), [], np.array(3), [], lambda a, b: np.multiply(a, b), np.array(6), []), (np.array(2), [], np.array(3), [], lambda a, b: np.maximum(a, b), np.array(3), []), (np.array(2), [], np.array(3), [], lambda a, b: np.add(a, b), np.array(5), []), @@ -67,8 +67,8 @@ class TestEltwiseInfer(unittest.TestCase): res_shape = graph.node['node_3']['shape'] res_value = eltwise_node.out_node().value if exp_value is not None: - self.assertTrue(strict_compare_tensors(res_value, shape_array(exp_value))) - self.assertTrue(strict_compare_tensors(res_shape, shape_array(exp_shape))) + assert strict_compare_tensors(res_value, shape_array(exp_value)) + assert strict_compare_tensors(res_shape, shape_array(exp_shape)) def test_eltwise_infer_none_val(self): graph = build_graph(nodes_attributes, @@ -89,9 +89,9 @@ class TestEltwiseInfer(unittest.TestCase): res_shape = graph.node['node_3']['shape'] res_value = eltwise_node.out_node().value for i in range(0, len(exp_shape)): - self.assertEqual(exp_shape[i], res_shape[i]) + assert exp_shape[i] == res_shape[i] - self.assertIsNone(res_value) + assert res_value is None def test_eltwise_infer_none_min_max(self): graph = build_graph(nodes_attributes, @@ -107,7 +107,7 @@ class TestEltwiseInfer(unittest.TestCase): graph.graph['layout'] = 'NCHW' eltwise_node = Node(graph, 'eltw_1') - with self.assertRaisesRegex(Error, 'Input shapes mismatch*'): + with pytest.raises(Error, match='Input shapes mismatch*'): eltwise_infer(eltwise_node) diff --git a/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py b/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py index b6fc90204ac..e535d7f8f20 100644 --- a/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py +++ b/tools/mo/unit_tests/mo/front/common/partial_infer/utils_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array, mo_array, is_fully_defined, \ dynamic_dimension_value, dynamic_dimension, shape_array, compatible_shapes, shape_delete, shape_insert, \ @@ -26,9 +26,8 @@ def gen_masked_array(array, masked_indices): return res -@generator -class IsFullyDefinedTest(unittest.TestCase): - @generate(*[(None, False), +class TestIsFullyDefinedTest(): + @pytest.mark.parametrize("data, result",[(None, False), (int64_array([2, 3, 5, 7]), True), # int64 array with valid values (np.array([2, 3, 5, 7]), True), # any numpy array with valid values (np.array([2, dynamic_dimension_value]), True), # array with dynamic dimension value is fully defined! @@ -42,12 +41,11 @@ class IsFullyDefinedTest(unittest.TestCase): ([dynamic_dimension, 1], False), # list with dynamic dimension is not fully defined ]) def test_is_fully_defined(self, data, result): - self.assertEqual(is_fully_defined(data), result) + assert is_fully_defined(data) == result -@generator -class ShapeArrayTest(unittest.TestCase): - @generate(*[([1], shape_array([1]), True), +class TestShapeArrayTest(): + @pytest.mark.parametrize("data, ref, result",[([1], shape_array([1]), True), # if we provide a list with dynamic_dimension_value then it is converted to dynamic dimension ([dynamic_dimension_value, 5], gen_masked_array([1, 5], [0]), True), # if we provide a list with dynamic_dimension then the generated shape array still have it @@ -56,12 +54,12 @@ class ShapeArrayTest(unittest.TestCase): ([2], gen_masked_array([1], []), False), ]) def test_shape_array(self, data, ref, result): - self.assertEqual(strict_compare_tensors(shape_array(data), ref), result) + assert strict_compare_tensors(shape_array(data), ref) == result -@generator -class CompareShapesTest(unittest.TestCase): - @generate(*[(gen_masked_array([1, 2, 3], []), gen_masked_array([1, 2, 3], []), True), +class TestCompareShapesTest(): + @pytest.mark.parametrize("input1, input2, result",[(gen_masked_array([1, 2, 3], []), + gen_masked_array([1, 2, 3], []), True), (gen_masked_array([4, 2, 3], []), gen_masked_array([1, 2, 3], []), False), (gen_masked_array([1, 2], []), gen_masked_array([1, 2, 3], []), False), (gen_masked_array([1, 2, 3], []), gen_masked_array([1, 2], []), False), @@ -75,12 +73,12 @@ class CompareShapesTest(unittest.TestCase): (np.array([1, 2]), np.array([3, 2]), False), ]) def test_compare_shapes(self, input1, input2, result): - self.assertEqual(compatible_shapes(input1, input2), result) + assert compatible_shapes(input1, input2) == result -@generator -class ShapeDeleteTest(unittest.TestCase): - @generate(*[(gen_masked_array([1, 2, 3], []), [], gen_masked_array([1, 2, 3], [])), +class TestShapeDeleteTest(): + @pytest.mark.parametrize("shape, indices, result",[(gen_masked_array([1, 2, 3], []), [], + gen_masked_array([1, 2, 3], [])), # [1, d, 3] -> [d, 3]. Indices input is a list (gen_masked_array([1, 2, 3], [1]), [0], gen_masked_array([2, 3], [0])), # [1, d, 3] -> [d, 3]. Indices input is a numpy array @@ -103,16 +101,16 @@ class ShapeDeleteTest(unittest.TestCase): (np.array([1, 2, 3, 4]), -2, [1, 2, 4]), # [1, 2, 3, 4] -> [1, 2, 4]. Negative index ]) def test_shape_delete(self, shape, indices, result): - self.assertTrue(strict_compare_tensors(shape_delete(shape, indices), result)) + assert strict_compare_tensors(shape_delete(shape, indices), result) def test_shape_delete_raise_exception(self): - with self.assertRaisesRegex(Error, '.*Incorrect parameter type.*'): + with pytest.raises(Error, match ='.*Incorrect parameter type.*'): shape_delete(gen_masked_array([1, 2, 3], []), {}) -@generator -class ShapeInsertTest(unittest.TestCase): - @generate(*[(gen_masked_array([1, 2, 3], []), 1, [5], gen_masked_array([1, 5, 2, 3], [])), +class TestShapeInsertTest(): + @pytest.mark.parametrize("shape, pos, values, result",[(gen_masked_array([1, 2, 3], []), 1, [5], + gen_masked_array([1, 5, 2, 3], [])), (gen_masked_array([1, 2, 3], [1]), 1, [5], gen_masked_array([1, 5, 2, 3], [2])), (gen_masked_array([1, 2, 3], [1]), 1, [dynamic_dimension], gen_masked_array([1, 5, 2, 3], [1, 2])), (gen_masked_array([1, 2, 3], [1]), 0, [dynamic_dimension], gen_masked_array([5, 1, 2, 3], [0, 2])), @@ -124,26 +122,25 @@ class ShapeInsertTest(unittest.TestCase): (gen_masked_array([1], [0]), 0, [7, dynamic_dimension], gen_masked_array([7, 5, 2], [1, 2])), ]) def test_shape_insert(self, shape, pos, values, result): - self.assertTrue(strict_compare_tensors(shape_insert(shape, pos, values), result)) + assert strict_compare_tensors(shape_insert(shape, pos, values), result) def test_shape_insert_raise_exception(self): - with self.assertRaisesRegex(Error, '.*Incorrect parameter type.*'): + with pytest.raises(Error, match='.*Incorrect parameter type.*'): shape_insert(gen_masked_array([1, 2, 3], []), 2, {}) -@generator -class mo_array_test(unittest.TestCase): - @generate(*[(mo_array([2, 3, 5, 7]), np.array([2, 3, 5, 7])), +class Testmo_array_test(): + @pytest.mark.parametrize("data, result",[(mo_array([2, 3, 5, 7]), np.array([2, 3, 5, 7])), (mo_array([2., 3., 5., 7.], dtype=np.float64), np.array([2., 3., 5., 7.])), (mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.], dtype=np.float32)), ]) def test_mo_array_positive(self, data, result): - self.assertEqual(data.dtype, result.dtype) + assert data.dtype == result.dtype - @generate(*[(mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.])), + @pytest.mark.parametrize("data, result",[(mo_array([2., 3., 5., 7.]), np.array([2., 3., 5., 7.])), ]) def test_mo_array_negative(self, data, result): - self.assertNotEqual(data.dtype, result.dtype) + assert data.dtype != result.dtype class clarify_partial_shape_test(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py b/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py index da55cd415bf..7d62cff4b70 100644 --- a/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py +++ b/tools/mo/unit_tests/mo/front/interpolate_reshape_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.interpolate_reshape import InterpolateWithConcat from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -39,8 +38,7 @@ nodes = { } -@generator -class TestInterpolateConcat(unittest.TestCase): +class TestInterpolateConcat(): def test_interpolate_concat_reshape_graph_comparison(self): graph = build_graph(nodes, [ *connect('placeholder', '0:interpolate'), @@ -64,7 +62,7 @@ class TestInterpolateConcat(unittest.TestCase): *connect('concat', 'output'), ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_interpolate_identity_concat_reshape_graph_comparison(self): graph = build_graph(nodes, [ @@ -97,7 +95,7 @@ class TestInterpolateConcat(unittest.TestCase): *connect('concat', 'output'), ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_interpolate_concat_negate(self): graph = build_graph(nodes, [ @@ -120,9 +118,9 @@ class TestInterpolateConcat(unittest.TestCase): *connect('identity_01', 'output_1'), ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[ + @pytest.mark.parametrize("update_attrs",[ {'concat': {'axis': None}}, {'concat': {'axis': -1}}, @@ -148,7 +146,7 @@ class TestInterpolateConcat(unittest.TestCase): ], update_attributes=update_attrs, nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_interpolate_tf_style_concat(self): graph = build_graph(nodes, [ @@ -161,4 +159,4 @@ class TestInterpolateConcat(unittest.TestCase): graph_ref = graph.copy() InterpolateWithConcat().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py b/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py index 0b71abb4be8..14385f66b79 100644 --- a/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py +++ b/tools/mo/unit_tests/mo/front/kaldi/tdnn_component_replacer_test.py @@ -1,20 +1,18 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.kaldi.tdnn_component_replacer import TdnnComponentReplacer from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph, regular_op, result, connect_front, const -@generator -class TdnnComponentReplacerTest(unittest.TestCase): +class TestTdnnComponentReplacerTest(): - @generate(*[ + @pytest.mark.parametrize("weights, biases, time_offsets",[ ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1],), ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 1, 2, 10, 1000],), ([[1, 1, 1], [4, 4, 4]], [1, 2], [-1, 0]), @@ -72,4 +70,4 @@ class TdnnComponentReplacerTest(unittest.TestCase): TdnnComponentReplacer().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, ref_graph, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py b/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py index 31b3f9eb97d..d1eb31dc1af 100644 --- a/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py +++ b/tools/mo/unit_tests/mo/front/mxnet/MXFFTToDFT_test.py @@ -2,9 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -import unittest - -from generator import generator, generate +import pytest from openvino.tools.mo.front.mxnet.MXFFTToDFT import MXFFTToDFT from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -152,10 +150,8 @@ ref_converted_ifft_graph_edges = [ ('abs', 'output'), ] - -@generator -class MXFFTToDFTTest(unittest.TestCase): - @generate(*[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) +class TestMXFFTToDFTTest(): + @pytest.mark.parametrize("input_shape",[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) def test_fft_replacement(self, input_shape): graph = build_graph(nodes_attrs=fft_graph_node_attrs, edges=fft_graph_edges, @@ -170,9 +166,9 @@ class MXFFTToDFTTest(unittest.TestCase): 'placeholder': {'shape': input_shape} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) + @pytest.mark.parametrize("input_shape",[int64_array([3, 100, 100, 8]), int64_array([5, 60])]) def test_ifft_replacement(self, input_shape): graph = build_graph(nodes_attrs=fft_graph_node_attrs, edges=fft_graph_edges, @@ -188,4 +184,4 @@ class MXFFTToDFTTest(unittest.TestCase): 'placeholder': {'shape': input_shape} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py b/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py index edf66a916ed..e6bbd636b6b 100644 --- a/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/AttributedSliceToSlice_test.py @@ -1,19 +1,17 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.onnx.AttributedSliceToSlice import AttributedSliceToSliceReplacer from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, const, connect_front -@generator -class SliceReplacerTest(unittest.TestCase): - @generate(*[ +class TestSliceReplacerTest(): + @pytest.mark.parametrize("attributed_slice_attrs",[ {'op': 'AttributedSlice', 'type': None, 'starts': np.array([0, 0]), 'ends': np.array([1, -1]), 'axes': np.array([0, 1])} ]) def test_attributed_slice_replacer(self, attributed_slice_attrs): @@ -46,4 +44,4 @@ class SliceReplacerTest(unittest.TestCase): ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py index ff510b7573c..282a92c7629 100644 --- a/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/activation_ext_test.py @@ -1,11 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest - import numpy as np import onnx -from generator import generator, generate +import pytest import openvino.tools.mo.front.onnx.activation_ext as extractors from openvino.tools.mo.ops.activation_ops import Elu @@ -15,8 +13,7 @@ from unit_tests.utils.extractors import PB from unit_tests.utils.graph import build_graph -@generator -class ActivationOpsONNXExtractorTest(unittest.TestCase): +class TestActivationOpsONNXExtractorTest(): @staticmethod def _create_node(op_name: str): pb = onnx.helper.make_node(op_name, ["X"], ["Y"]) @@ -37,7 +34,7 @@ class ActivationOpsONNXExtractorTest(unittest.TestCase): status = out[key] == ref[key] if type(status) in [list, np.ndarray]: status = np.all(status) - self.assertTrue(status, 'Mismatch for field {}, observed: {}, expected: {}'.format(key, out[key], ref[key])) + assert status, f"Mismatch for field {key}, observed: {out[key]}, expected: {ref[key]}" @staticmethod def _extract(op_name): @@ -45,7 +42,7 @@ class ActivationOpsONNXExtractorTest(unittest.TestCase): getattr(extractors, op_name + 'Extractor').extract(node) return node.graph.node[node.id] - @generate(*['Abs', 'Acos', 'Asin', 'Atan', 'Acosh', 'Asinh', 'Atanh', 'Cos', 'Cosh', 'Erf', 'Exp', 'Floor', 'Log', 'Not', 'Sigmoid', 'Sin', + @pytest.mark.parametrize("op_name",['Abs', 'Acos', 'Asin', 'Atan', 'Acosh', 'Asinh', 'Atanh', 'Cos', 'Cosh', 'Erf', 'Exp', 'Floor', 'Log', 'Not', 'Sigmoid', 'Sin', 'Sinh', 'Tan', 'Tanh']) def test_default(self, op_name): ref = self._base_attrs(op_name) @@ -55,8 +52,7 @@ class ActivationOpsONNXExtractorTest(unittest.TestCase): self._match(out, ref) -@generator -class TestEluONNXExt(unittest.TestCase): +class TestEluONNXExt(): @staticmethod def _create_elu_node(alpha=1.0): pb = onnx.helper.make_node( @@ -72,7 +68,7 @@ class TestEluONNXExt(unittest.TestCase): def setUpClass(cls): Op.registered_ops['Elu'] = Elu - @generate(*[1.0, 2.0, 3.0]) + @pytest.mark.parametrize("alpha",[1.0, 2.0, 3.0]) def test_elu_ext(self, alpha): node = self._create_elu_node(alpha) extractors.EluExtractor.extract(node) @@ -84,4 +80,4 @@ class TestEluONNXExt(unittest.TestCase): } for key in exp_res.keys(): - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py index 8dd62f9b1ac..a1659794832 100644 --- a/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/squeeze_ext_test.py @@ -1,11 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest - import numpy as np import onnx -from generator import generator, generate +import pytest from openvino.tools.mo.front.onnx.squeeze_ext import SqueezeFrontExtractor from openvino.tools.mo.ops.op import Op @@ -13,8 +11,7 @@ from openvino.tools.mo.ops.squeeze import Squeeze from unit_tests.utils.extractors import PB -@generator -class TestSqueezeONNXExt(unittest.TestCase): +class TestSqueezeONNXExt(): @staticmethod def _create_squeeze_node(axes): if axes is None: @@ -38,7 +35,7 @@ class TestSqueezeONNXExt(unittest.TestCase): def setUpClass(cls): Op.registered_ops['Squeeze'] = Squeeze - @generate(*[[0, 1, 2, 3], [1], None]) + @pytest.mark.parametrize("axes",[[0, 1, 2, 3], [1], None]) def test_squeeze_ext(self, axes): node = self._create_squeeze_node(axes) SqueezeFrontExtractor.extract(node) @@ -50,6 +47,6 @@ class TestSqueezeONNXExt(unittest.TestCase): for key in exp_res.keys(): if type(node[key]) in [list, np.ndarray]: - self.assertTrue(np.array_equal(np.array(node[key]), np.array(exp_res[key]))) + assert np.array_equal(np.array(node[key]), np.array(exp_res[key])) else: - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py index c7fdd8c24e9..c58e4871cb8 100644 --- a/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/transpose_ext_test.py @@ -2,11 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 import itertools -import unittest +import pytest import numpy as np import onnx -from generator import generator, generate from openvino.tools.mo.front.onnx.transpose_ext import TransposeFrontExtractor from openvino.tools.mo.ops.transpose import Transpose @@ -14,8 +13,7 @@ from openvino.tools.mo.ops.op import Op from unit_tests.utils.extractors import PB -@generator -class TestTransposeONNXExt(unittest.TestCase): +class TestTransposeONNXExt(): @staticmethod def _create_transpose_node(order: list): if order is None: @@ -42,7 +40,7 @@ class TestTransposeONNXExt(unittest.TestCase): pass # This generator generates all permutations for [0,1,2,3] and [0,1,2] orders - @generate(*[list(order) for order in list(itertools.permutations(np.arange(4)))] + + @pytest.mark.parametrize("order",[list(order) for order in list(itertools.permutations(np.arange(4)))] + [list(order) for order in list(itertools.permutations(np.arange(3)))] + [None]) def test_transpose_ext(self, order): node = self._create_transpose_node(order) @@ -56,7 +54,7 @@ class TestTransposeONNXExt(unittest.TestCase): for key in exp_res.keys(): if isinstance(exp_res[key], list): - self.assertTrue(np.array_equal(node[key], exp_res[key]), - "Orders are not the same: {} and {}".format(node[key], exp_res[key])) + assert np.array_equal(node[key], exp_res[key]),\ + "Orders are not the same: {} and {}".format(node[key], exp_res[key]) else: - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py b/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py index 852121cecab..07a38883d2a 100644 --- a/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py +++ b/tools/mo/unit_tests/mo/front/onnx/unsqueeze_ext_test.py @@ -1,11 +1,10 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np import onnx -from generator import generator, generate from openvino.tools.mo.front.onnx.unsqueeze_ext import UnsqueezeFrontExtractor from openvino.tools.mo.ops.op import Op @@ -13,8 +12,7 @@ from openvino.tools.mo.ops.unsqueeze import Unsqueeze from unit_tests.utils.extractors import PB -@generator -class TestUnsqueezeONNXExt(unittest.TestCase): +class TestUnsqueezeONNXExt(): @staticmethod def _create_unsqueeze_node(axes): if axes is None: @@ -38,7 +36,7 @@ class TestUnsqueezeONNXExt(unittest.TestCase): def setUpClass(cls): Op.registered_ops['Unsqueeze'] = Unsqueeze - @generate(*[[0, 1, 2, 3], [1], []]) + @pytest.mark.parametrize("axes",[[0, 1, 2, 3], [1], []]) def test_unsqueeze_ext(self, axes): node = self._create_unsqueeze_node(axes) UnsqueezeFrontExtractor.extract(node) @@ -49,6 +47,6 @@ class TestUnsqueezeONNXExt(unittest.TestCase): for key in exp_res.keys(): if type(node[key]) in [list, np.ndarray]: - self.assertTrue(np.array_equal(np.array(node[key]), np.array(exp_res[key]))) + assert np.array_equal(np.array(node[key]), np.array(exp_res[key])) else: - self.assertEqual(node[key], exp_res[key]) + assert node[key] == exp_res[key] diff --git a/tools/mo/unit_tests/mo/front/rank_decomposer_test.py b/tools/mo/unit_tests/mo/front/rank_decomposer_test.py index b068dfcfead..2b7fb690f33 100644 --- a/tools/mo/unit_tests/mo/front/rank_decomposer_test.py +++ b/tools/mo/unit_tests/mo/front/rank_decomposer_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.rank_decomposer import RankDecomposer from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -24,10 +23,9 @@ nodes = lambda output_type: { } -@generator -class RankDecomposerTest(unittest.TestCase): +class TestRankDecomposerTest(): - @generate(np.int32, np.int64) + @pytest.mark.parametrize("output_type", [np.int32, np.int64]) def test_rank_decomposer(self, output_type): graph = build_graph(nodes_attrs=nodes(output_type), edges=[ *connect('input', 'rank'), @@ -44,9 +42,9 @@ class RankDecomposerTest(unittest.TestCase): ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) - self.assertEqual(graph.get_op_nodes(type='Squeeze')[0]['name'], 'my_rank', - 'Name is not inherited from original node for RankDecomposer') + assert flag, resp + assert graph.get_op_nodes(type='Squeeze')[0]['name'] == 'my_rank',\ + 'Name is not inherited from original node for RankDecomposer' print(output_type) def test_rank_decomposer_assertion(self): @@ -54,4 +52,5 @@ class RankDecomposerTest(unittest.TestCase): *connect('input', 'rank'), *connect('rank', 'output'), ], nodes_with_edges_only=True) - self.assertRaises(AssertionError, RankDecomposer().find_and_replace_pattern, graph) + with pytest.raises(AssertionError): + RankDecomposer().find_and_replace_pattern (graph) diff --git a/tools/mo/unit_tests/mo/front/size_replacer_test.py b/tools/mo/unit_tests/mo/front/size_replacer_test.py index 0ad4dbdcfd5..75288d4b580 100644 --- a/tools/mo/unit_tests/mo/front/size_replacer_test.py +++ b/tools/mo/unit_tests/mo/front/size_replacer_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.SizeReplacer import SizeFrontReplacer from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -23,10 +22,9 @@ nodes = lambda output_type: { } -@generator -class SizeReplacerTest(unittest.TestCase): +class TestSizeReplacerTest(): - @generate(np.int32, np.int64) + @pytest.mark.parametrize("output_type" ,[np.int32, np.int64]) def test_size_replacer(self, output_type): graph = build_graph(nodes_attrs=nodes(output_type), edges=[ *connect('input', 'size'), @@ -42,9 +40,9 @@ class SizeReplacerTest(unittest.TestCase): ], nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) - self.assertEqual(graph.get_op_nodes(type='ReduceProd')[0]['name'], 'my_size', - 'Name is not inherited from original node for SizeReplacer') + assert flag, resp + assert graph.get_op_nodes(type='ReduceProd')[0]['name'] == 'my_size',\ + 'Name is not inherited from original node for SizeReplacer' print(output_type) def test_size_replacer_assertion(self): @@ -52,4 +50,5 @@ class SizeReplacerTest(unittest.TestCase): *connect('input', 'size'), *connect('size', 'output'), ], nodes_with_edges_only=True) - self.assertRaises(AssertionError, SizeFrontReplacer().find_and_replace_pattern, graph) + with pytest.raises(AssertionError): + SizeFrontReplacer().find_and_replace_pattern (graph) diff --git a/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py b/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py index 744f5585b8e..687cb940102 100644 --- a/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py +++ b/tools/mo/unit_tests/mo/front/tf/CorrectPaddingsForPadAfterComplex_test.py @@ -5,7 +5,6 @@ import unittest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.tf.CorrectPaddingsForPadAfterComplex import CorrectPaddingsForPadAfterComplex from openvino.tools.mo.front.common.partial_infer.utils import int64_array diff --git a/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py b/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py index 44ecbe6b265..235a43b5406 100644 --- a/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py +++ b/tools/mo/unit_tests/mo/front/tf/ObjectDetectionAPI_test.py @@ -6,7 +6,7 @@ from argparse import Namespace from unittest.mock import patch import os -from generator import generator, generate +import pytest from openvino.tools.mo.front.tf.ObjectDetectionAPI import calculate_shape_keeping_aspect_ratio, \ calculate_placeholder_spatial_shape, ObjectDetectionAPIPreprocessor2Replacement @@ -31,12 +31,11 @@ class FakePipelineConfig: return self._model_params[param] -@generator -class TestCalculateShape(unittest.TestCase): +class TestCalculateShape(): min_size = 600 max_size = 1024 - @generate(*[(100, 300, 341, 1024), + @pytest.mark.parametrize("h, w, th, tw",[(100, 300, 341, 1024), (100, 600, 171, 1024), (100, 3000, 34, 1024), (300, 300, 600, 600), @@ -53,7 +52,7 @@ class TestCalculateShape(unittest.TestCase): (2000, 1800, 667, 600), ]) def test_calculate_shape(self, h, w, th, tw): - self.assertTupleEqual(calculate_shape_keeping_aspect_ratio(h, w, self.min_size, self.max_size), (th, tw)) + assert calculate_shape_keeping_aspect_ratio(h, w, self.min_size, self.max_size) == (th, tw) class TestCalculatePlaceholderSpatialShape(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py b/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py index 15ec580b118..1dfb957c747 100644 --- a/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py +++ b/tools/mo/unit_tests/mo/front/tf/RFFTRealImagToRFFTSplit_test.py @@ -1,10 +1,7 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 - -import unittest - -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.tf.RFFTRealImagToRFFTSplit import RFFTRealImagToRDFTSplit @@ -85,9 +82,8 @@ ref_graph_edges = [ ] -@generator -class RFFTRealImagToRFFTSplitTest(unittest.TestCase): - @generate(*[1, 2, 3]) +class TestRFFTRealImagToRFFTSplitTest(): + @pytest.mark.parametrize("num_of_dims",[1, 2, 3]) def test_replacement(self, num_of_dims): graph = build_graph(nodes_attrs=graph_node_attrs, edges=graph_edges, @@ -102,4 +98,4 @@ class RFFTRealImagToRFFTSplitTest(unittest.TestCase): 'rfft': {'num_of_dimensions': num_of_dims} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py b/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py index b5e5d234a0c..2464b8679d8 100644 --- a/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py +++ b/tools/mo/unit_tests/mo/front/tf/TFFFTToDFT_test.py @@ -2,9 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 -import unittest - -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.front.tf.TFFFTToDFT import TFFFTToDFT @@ -83,9 +81,8 @@ ref_dft_graph_with_signal_size_edges = [ ] -@generator -class TFFFTToDFTTest(unittest.TestCase): - @generate(*[(2, 'DFT', int64_array([-2, -1])), +class TestTFFFTToDFTTest(): + @pytest.mark.parametrize("num_of_dimensions, dft_type, fft_axes",[(2, 'DFT', int64_array([-2, -1])), (2, 'IDFT', int64_array([-2, -1])), (1, 'DFT', int64_array([-1])), (1, 'IDFT', int64_array([-1])), @@ -113,9 +110,9 @@ class TFFFTToDFTTest(unittest.TestCase): 'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)}, }) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[ + @pytest.mark.parametrize("num_of_dims, fft_kind, fft_axes, input_shape, signal_size",[ (2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([100, -1])), (2, 'IRDFT', int64_array([-2, -1]), int64_array([3, 100, 100, 2]), int64_array([100, -1])), (2, 'RDFT', int64_array([-2, -1]), int64_array([3, 100, 100]), int64_array([95, 116])), @@ -159,4 +156,4 @@ class TFFFTToDFTTest(unittest.TestCase): 'fft_axes': {'value': fft_axes, 'shape': int64_array(fft_axes.shape)}, }) (flag, resp) = compare_graphs(graph, ref_graph, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py b/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py index 0247ab46e55..22dc6a4d44e 100644 --- a/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py +++ b/tools/mo/unit_tests/mo/front/tf/WhereDecomposition_test.py @@ -1,12 +1,10 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate - from openvino.tools.mo.front.tf.WhereDecomposition import WhereDecomposition from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs @@ -64,9 +62,8 @@ ref_graph_edges = [ ] -@generator -class TFWhereDecompositionTest(unittest.TestCase): - @generate(*[[1, 100, 120, 150], [16, 125, 14]]) +class TestTFWhereDecompositionTest(): + @pytest.mark.parametrize("input_shape",[[1, 100, 120, 150], [16, 125, 14]]) def test_1(self, input_shape): in_shape = int64_array(input_shape) graph = build_graph(graph_node_attrs, @@ -81,4 +78,4 @@ class TFWhereDecompositionTest(unittest.TestCase): 'placeholder_data': {'shape': in_shape} }) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag,resp diff --git a/tools/mo/unit_tests/mo/graph/graph_test.py b/tools/mo/unit_tests/mo/graph/graph_test.py index e106c3ee806..3611c9c4c5f 100644 --- a/tools/mo/unit_tests/mo/graph/graph_test.py +++ b/tools/mo/unit_tests/mo/graph/graph_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.graph.graph import Node, Graph, add_opoutput, dict_includes_compare_attrs, get_edge_attribute_between_nodes, \ set_edge_attribute_between_nodes @@ -364,8 +364,7 @@ class TestGraphShapeChecker(unittest.TestCase): graph.check_shapes_consistency() -@generator -class TestGraphPortsChecker(unittest.TestCase): +class TestGraphPortsChecker(): nodes = { '0': {'type': 'Parameter', 'value': None, 'kind': 'op', 'op': 'Parameter'}, '0_data': {'value': None, 'shape': None, 'kind': 'data'}, @@ -380,7 +379,7 @@ class TestGraphPortsChecker(unittest.TestCase): '3_data': {'value': None, 'shape': None, 'kind': 'data'}, } - @generate(*[('0', 'in', 1), ('0', 'out', 2), ('1', 'in', 2), ('3', 'out', 2)]) + @pytest.mark.parametrize("node_id, port_type, port_idx",[('0', 'in', 1), ('0', 'out', 2), ('1', 'in', 2), ('3', 'out', 2)]) def test_check_shape_consistency_1(self, node_id: str, port_type: str, port_idx: int): # # ,->2-->2_data---,->3-->3_data @@ -404,7 +403,7 @@ class TestGraphPortsChecker(unittest.TestCase): else: node.add_output_port(idx=port_idx) - with self.assertRaisesRegex(Error, "Node {} has not consecutive {} ports indexes:.*".format(node_id, + with pytest.raises (Error, match= "Node {} has not consecutive {} ports indexes:.*".format(node_id, port_type)): graph.check_nodes_ports_are_consecutive() @@ -1864,4 +1863,5 @@ class TestTopologicalSort(unittest.TestCase): stat_node = Node(graph, "E") nodes_names = [node.name for node in graph.pseudo_topological_sort_with_start_node(start_node=stat_node, reverse=True)] - assert nodes_names == ['E'] \ No newline at end of file + assert nodes_names == ['E'] + \ No newline at end of file diff --git a/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py b/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py index 4eb09947a85..edaebbf1ee1 100644 --- a/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py +++ b/tools/mo/unit_tests/mo/middle/ConvertGroupedStridedSlice_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.middle.ConvertGroupedStridedSlice import ConvertGroupedStridedSlice from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value @@ -108,8 +108,7 @@ one_strided_slice_case_edges = [ ] -@generator -class ConvertGroupedStridedSliceTests(unittest.TestCase): +class TestConvertGroupedStridedSliceTests(): def test_1(self): graph = build_graph(nodes_attributes, [('placeholder_1', 'placeholder_1_data'), @@ -172,7 +171,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_2(self): graph = build_graph(nodes_attributes, @@ -236,7 +235,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Intersection of split ranges in feature dimension def test_3_neg(self): @@ -307,7 +306,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split range overflow in feature dimension def test_4_neg(self): @@ -377,7 +376,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split(1,H,W,54)--->Fake_data (1,H,W,1) # |`---->Sslice1_out (1,H,W,18) @@ -447,7 +446,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split(1,H,W,54) # |`---->Sslice1_out (1,H,W,(0,18)) @@ -511,7 +510,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): ConvertGroupedStridedSlice().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_7_neg(self): graph = build_graph(nodes_attributes, @@ -567,7 +566,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Split(1,54,W,C) # |`---->Sslice1_out (1,(0,18),W,C) @@ -628,10 +627,10 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Test for the case when there is only 1 StridedSlice. - @generate(*[(np.array([1, 227, 227, 54]), + @pytest.mark.parametrize("input_shape, slices, output_shape",[(np.array([1, 227, 227, 54]), np.array([slice(0, 1, 1), slice(0, 227, 1), slice(0, 227, 1), slice(0, 18, 1)]), np.array([1, 227, 227, 18])), (np.array([57, 16, 100, 23]), @@ -659,7 +658,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern = ConvertGroupedStridedSlice() pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'op_output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # Test for case when # 1) There are 4 StridedSlice operations. @@ -763,7 +762,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern = ConvertGroupedStridedSlice() pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # dynamic slice def test_11(self): @@ -804,7 +803,7 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'concat_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp # one unuque StridedSlice def test_12(self): @@ -841,9 +840,9 @@ class ConvertGroupedStridedSliceTests(unittest.TestCase): pattern.find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'sslice_1_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp (flag, resp) = compare_graphs(graph, graph_ref, 'sslice_2_data', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp class AddReshapeAfterStridedSliceTests(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py b/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py index a58cfcecf67..e997e57b614 100644 --- a/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py +++ b/tools/mo/unit_tests/mo/middle/FusedBatchNormTraining_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.middle.FusedBatchNormTraining import FusedBatchNormTraining from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -71,9 +70,8 @@ nodes_attributes = { } -@generator -class FusedBatchNormTrainingTest(unittest.TestCase): - @generate(*[ +class TestFusedBatchNormTrainingTest(): + @pytest.mark.parametrize("op",[ 'FusedBatchNorm', 'FusedBatchNormV2', 'FusedBatchNormV3', ]) def test_transformation(self, op: str): @@ -137,7 +135,7 @@ class FusedBatchNormTrainingTest(unittest.TestCase): graph_ref.nodes['batchnorm']['op'] = op (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_non_training(self): graph = build_graph(nodes_attributes, @@ -161,4 +159,4 @@ class FusedBatchNormTrainingTest(unittest.TestCase): shape_inference(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py b/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py index f952d60daac..b5620a71b58 100644 --- a/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py +++ b/tools/mo/unit_tests/mo/middle/L2NormFusing_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.middle.L2NormFusing import L2NormToNorm from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -67,9 +66,9 @@ edges_after_replacement = [ ] -@generator -class L2NormToNormTest(unittest.TestCase): - @generate(*[(int64_array([2, 3]), int64_array([1]), 'NCHW'), # NC layout, normalize C dimension +class TestL2NormToNormTest(): + @pytest.mark.parametrize("input_shape, axes, layout", + [(int64_array([2, 3]), int64_array([1]), 'NCHW'), # NC layout, normalize C dimension (int64_array([2, 3]), int64_array([1]), 'NHWC'), # NC layout, normalize C dimension (int64_array([2, 3, 5]), int64_array([1]), 'NCHW'), # NCH layout, normalize C dimension (int64_array([2, 3, 5]), int64_array([1]), 'NHWC'), # NCH layout, normalize C dimension @@ -102,10 +101,11 @@ class L2NormToNormTest(unittest.TestCase): ], edges_after_replacement, nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(graph.node[graph.get_nodes_with_attributes(type='NormalizeL2')[0]]['name'] == 'l2_norm_name') - self.assertTrue(flag, resp) + assert (graph.node[graph.get_nodes_with_attributes(type='NormalizeL2')[0]]['name'] == 'l2_norm_name') + assert flag, resp - @generate(*[(int64_array([2]), int64_array([0]), 'NCHW'), + @pytest.mark.parametrize("input_shape, axes, layout", + [(int64_array([2]), int64_array([0]), 'NCHW'), (int64_array([2, 3]), int64_array([0]), 'NCHW'), (int64_array([2, 3]), int64_array([0]), 'NHWC'), (int64_array([2, 3]), int64_array([0, 1]), 'NCHW'), @@ -161,4 +161,4 @@ class L2NormToNormTest(unittest.TestCase): ], edges, nodes_with_edges_only=True) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py b/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py index 11ec3cc69ae..393b4f7bac6 100644 --- a/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py +++ b/tools/mo/unit_tests/mo/middle/PreserveRuntimeInfo_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.elemental import copy_shape_infer from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -94,9 +93,8 @@ edges_with_transpose_for_case_with_two_results = [ ] -@generator -class PreserveRuntimeInfoTest(unittest.TestCase): - @generate(*[ +class TestPreserveRuntimeInfoTest(): + @pytest.mark.parametrize("nhwc_to_nchw_order, nchw_to_nhwc_order, add_permutation_attrs",[ ([0, 3, 1, 2], [0, 2, 3, 1], True), ([0, 4, 1, 2, 3], [0, 2, 3, 4, 1], True), (None, None, False), @@ -135,19 +133,19 @@ class PreserveRuntimeInfoTest(unittest.TestCase): PreserveRuntimeInfo().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result') - self.assertTrue(flag, resp) + assert flag, resp - self.assertFalse(param_node.has_valid('permute_attrs')) - self.assertFalse(param_node.out_node(0).has_valid('permutation')) + assert not param_node.has_valid('permute_attrs') + assert not param_node.out_node(0).has_valid('permutation') if add_permutation_attrs: rt_info = param_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)) + assert np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order) rt_info = result_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['order'], nhwc_to_nchw_order)) + assert np.array_equal(old_api_map['order'], nhwc_to_nchw_order) def test_auto_disable_nhwc_to_nchw(self): shape_len = 4 @@ -173,18 +171,18 @@ class PreserveRuntimeInfoTest(unittest.TestCase): PreserveRuntimeInfo().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result') - self.assertTrue(flag, resp) + assert flag, resp rt_info = param_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['inverse_order'], [0, 2, 3, 1])) + assert np.array_equal(old_api_map['inverse_order'], [0, 2, 3, 1]) rt_info = result_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['order'], [0, 3, 1, 2])) + assert np.array_equal(old_api_map['order'], [0, 3, 1, 2]) - @generate(*[ - ([0, 3, 1, 2], [0, 2, 3, 1], True, 'DFT'), + @pytest.mark.parametrize("nhwc_to_nchw_order, nchw_to_nhwc_order,add_permutation_attrs, fft_kind", + [([0, 3, 1, 2], [0, 2, 3, 1], True, 'DFT'), ([0, 3, 1, 2], [0, 2, 3, 1], True, 'IDFT'), (None, None, False, 'DFT'), (None, None, False, 'IDFT'), @@ -235,12 +233,12 @@ class PreserveRuntimeInfoTest(unittest.TestCase): PreserveRuntimeInfo().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result1') - self.assertTrue(flag, resp) + assert flag, resp - self.assertFalse(param1_node.has_valid('permute_attrs')) - self.assertFalse(param1_node.out_node(0).has_valid('permutation')) + assert not param1_node.has_valid('permute_attrs') + assert not param1_node.out_node(0).has_valid('permutation') if add_permutation_attrs: rt_info = param1_node.rt_info.info old_api_map = rt_info[('old_api_map_order', 0)].info - self.assertTrue(np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order)) + assert np.array_equal(old_api_map['inverse_order'], nchw_to_nhwc_order) diff --git a/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py b/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py index 6eff641ccdd..e65eef945a1 100644 --- a/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py +++ b/tools/mo/unit_tests/mo/middle/UpsampleToResample_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.middle.UpsampleToResample import UpsampleToResample from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float32_array @@ -143,9 +142,8 @@ ref_graph_edges = [ ] -@generator -class UpsampleToResampleTest(unittest.TestCase): - @generate(*[([2, 10, 20, 30], [1, 1, 5, 5], [2, 3]), +class TestUpsampleToResampleTest(): + @pytest.mark.parametrize("input_shape, scales, axes",[([2, 10, 20, 30], [1, 1, 5, 5], [2, 3]), ([2, 20, 30, 40], [1, 1, 3, 3], [2, 3]), ([2, 10, 20, 30], [1, 1, 6, 5], [2, 3]), ([2, 20, 30, 40], [1, 1, 3, 4], [2, 3]), @@ -193,9 +191,9 @@ class UpsampleToResampleTest(unittest.TestCase): }) UpsampleToResample().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp - @generate(*[([2, 10, 20, 30], [1, 2, 5, 5],), + @pytest.mark.parametrize("input_shape, scales",[([2, 10, 20, 30], [1, 2, 5, 5],), ([2, 3, 20, 30, 40], [1, 2, 3, 3, 3],), ]) def test_pattern_does_not_satisfy(self, input_shape, scales): @@ -214,4 +212,4 @@ class UpsampleToResampleTest(unittest.TestCase): UpsampleToResample().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, ref_graph, 'output') - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py b/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py index 065419fe6d4..de0c363fb9a 100644 --- a/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py +++ b/tools/mo/unit_tests/mo/middle/dequantize_linear_resolver_test.py @@ -9,7 +9,7 @@ from openvino.tools.mo.middle.dequantize_linear_resolver import DequantizeLinear from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph -from generator import generator, generate +import pytest nodes1_attributes = { 'input': {'kind': 'op', 'op': 'AnyOp'}, @@ -145,9 +145,9 @@ class TestDequantizeLinearResolver(unittest.TestCase): (flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True) self.assertTrue(flag, resp) -@generator -class TestDequantizeWithAxis(unittest.TestCase): - @generate(*[(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), +class TestDequantizeWithAxis(): + @pytest.mark.parametrize("input_shape, scale_param_value, zero_param_value, target_shape, axis", + [(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]), 2), (int64_array([1, 3, 4, 4]), int64_array([2, 3, 4, 5]), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 3, 1, 1]), 1), @@ -234,4 +234,4 @@ class TestDequantizeWithAxis(unittest.TestCase): DequantizeLinearResolver().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'out', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py b/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py index a6b2aceb871..eaacfe79694 100644 --- a/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py +++ b/tools/mo/unit_tests/mo/middle/quantize_linear_resolver_test.py @@ -9,7 +9,7 @@ from openvino.tools.mo.middle.quantize_linear_resolver import QuantizeLinearReso from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph -from generator import generator, generate +import pytest nodes1_attributes = { 'input': {'kind': 'op', 'op': 'AnyOp'}, @@ -247,9 +247,9 @@ class TestQuantizeLinearResolver(unittest.TestCase): self.assertTrue(flag, resp) -@generator -class TestQuantizeWithAxis(unittest.TestCase): - @generate(*[(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), +class TestQuantizeWithAxis(): + @pytest.mark.parametrize("input_shape, scale_param_value, zero_param_value,target_shape, in_low, in_high, out_low, out_high, axis", + [(int64_array([1, 3, 4, 4]), np.array([2, 3, 4, 5], dtype=np.float32), np.array([2, 3, 4, 5], dtype=np.uint8), int64_array([1, 1, 4, 1]), np.array([-2., -3., -4., -5.]), np.array([253., 252., 251., 250.]), 0, 255, 2), @@ -366,4 +366,4 @@ class TestQuantizeWithAxis(unittest.TestCase): QuantizeLinearResolver().find_and_replace_pattern(graph) (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/ops/Complex_test.py b/tools/mo/unit_tests/mo/ops/Complex_test.py index 48e37c04c39..4fcd8a61e61 100644 --- a/tools/mo/unit_tests/mo/ops/Complex_test.py +++ b/tools/mo/unit_tests/mo/ops/Complex_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array from openvino.tools.mo.graph.graph import Node @@ -31,9 +30,8 @@ graph_edges_sizes = [ ] -@generator -class TestComplexOp(unittest.TestCase): - @generate(*[ +class TestComplexOp(): + @pytest.mark.parametrize("input_shape, output_shape",[ ([1, 260, 100, 150], [1, 260, 100, 150, 2]), ([1, 260, 100], [1, 260, 100, 2]), ([5, 14, 300, 40], [5, 14, 300, 40, 2]), @@ -52,5 +50,5 @@ class TestComplexOp(unittest.TestCase): msg = "Complex operation infer failed for case: expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['complex_data']['shape'], int64_array(output_shape)), - msg.format(output_shape, graph.node['complex_data']['shape'])) + assert np.array_equal(graph.node['complex_data']['shape'], int64_array(output_shape)),\ + msg.format(output_shape, graph.node['complex_data']['shape']) diff --git a/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py b/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py index 91ea30aa25f..89632480a0f 100644 --- a/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py +++ b/tools/mo/unit_tests/mo/ops/ExtractImagePatches_test.py @@ -1,10 +1,8 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 - -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.ExtractImagePatches import ExtractImagePatches from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -26,9 +24,8 @@ edges = [ ('EIP_data', 'output'), ] -@generator -class TestExtractImagePatchesPartialInfer(unittest.TestCase): - @generate(*[ +class TestExtractImagePatchesPartialInfer(): + @pytest.mark.parametrize("input_shape, sizes, strides, rates, auto_pad, layout, output_shape",[ ([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 2, 2, 27]), ([1, 10, 10, 3], [1, 3, 3, 1], [1, 5, 5, 1], [1, 2, 2, 1], 'valid', 'NHWC', [1, 2, 2, 27]), ([1, 10, 10, 3], [1, 4, 4, 1], [1, 8, 8, 1], [1, 1, 1, 1], 'valid', 'NHWC', [1, 1, 1, 48]), @@ -65,4 +62,4 @@ class TestExtractImagePatchesPartialInfer(unittest.TestCase): eip_node = Node(graph, 'EIP') ExtractImagePatches.infer(eip_node) - self.assertTrue(np.array_equal(eip_node.out_port(0).data.get_shape(), output_shape)) + assert np.array_equal(eip_node.out_port(0).data.get_shape(), output_shape) diff --git a/tools/mo/unit_tests/mo/ops/If_test.py b/tools/mo/unit_tests/mo/ops/If_test.py index 4ced43aec82..fcc457831bd 100644 --- a/tools/mo/unit_tests/mo/ops/If_test.py +++ b/tools/mo/unit_tests/mo/ops/If_test.py @@ -1,11 +1,10 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np import numpy.testing as npt -from generator import generate, generator from openvino.tools.mo.ops.If import If from openvino.tools.mo.ops.elementwise import Add, Mul @@ -22,9 +21,8 @@ from unit_tests.utils.graph import regular_op_with_empty_data, connect, result, empty_data -@generator -class TestIf(unittest.TestCase): - @generate(*[ +class TestIf(): + @pytest.mark.parametrize("cond, output_port_0_shape, output_port_1_shape",[ (np.array([True], dtype=bool), shape_array([3]), shape_array([3])), (np.array([False], dtype=bool), shape_array([3]), shape_array([2])), (shape_array(dynamic_dimension_value), shape_array([3]), shape_array([dynamic_dimension_value])), @@ -94,9 +92,9 @@ class TestIf(unittest.TestCase): graph.stage = 'middle' partial_infer(graph) if_node = Node(graph, 'if') - self.assertTrue(strict_compare_tensors(if_node.out_port(0).data.get_shape(), output_port_0_shape)) + assert strict_compare_tensors(if_node.out_port(0).data.get_shape(), output_port_0_shape) # shape of the "then" branch is [3] and shape of the "else" branch is [2], so the output shape is "[dynamic]" - self.assertTrue(strict_compare_tensors(if_node.out_port(1).data.get_shape(), output_port_1_shape)) + assert strict_compare_tensors(if_node.out_port(1).data.get_shape(), output_port_1_shape) def test_fake_results(self): then_graph_nodes = {**valued_const_with_data('fake_const', int64_array(0)), diff --git a/tools/mo/unit_tests/mo/ops/MatMul_test.py b/tools/mo/unit_tests/mo/ops/MatMul_test.py index f1e8c29fe91..319250d89a9 100644 --- a/tools/mo/unit_tests/mo/ops/MatMul_test.py +++ b/tools/mo/unit_tests/mo/ops/MatMul_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.MatMul import MatMul from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value @@ -12,8 +11,7 @@ from openvino.tools.mo.graph.graph import Node from unit_tests.utils.graph import build_graph_with_attrs -@generator -class TestMatMul(unittest.TestCase): +class TestMatMul(): nodes = [ ('A', {'type': 'Parameter', 'kind': 'op'}), ('A_d', {'kind': 'data'}), @@ -32,7 +30,7 @@ class TestMatMul(unittest.TestCase): ('mat_mul_d', 'op_output'), ] - @generate(*[ + @pytest.mark.parametrize("A_shape, B_shape, C_shape, transpose_a, transpose_b",[ ([1024], [1024, 1000], [1000], False, False), ([dynamic_dimension_value], [1024, 1000], [1000], False, False), ([1024], [dynamic_dimension_value, 1000], [1000], False, False), @@ -65,11 +63,11 @@ class TestMatMul(unittest.TestCase): msg = "MatMul infer failed for case: A_shape={}, B_shape={}, transpose_a={}, transpose_b={} " \ "expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['mat_mul_d']['shape'], shape_array(C_shape)), + assert np.array_equal(graph.node['mat_mul_d']['shape'], shape_array(C_shape)),\ msg.format(A_shape, B_shape, transpose_a, transpose_b, C_shape, - graph.node['mat_mul_d']['shape'])) + graph.node['mat_mul_d']['shape']) - @generate(*[ + @pytest.mark.parametrize("A_shape, B_shape",[ (None, [1024, 1000]), (1, [1024, 1000]), ([], [1024, 1000]), @@ -84,4 +82,5 @@ class TestMatMul(unittest.TestCase): ]) node = Node(graph, 'mat_mul') - self.assertRaises(AssertionError, MatMul.infer, node) + with pytest.raises(AssertionError): + MatMul.infer(node) diff --git a/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py b/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py index f71a84d966c..e845fe5f20a 100644 --- a/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py +++ b/tools/mo/unit_tests/mo/ops/MatMul_value_propagation_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.MatMul import MatMul, transpose from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -32,9 +31,8 @@ graph_edges=[ ] -@generator -class TestMatMulValuePropagation(unittest.TestCase): - @generate(*[ +class TestMatMulValuePropagation(): + @pytest.mark.parametrize("a_shape, a_value, b_shape, b_value, transpose_a, transpose_b",[ ([16, 3], np.arange(-5, -5 + 16 * 3).reshape((16, 3)), [3, 5], np.arange(0, 3 * 5).reshape((3, 5)), False, False), @@ -91,4 +89,4 @@ class TestMatMulValuePropagation(unittest.TestCase): node_data_shape = node_data.shape ref_data_shape = ref_data.shape msg = "Value propagation for 'matmul' node is not correct." - self.assertTrue(node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg) + assert node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg diff --git a/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py b/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py index 319ccc69dbc..bf9a42a6b9c 100644 --- a/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py +++ b/tools/mo/unit_tests/mo/ops/ONNXResize11_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.ONNXResize11 import ONNXResize11Op from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -68,9 +67,8 @@ graph_edges_scales = [ ] -@generator -class TestONNXResize11Op(unittest.TestCase): - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), +class TestONNXResize11Op(): + @pytest.mark.parametrize("input_shape, output_shape, sizes, scales",[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]), @@ -95,10 +93,11 @@ class TestONNXResize11Op(unittest.TestCase): msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape']) - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), + @pytest.mark.parametrize("input_shape, output_shape, scales", + [([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), ([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]), ([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]), @@ -121,10 +120,11 @@ class TestONNXResize11Op(unittest.TestCase): msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape']) - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), + @pytest.mark.parametrize("input_shape, output_shape, sizes, scales", + [([1, 260, 100, 150], [1, 260, 200, 350], [1, 260, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([1, 260, 100, 150], [1, 260, 200, 350], [1, 1, 200, 350], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [1, 1, 140, 280], [1.0, 1.0, 1.0, 1.0]), ([5, 14, 300, 40], [5, 14, 140, 280], [5, 14, 140, 280], [1.0, 1.0, 1.0, 1.0]), @@ -155,10 +155,11 @@ class TestONNXResize11Op(unittest.TestCase): msg = "ONNXResize11 infer failed for case: sizes={}, scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(sizes, scales, output_shape, graph.node['onnx_resize11_data']['shape']) - @generate(*[([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), + @pytest.mark.parametrize("input_shape, output_shape, scales", + [([1, 260, 100, 150], [1, 260, 200, 350], [1.0, 1.0, 2.0, 350 / 150]), ([1, 3, 100, 200], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([5, 14, 300, 40], [5, 14, 140, 280], [1.0, 1.0, 140 / 300, 7.0]), ([5, 14, 300, 40], [5, 14, 140, 560], [1.0, 1.0, 140 / 300, 14.0]), @@ -187,5 +188,5 @@ class TestONNXResize11Op(unittest.TestCase): msg = "ONNXResize11 infer failed for case: scales={}, expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)), - msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape'])) + assert np.array_equal(graph.node['onnx_resize11_data']['shape'], int64_array(output_shape)),\ + msg.format(scales, output_shape, graph.node['onnx_resize11_data']['shape']) diff --git a/tools/mo/unit_tests/mo/ops/ReduceOps_test.py b/tools/mo/unit_tests/mo/ops/ReduceOps_test.py index 8db3a7ab75c..3cfa78c544e 100644 --- a/tools/mo/unit_tests/mo/ops/ReduceOps_test.py +++ b/tools/mo/unit_tests/mo/ops/ReduceOps_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.ops.ReduceOps import reduce_infer from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, is_fully_defined @@ -21,9 +20,8 @@ nodes_attributes = { } -@generator -class ReduceLpTest(unittest.TestCase): - @generate(*[ +class TestReduceLpTest(): + @pytest.mark.parametrize("shape, axes, keepdims, p",[ ([3, 2, 2], [0], True, 1), ([3, 2, 2], [0], True, 2), ([3, 2, 2], [1], True, 2), @@ -53,9 +51,9 @@ class ReduceLpTest(unittest.TestCase): reduce_node = Node(graph, 'reduce_lp') reduce_node.op = reduce_node.type = 'ReduceL' + str(p) reduce_infer(reduce_node) - self.assertTrue(np.array_equal(reduce_node.out_port(0).data.get_value(), reduced)) + assert np.array_equal(reduce_node.out_port(0).data.get_value(), reduced) - @generate(*[ + @pytest.mark.parametrize("shape, axes, keepdims, p",[ ([3, 2, 2], [0], True, 1), ([3, 2, 2], [2], False, 2), ([3, 2, 2], [0, 2], False, 2), @@ -86,4 +84,4 @@ class ReduceLpTest(unittest.TestCase): reduce_node = Node(graph, 'reduce_lp') reduce_node.op = reduce_node.type = 'ReduceL' + str(p) reduce_infer(reduce_node) - self.assertTrue(strict_compare_tensors(reduce_node.out_port(0).data.get_value(), fully_undefined)) + assert strict_compare_tensors(reduce_node.out_port(0).data.get_value(), fully_undefined) diff --git a/tools/mo/unit_tests/mo/ops/broadcast_test.py b/tools/mo/unit_tests/mo/ops/broadcast_test.py index 7da252317a7..72ee2cf5c23 100644 --- a/tools/mo/unit_tests/mo/ops/broadcast_test.py +++ b/tools/mo/unit_tests/mo/ops/broadcast_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, undefined_shape_of_rank from openvino.tools.mo.graph.graph import Node @@ -13,31 +12,30 @@ from unit_tests.utils.graph import build_graph, valued_const_with_data, regular_ shaped_data -@generator -class BroadcastTest(unittest.TestCase): - @generate(*[ - ([1], [3, 3], None, 'numpy', [[1, 1, 1], [1, 1, 1], [1, 1, 1]]), - ([1], [3, 3], None, 'numpy'), +class TestBroadcastTest(): + @pytest.mark.parametrize("data, target_shape, axes_mapping, mode, ref_out, test_raising",[ + ([1], [3, 3], None, 'numpy', [[1, 1, 1], [1, 1, 1], [1, 1, 1]], False), + ([1], [3, 3], None, 'numpy', None, False), # shape broadcasting - ([1], [1, 2], [0], 'explicit'), - ([1], [1, 2], [-2], 'explicit'), - ([1, 7], [5, 1, 7, 3], [1, 2], 'explicit'), - ([2, 1, 3], [2, 1, 3, 3], [0, 1, 2], 'explicit'), - ([2, 1, 3], [5, 2, 1, 3], [1, 2, 3], 'explicit'), + ([1], [1, 2], [0], 'explicit', None, False), + ([1], [1, 2], [-2], 'explicit', None, False), + ([1, 7], [5, 1, 7, 3], [1, 2], 'explicit', None, False), + ([2, 1, 3], [2, 1, 3, 3], [0, 1, 2], 'explicit', None, False), + ([2, 1, 3], [5, 2, 1, 3], [1, 2, 3], 'explicit', None, False), # value broadcasting - ([1], [1, 2], [0], 'explicit', [[1, 1]]), + ([1], [1, 2], [0], 'explicit', [[1, 1]], False), - ([[3, 1]], [2, 1, 2], [1, 2], 'explicit', [[[3, 1]], [[3, 1]]]), # ref_shape (2, 1, 2) + ([[3, 1]], [2, 1, 2], [1, 2], 'explicit', [[[3, 1]], [[3, 1]]], False), # ref_shape (2, 1, 2) - ([[3, 1]], [2, 1, 2], [-2, -1], 'explicit', [[[3, 1]], [[3, 1]]]), # ref_shape (2, 1, 2) + ([[3, 1]], [2, 1, 2], [-2, -1], 'explicit', [[[3, 1]], [[3, 1]]], False), # ref_shape (2, 1, 2) ([[[9, 5, 7]], [[9, 5, 7]]], [2, 2, 1, 3], [1, 2, 3], 'explicit', # in_shape (2, 1, 3) - [[[[9, 5, 7]], [[9, 5, 7]]], [[[9, 5, 7]], [[9, 5, 7]]]]), # ref_out_shape (2, 2, 1, 3) + [[[[9, 5, 7]], [[9, 5, 7]]], [[[9, 5, 7]], [[9, 5, 7]]]], False), # ref_out_shape (2, 2, 1, 3) ([[[9, 5, 7]], [[3, 4, 8]]], [2, 1, 3, 3], [0, 1, 2], 'explicit', # in_shape (2, 1, 3) - [[[[9, 9, 9], [5, 5, 5], [7, 7, 7]]], [[[3, 3, 3], [4, 4, 4], [8, 8, 8]]]]), # ref_out_shape (2, 1, 3, 3) + [[[[9, 9, 9], [5, 5, 5], [7, 7, 7]]], [[[3, 3, 3], [4, 4, 4], [8, 8, 8]]]], False), # ref_out_shape (2, 1, 3, 3) # negative tests ([1], [2, 2], [0], 'explicit', None, True), @@ -45,7 +43,7 @@ class BroadcastTest(unittest.TestCase): ([1, 7], [5, 2, 7, 3], [2, 1], 'explicit', None, True), ([1, 7], [5, 2, 7, 3], [-3, -2], 'explicit', None, True), ]) - def test_broadcast(self, data, target_shape, axes_mapping=None, mode='numpy', ref_out=None, test_raising=False): + def test_broadcast(self, data, target_shape, axes_mapping, mode, ref_out, test_raising): if ref_out is not None: input = valued_const_with_data('data', int64_array(data)) else: @@ -68,25 +66,26 @@ class BroadcastTest(unittest.TestCase): broadcast_node = Node(graph, 'broadcast') if test_raising: - self.assertRaises(AssertionError, Broadcast.infer, broadcast_node) + with pytest.raises(AssertionError): + Broadcast.infer(broadcast_node) return Broadcast.infer(broadcast_node) if ref_out is not None: - self.assertTrue(np.array_equal(broadcast_node.out_node().value, np.array(ref_out))) + assert np.array_equal(broadcast_node.out_node().value, np.array(ref_out)) else: - self.assertTrue(np.array_equal(broadcast_node.out_node().shape, np.array(target_shape))) + assert np.array_equal(broadcast_node.out_node().shape, np.array(target_shape)) - @generate(*[ - ([1], [3], [0], 'explicit', undefined_shape_of_rank(3)), - ([1], [3], None, 'numpy', undefined_shape_of_rank(3)), - ([1], [3], None, 'bidirectional', undefined_shape_of_rank(3)), - ([1, 7], [4], [1, 2], 'explicit', undefined_shape_of_rank(4)), - ([1, 2], [3], None, 'numpy', undefined_shape_of_rank(3)), - ([1, 1], [2], None, 'bidirectional', undefined_shape_of_rank(2)), + @pytest.mark.parametrize("data, target_shape_shape, axes_mapping, mode, ref_out_shape, test_raising",[ + ([1], [3], [0], 'explicit', undefined_shape_of_rank(3), False), + ([1], [3], None, 'numpy', undefined_shape_of_rank(3), False), + ([1], [3], None, 'bidirectional', undefined_shape_of_rank(3),False), + ([1, 7], [4], [1, 2], 'explicit', undefined_shape_of_rank(4), False), + ([1, 2], [3], None, 'numpy', undefined_shape_of_rank(3),False), + ([1, 1], [2], None, 'bidirectional', undefined_shape_of_rank(2), False), ([1, 1], [2, 1], None, 'numpy', None, True), ]) - def test_broadcast_dynamic(self, data, target_shape_shape, axes_mapping=None, mode='numpy', ref_out_shape=None, test_raising=False): + def test_broadcast_dynamic(self, data, target_shape_shape, axes_mapping, mode, ref_out_shape, test_raising): nodes = { **shaped_data('data', int64_array(data)), **shaped_data('target_shape', int64_array(target_shape_shape)), @@ -105,8 +104,9 @@ class BroadcastTest(unittest.TestCase): broadcast_node = Node(graph, 'broadcast') if test_raising: - self.assertRaises(AssertionError, Broadcast.infer, broadcast_node) + with pytest.raises(AssertionError): + Broadcast.infer(broadcast_node) return Broadcast.infer(broadcast_node) - self.assertTrue(np.array_equal(broadcast_node.out_node().shape, ref_out_shape)) + assert np.array_equal(broadcast_node.out_node().shape, ref_out_shape) diff --git a/tools/mo/unit_tests/mo/ops/cast_test.py b/tools/mo/unit_tests/mo/ops/cast_test.py index efdf33a4e90..985a7276514 100644 --- a/tools/mo/unit_tests/mo/ops/cast_test.py +++ b/tools/mo/unit_tests/mo/ops/cast_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.Cast import Cast from openvino.tools.mo.middle.passes.convert_data_type import packed_U4, packed_I4 @@ -19,8 +18,7 @@ nodes = lambda value, dst_type: { } -@generator -class CastTest(unittest.TestCase): +class TestCastTest(): """ Example of checking: 7 == 0111, padded to 0111 0000, results in 112 @@ -29,7 +27,7 @@ class CastTest(unittest.TestCase): -8 == 1000, padded to 1000 0000, results in 128 """ - @generate(*[ + @pytest.mark.parametrize("value, expected, custom_dtype",[ ([0], [0], packed_U4), ([1], [16], packed_U4), ([2], [32], packed_U4), @@ -110,4 +108,4 @@ class CastTest(unittest.TestCase): 'value': expected}}) (flag, resp) = compare_graphs(graph, graph_ref, 'output', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp diff --git a/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py b/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py index 23c893bd215..7843b203371 100644 --- a/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py +++ b/tools/mo/unit_tests/mo/ops/dft_signal_size_canonicalization_test.py @@ -1,18 +1,16 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.dft import FFTBase from openvino.tools.mo.front.common.partial_infer.utils import int64_array -@generator -class DFTSignalSizeCanonicalizationTest(unittest.TestCase): - @generate(*[ +class TestDFTSignalSizeCanonicalizationTest(): + @pytest.mark.parametrize("signal_size, axes, input_shape, expected_result",[ (int64_array([-1, 77]), int64_array([1, 2]), int64_array([2, 180, 180, 2]), int64_array([180, 77])), (int64_array([390, 87]), int64_array([2, 0]), int64_array([2, 180, 180, 2]), int64_array([390, 87])), (int64_array([600, -1, 40]), @@ -38,4 +36,4 @@ class DFTSignalSizeCanonicalizationTest(unittest.TestCase): ]) def test_canonicalization(self, signal_size, axes, input_shape, expected_result): canonicalized_signal_size = FFTBase.canonicalize_signal_size(signal_size, axes, input_shape) - self.assertTrue(np.array_equal(canonicalized_signal_size, expected_result)) + assert np.array_equal(canonicalized_signal_size, expected_result) diff --git a/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py b/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py index 9202aa08c98..5d68f196e62 100644 --- a/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py +++ b/tools/mo/unit_tests/mo/ops/div_value_propagation_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.elementwise import Div from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -32,9 +31,8 @@ graph_edges = [ ] -@generator -class TestDivValuePropagation(unittest.TestCase): - @generate(*[ +class TestDivValuePropagation(): + @pytest.mark.parametrize("a_shape, a_value, b_shape, b_value, elem_type",[ ([2, 3], np.array([[1, 4, -6], [0, -16, 45]], dtype=np.int64), [2, 3], np.array([[1, 2, -4], [1, -8, -5]], dtype=np.int64), np.int64), @@ -80,4 +78,4 @@ class TestDivValuePropagation(unittest.TestCase): node_data_shape = node_data.shape ref_data_shape = ref_data.shape msg = "Value propagation for 'div' node is not correct." - self.assertTrue(node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg) + assert node_data_shape == ref_data_shape and np.all(node_data == ref_data), msg diff --git a/tools/mo/unit_tests/mo/ops/einsum_test.py b/tools/mo/unit_tests/mo/ops/einsum_test.py index ad7e81a2c11..884f6b5e10c 100644 --- a/tools/mo/unit_tests/mo/ops/einsum_test.py +++ b/tools/mo/unit_tests/mo/ops/einsum_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.einsum import Einsum from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -35,9 +34,8 @@ def create_einsum_graph(input_shapes: list, equation: str) -> Graph: return graph -@generator -class TestEinsum(unittest.TestCase): - @generate(*[ +class TestEinsum(): + @pytest.mark.parametrize("input_shapes, equation, ref_output_shape",[ # dot product ([int64_array([10]), int64_array([10])], "i,i->", int64_array([])), # matrix multiplication @@ -74,22 +72,23 @@ class TestEinsum(unittest.TestCase): # get the result res_output_shape = graph.node['einsum_node_d']['shape'] - self.assertTrue(np.array_equal(ref_output_shape, res_output_shape), - 'shape does not match expected: {} and given: {}'.format(ref_output_shape, res_output_shape)) + assert np.array_equal(ref_output_shape, res_output_shape),\ + 'shape does not match expected: {} and given: {}'.format(ref_output_shape, res_output_shape) - @generate(*[ - # incorrect subscript numbers or inputs - ([int64_array([3, 11]), int64_array([11, 4])], "ab,bc,cd->ac", None), - # invalid labels - ([int64_array([3, 11]), int64_array([11, 4])], "a$,Bc->ac", None), - # incompatible shapes - ([int64_array([3, 11]), int64_array([12, 4])], "ab,bc->ac", None), - # not broadcastable shapes - ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 5])], "a...b,b...->a...", None), - # missed ellipsis - ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 4])], "a...b,b...->a", None), - ]) + @pytest.mark.parametrize("input_shapes, equation, ref_output_shape", [ + # incorrect subscript numbers or inputs + ([int64_array([3, 11]), int64_array([11, 4])], "ab,bc,cd->ac", None), + # invalid labels + ([int64_array([3, 11]), int64_array([11, 4])], "a$,Bc->ac", None), + # incompatible shapes + ([int64_array([3, 11]), int64_array([12, 4])], "ab,bc->ac", None), + # not broadcastable shapes + ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 5])], "a...b,b...->a...", None), + # missed ellipsis + ([int64_array([11, 1, 4, 3]), int64_array([3, 11, 7, 4])], "a...b,b...->a", None), +]) def test_invalid_cases(self, input_shapes, equation, ref_output_shape): graph = create_einsum_graph(input_shapes, equation) einsum_node = Node(graph, 'einsum_node') - self.assertRaises(AssertionError, Einsum.infer, einsum_node) + with pytest.raises(AssertionError): + Einsum.infer(einsum_node) diff --git a/tools/mo/unit_tests/mo/ops/expand_dims_test.py b/tools/mo/unit_tests/mo/ops/expand_dims_test.py index be36d55bd21..768fe4077f4 100644 --- a/tools/mo/unit_tests/mo/ops/expand_dims_test.py +++ b/tools/mo/unit_tests/mo/ops/expand_dims_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -28,9 +27,8 @@ nodes_attributes = { } } -@generator -class ExpandDimsOp(unittest.TestCase): - @generate(*[(0, [1, 2, 3, 224, 224]), +class TestExpandDimsOp(): + @pytest.mark.parametrize("axis, ref_out_shape",[(0, [1, 2, 3, 224, 224]), (1, [2, 1, 3, 224, 224]), (2, [2, 3, 1, 224, 224]), (3, [2, 3, 224, 1, 224]), @@ -45,12 +43,11 @@ class ExpandDimsOp(unittest.TestCase): ExpandDims.infer(expand_dims_node) - self.assertTrue(np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))) + assert np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape)) -@generator -class ExpandDimsOpDynamicDims(unittest.TestCase): - @generate(*[(0, [1, 2, 3, dynamic_dimension_value, 224]), +class TestExpandDimsOpDynamicDims(): + @pytest.mark.parametrize("axis, ref_out_shape",[(0, [1, 2, 3, dynamic_dimension_value, 224]), (1, [2, 1, 3, dynamic_dimension_value, 224]), (2, [2, 3, 1, dynamic_dimension_value, 224]), (3, [2, 3, dynamic_dimension_value, 1, 224]), @@ -66,12 +63,11 @@ class ExpandDimsOpDynamicDims(unittest.TestCase): ExpandDims.infer(expand_dims_node) - self.assertTrue(strict_compare_tensors(expand_dims_node.out_node().shape, shape_array(ref_out_shape))) + assert strict_compare_tensors(expand_dims_node.out_node().shape, shape_array(ref_out_shape)) -@generator -class ExpandDimsOpValueInfer(unittest.TestCase): - @generate(*[(0, [2, 3, 224, 224], [1, 2, 3, 224, 224]), +class TestExpandDimsOpValueInfer(): + @pytest.mark.parametrize("axis, in_shape, ref_out_shape",[(0, [2, 3, 224, 224], [1, 2, 3, 224, 224]), (1, [2, 3, 224, 224], [2, 1, 3, 224, 224]), (2, [2, 3, 224, 224], [2, 3, 1, 224, 224]), (3, [2, 3, 224, 224], [2, 3, 224, 1, 224]), @@ -88,5 +84,5 @@ class ExpandDimsOpValueInfer(unittest.TestCase): ExpandDims.infer(expand_dims_node) - self.assertTrue(np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape))) - self.assertTrue(np.array_equal(expand_dims_node.out_node().value, np.array(in_value.reshape(ref_out_shape)))) + assert np.array_equal(expand_dims_node.out_node().shape, np.array(ref_out_shape)) + assert np.array_equal(expand_dims_node.out_node().value, np.array(in_value.reshape(ref_out_shape))) diff --git a/tools/mo/unit_tests/mo/ops/eye_test.py b/tools/mo/unit_tests/mo/ops/eye_test.py index c005200be96..1689f161fdd 100644 --- a/tools/mo/unit_tests/mo/ops/eye_test.py +++ b/tools/mo/unit_tests/mo/ops/eye_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.eye import Eye from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -50,17 +49,16 @@ graph_edges_sizes = [ ] -@generator -class TestComplexOp(unittest.TestCase): - @generate(*[ - ([], [dynamic_dimension_value, dynamic_dimension_value]), - ([1], [dynamic_dimension_value, dynamic_dimension_value]), +class TestComplexOp(): + @pytest.mark.parametrize("input_shape, output_shape, num_rows, num_cols, batch_shape",[ + ([], [dynamic_dimension_value, dynamic_dimension_value],None,None,[]), + ([1], [dynamic_dimension_value, dynamic_dimension_value],None,None,[]), ([1], [2, dynamic_dimension_value, dynamic_dimension_value], None, None, [2]), ([1], [2, 3, dynamic_dimension_value], 3, None, [2]), ([1], [2, dynamic_dimension_value, 4], None, 4, [2]), ([1], [2, 3, 4], [3], [4], [2]) ]) - def test_complex_op_shape_inference(self, input_shape, output_shape, num_rows=None, num_cols=None, batch_shape=[]): + def test_complex_op_shape_inference(self, input_shape, output_shape, num_rows, num_cols, batch_shape): graph = build_graph_with_attrs(nodes_with_attrs=graph_node_attrs_sizes, edges_with_attrs=graph_edges_sizes, update_nodes_attributes=[ @@ -75,8 +73,8 @@ class TestComplexOp(unittest.TestCase): msg = "Eye operation infer failed for case: expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['eye_op_data']['shape'], output_shape), - msg.format(output_shape, graph.node['eye_op_data']['shape'])) + assert np.array_equal(graph.node['eye_op_data']['shape'], output_shape),\ + msg.format(output_shape, graph.node['eye_op_data']['shape']) def test_value_inference(self): graph_node_attrs_sizes = { @@ -103,5 +101,5 @@ class TestComplexOp(unittest.TestCase): msg = "Eye operation infer failed for case: expected_value={}, actual_value={}" - self.assertTrue(np.array_equal(graph.node['eye_op_d']['value'], output_value), - msg.format(output_value, graph.node['eye_op_d']['value'])) + assert np.array_equal(graph.node['eye_op_d']['value'], output_value),\ + msg.format(output_value, graph.node['eye_op_d']['value']) diff --git a/tools/mo/unit_tests/mo/ops/gatherelements_test.py b/tools/mo/unit_tests/mo/ops/gatherelements_test.py index 90ee62fd4b0..feb1807c5cb 100644 --- a/tools/mo/unit_tests/mo/ops/gatherelements_test.py +++ b/tools/mo/unit_tests/mo/ops/gatherelements_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.gatherelements import GatherElements from openvino.tools.mo.front.common.partial_infer.utils import int64_array, strict_compare_tensors, dynamic_dimension @@ -15,9 +14,8 @@ from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, resu dyn = dynamic_dimension -@generator -class GatherElementsInferTest(unittest.TestCase): - @generate(*[ +class TestGatherElementsInferTest(): + @pytest.mark.parametrize("data, indices, axis, ref_res",[ ([[1, 2], [3, 4]], [[0, 1], @@ -96,11 +94,11 @@ class GatherElementsInferTest(unittest.TestCase): GatherElements.infer(gather_el_node) res_output_shape = gather_el_node.out_node().shape - self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) + assert np.array_equal(int64_array(ref_res).shape, res_output_shape) res_output_value = gather_el_node.out_node().value if res_output_value is not None: - self.assertTrue(np.array_equal(int64_array(ref_res), res_output_value)) + assert np.array_equal(int64_array(ref_res), res_output_value) def check_shape_infer(self, data_shape, indices_shape, axis, ref): nodes = { @@ -121,7 +119,7 @@ class GatherElementsInferTest(unittest.TestCase): GatherElements.infer(gather_el_node) res_output_shape = gather_el_node.out_node().shape - self.assertTrue(strict_compare_tensors(res_output_shape, ref)) + assert strict_compare_tensors(res_output_shape, ref) def test_shape_infer_1(self): self.check_shape_infer(data_shape=[3], indices_shape=[100], ref=[100], axis=0) @@ -165,13 +163,13 @@ class GatherElementsInferTest(unittest.TestCase): # negative tests def test_negative_shape_infer_ranks_differ(self): - self.assertRaises(AssertionError, self.check_shape_infer, - data_shape=[1, 3, 64], indices_shape=[1, 3], ref=[1, 3, 1024], axis=2) + with pytest.raises(AssertionError): + self.check_shape_infer(data_shape=[1, 3, 64], indices_shape=[1, 3], ref=[1, 3, 1024], axis=2) def test_negative_shape_infer_axis_out_of_bound(self): - self.assertRaises(AssertionError, self.check_shape_infer, - data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=20) + with pytest.raises(AssertionError): + self.check_shape_infer(data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=20) def test_negative_shape_infer_inconsistent_shapes(self): - self.assertRaises(Error, self.check_shape_infer, - data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=2) + with pytest.raises(Error): + self.check_shape_infer(data_shape=[1, 4, 64], indices_shape=[1, 3, 64], ref=[1, 3, 1024], axis=2) diff --git a/tools/mo/unit_tests/mo/ops/interpolate_test.py b/tools/mo/unit_tests/mo/ops/interpolate_test.py index 3d773ea8177..72b95450936 100644 --- a/tools/mo/unit_tests/mo/ops/interpolate_test.py +++ b/tools/mo/unit_tests/mo/ops/interpolate_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.interpolate import Interpolate from openvino.tools.mo.front.common.partial_infer.utils import int64_array @@ -72,9 +71,9 @@ graph_edges = [ ] -@generator -class TestInterpolateOp(unittest.TestCase): - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), +class TestInterpolateOp(): + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales, axes", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -114,11 +113,12 @@ class TestInterpolateOp(unittest.TestCase): msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales, axes", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [350, 150], [3.5, 150 / 200], [2, 3]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 390, 600], [0.5, 390 / 200, 600 / 410], [0, 2, 3]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -165,11 +165,12 @@ class TestInterpolateOp(unittest.TestCase): msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}, axes={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, axes, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -212,11 +213,12 @@ class TestInterpolateOp(unittest.TestCase): msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) - @generate(*[([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), + @pytest.mark.parametrize("pads_begin, pads_end, input_shape, output_shape, sizes, scales", + [([0], [0], [1, 3, 100, 200], [1, 3, 350, 150], [1, 3, 350, 150], [1.0, 1.0, 3.5, 150 / 200]), ([0, 3, 10, 10], [0], [16, 7, 190, 400], [8, 10, 390, 600], [8, 10, 390, 600], [0.5, 1.0, 390 / 200, 600 / 410]), ([10, 5, 0, 10], [0, 4, 16, 18], [4, 33, 1024, 8000], [56, 42, 520, 8028], @@ -262,6 +264,6 @@ class TestInterpolateOp(unittest.TestCase): msg = "Interpolate-4 infer failed for case: sizes={}, scales={}, pads_begin={}, pads_end={}," \ " expected_shape={}, actual_shape={}" - self.assertTrue(np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)), + assert np.array_equal(graph.node['interpolate_data']['shape'], int64_array(output_shape)),\ msg.format(sizes, scales, pads_begin, pads_end, output_shape, - graph.node['interpolate_data']['shape'])) + graph.node['interpolate_data']['shape']) diff --git a/tools/mo/unit_tests/mo/ops/one_hot_test.py b/tools/mo/unit_tests/mo/ops/one_hot_test.py index be524817798..0c4d839dc62 100644 --- a/tools/mo/unit_tests/mo/ops/one_hot_test.py +++ b/tools/mo/unit_tests/mo/ops/one_hot_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.one_hot import OneHot from openvino.tools.mo.front.common.partial_infer.utils import int64_array, float_array @@ -32,29 +31,28 @@ edges = [ ] -@generator -class TestOneHotInfer(unittest.TestCase): - @generate(*[ +class TestOneHotInfer(): + @pytest.mark.parametrize("input_value, exp_value, axis",[ # 0d input - (1, [0, 1, 0, 0]), + (1, [0, 1, 0, 0], -1), # 1d input - ([1, 2], [[0, 1, 0, 0], [0, 0, 1, 0]]), + ([1, 2], [[0, 1, 0, 0], [0, 0, 1, 0]], -1), # 2D input ([[1, 2], [3, 4]], [[[0, 1, 0, 0], [0, 0, 1, 0]], - [[0, 0, 0, 1], [0, 0, 0, 0]]]), + [[0, 0, 0, 1], [0, 0, 0, 0]]], -1), # 3d input ([[[0, 2], [1, 2]], [[2, 1], [3, 0]]], [[[[1, 0, 0, 0], [0, 0, 1, 0]], [[0, 1, 0, 0], [0, 0, 1, 0]]], - [[[0, 0, 1, 0], [0, 1, 0, 0]], [[0, 0, 0, 1], [1, 0, 0, 0]]]]), + [[[0, 0, 1, 0], [0, 1, 0, 0]], [[0, 0, 0, 1], [1, 0, 0, 0]]]], -1), # 1d input with negative indices - ([-2, 2], [[0, 0, 1, 0], [0, 0, 1, 0]]), + ([-2, 2], [[0, 0, 1, 0], [0, 0, 1, 0]], -1), # check if axis is neither 0 nor -1 ([[1, 2], [3, 4]], [[[0, 0], [1, 0], [0, 1], [0, 0]], [[0, 0], [0, 0], [0, 0], [1, 0]]], 1) ]) - def test_infer(self, input_value, exp_value, axis=-1): + def test_infer(self, input_value, exp_value, axis): graph = build_graph(generate_nodes(int64_array(input_value), axis), edges) onehot_node = Node(graph, 'one_hot') OneHot.infer(onehot_node) res_value = graph.node['one_hot_d']['value'] - self.assertTrue(np.array_equal(exp_value, int64_array(res_value))) + assert np.array_equal(exp_value, int64_array(res_value)) diff --git a/tools/mo/unit_tests/mo/ops/reshape_test.py b/tools/mo/unit_tests/mo/ops/reshape_test.py index 7b0bb26676b..86fd2eb85b2 100644 --- a/tools/mo/unit_tests/mo/ops/reshape_test.py +++ b/tools/mo/unit_tests/mo/ops/reshape_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -47,9 +46,8 @@ nodes_attributes = { } -@generator -class TestReshapeShapeInfer(unittest.TestCase): - @generate(*[ +class TestReshapeShapeInfer(): + @pytest.mark.parametrize("input_value, input_shape, output_shape, ref_value, ref_shape",[ (None, shape_array([1, 100, 4]), shape_array([-1, 25]), None, [16, 25]), (None, shape_array([5, 100, 4]), shape_array([0, -1, 25]), None, [5, 16, 25]), (None, shape_array([5, dynamic_dimension_value, 4]), shape_array([4, -1, 5]), None, @@ -89,5 +87,5 @@ class TestReshapeShapeInfer(unittest.TestCase): node = Node(graph, 'reshape') Reshape.infer(node) if ref_value is not None: - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_value(), shape_array(ref_value))) - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_shape(), shape_array(ref_shape))) + assert strict_compare_tensors(node.out_port(0).data.get_value(), shape_array(ref_value)) + assert strict_compare_tensors(node.out_port(0).data.get_shape(), shape_array(ref_shape)) diff --git a/tools/mo/unit_tests/mo/ops/scatter_test.py b/tools/mo/unit_tests/mo/ops/scatter_test.py index 79b91cec1ce..1066ea8b1c5 100644 --- a/tools/mo/unit_tests/mo/ops/scatter_test.py +++ b/tools/mo/unit_tests/mo/ops/scatter_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.scatter import ScatterElementsUpdate, ScatterUpdate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value @@ -12,9 +11,8 @@ from openvino.tools.mo.graph.graph import Node from unit_tests.utils.graph import build_graph, regular_op_with_empty_data, result, connect, valued_const_with_data -@generator -class ScatterElementsInferTest(unittest.TestCase): - @generate(*[ +class TestScatterElementsInferTest(): + @pytest.mark.parametrize("data, indices, updates, axis, ref_res",[ ([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], @@ -96,15 +94,14 @@ class ScatterElementsInferTest(unittest.TestCase): ScatterElementsUpdate.infer(scatter_el_node) res_output_shape = scatter_el_node.out_node().shape - self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) + assert np.array_equal(int64_array(ref_res).shape, res_output_shape) res_output_value = scatter_el_node.out_node().value - self.assertTrue(np.array_equal(ref_res, res_output_value)) + assert np.array_equal(ref_res, res_output_value) -@generator -class ScatterUpdateInferTest(unittest.TestCase): - @generate(*[ +class TestScatterUpdateInferTest(): + @pytest.mark.parametrize("data, indices, updates, axis, ref_res",[ ([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], @@ -188,7 +185,7 @@ class ScatterUpdateInferTest(unittest.TestCase): ScatterUpdate.infer(scatter_update_node) res_output_shape = scatter_update_node.out_node().shape - self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape)) + assert np.array_equal(int64_array(ref_res).shape, res_output_shape) res_output_value = scatter_update_node.out_node().value - self.assertTrue(np.array_equal(ref_res, res_output_value)) + assert np.array_equal(ref_res, res_output_value) diff --git a/tools/mo/unit_tests/mo/ops/slice_test.py b/tools/mo/unit_tests/mo/ops/slice_test.py index a07514728ef..c69a8fec7ec 100644 --- a/tools/mo/unit_tests/mo/ops/slice_test.py +++ b/tools/mo/unit_tests/mo/ops/slice_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, \ strict_compare_tensors @@ -14,9 +13,8 @@ from unit_tests.utils.graph import build_graph, valued_const_with_data, valued_d connect, shaped_data, shaped_const_with_data -@generator -class TestSliceOp(unittest.TestCase): - @generate(*[ +class TestSliceOp(): + @pytest.mark.parametrize("inp_value, inp_shape, starts, ends, axes, steps, expected_value, expected_shape",[ # standard case ([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1], [[5], [3], [6]], [3, 1]), @@ -107,13 +105,12 @@ class TestSliceOp(unittest.TestCase): Slice.infer(slice_node) if expected_value is not None: - self.assertTrue(strict_compare_tensors(slice_node.out_node().value, expected_value)) - self.assertTrue(strict_compare_tensors(slice_node.out_node().shape, expected_shape)) + assert strict_compare_tensors(slice_node.out_node().value, expected_value) + assert strict_compare_tensors(slice_node.out_node().shape, expected_shape) -@generator -class TestOvSliceOp(unittest.TestCase): - @generate(*[ +class TestOvSliceOp(): + @pytest.mark.parametrize("inp_value, inp_shape, starts, ends, axes, steps, expected_value, expected_shape",[ # standard case ([[4, 5, 6, 7], [2, 3, 5, 6], [5, 6, 8, 9], [5, 6, 8, 9]], [4, 4], [0, 1], [3, 2], [0, 1], [1, 1], [[5], [3], [6]], [3, 1]), @@ -204,5 +201,5 @@ class TestOvSliceOp(unittest.TestCase): OvSlice.infer(slice_node) if expected_value is not None: - self.assertTrue(strict_compare_tensors(slice_node.out_node().value, expected_value)) - self.assertTrue(strict_compare_tensors(slice_node.out_node().shape, expected_shape)) + assert strict_compare_tensors(slice_node.out_node().value, expected_value) + assert strict_compare_tensors(slice_node.out_node().shape, expected_shape) diff --git a/tools/mo/unit_tests/mo/ops/split_test.py b/tools/mo/unit_tests/mo/ops/split_test.py index 962a476489c..de7e5c71c2c 100644 --- a/tools/mo/unit_tests/mo/ops/split_test.py +++ b/tools/mo/unit_tests/mo/ops/split_test.py @@ -4,7 +4,7 @@ import unittest import numpy as np -from generator import generator, generate +import pytest from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, \ dynamic_dimension_value, dynamic_dimension, strict_compare_tensors, mo_array @@ -248,8 +248,7 @@ class TestAttributedVariadicSplitOp(unittest.TestCase): self.assertTrue(np.all(node.split_lengths == np.array([2, 13, 10]))) -@generator -class TestVariadicSplitOp(unittest.TestCase): +class TestVariadicSplitOp(): nodes = { 'input': {'kind': 'op'}, 'split_input_data': {'kind': 'data', 'shape': None, 'value': None}, @@ -280,7 +279,7 @@ class TestVariadicSplitOp(unittest.TestCase): ('split_output_2_data', 'output_2'), ] - @generate(*[int64_array(2), + @pytest.mark.parametrize("axis",[int64_array(2), int64_array([2])]) def test_variadic_split_axis(self, axis): lengths = int64_array([2, 13, 10]) @@ -299,9 +298,9 @@ class TestVariadicSplitOp(unittest.TestCase): VariadicSplit.infer(node) ont_nodes_count = len(node.out_edges()) - self.assertTrue(ont_nodes_count == 3) + assert ont_nodes_count == 3 for out in range(ont_nodes_count): - self.assertTrue(np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))) + assert np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30])) def test_variadic_split_value_inference_with_uint32(self): axis = int64_array(2) @@ -329,11 +328,11 @@ class TestVariadicSplitOp(unittest.TestCase): VariadicSplit.infer(node) ont_nodes_count = len(node.out_edges()) - self.assertTrue(ont_nodes_count == 3) + assert ont_nodes_count == 3 for out in range(ont_nodes_count): - self.assertTrue(np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30]))) + assert np.all(node.out_node(out).shape == int64_array([2, 12, lengths[out], 30])) - @generate(*[int64_array([[2], [2]]), + @pytest.mark.parametrize("axis",[int64_array([[2], [2]]), int64_array([2, 2])]) def test_negative_variadic_split_axis(self, axis): lengths = int64_array([2, 13, 10]) @@ -352,8 +351,8 @@ class TestVariadicSplitOp(unittest.TestCase): try: VariadicSplit.infer(node) except AssertionError as e: - self.assertTrue(e.args[0] == 'VariadicSplit `axis` should be scalar or tensor with shape [1], ' - 'but it`s not for node split_op') + assert e.args[0] == 'VariadicSplit `axis` should be scalar or tensor with shape [1], '\ + 'but it`s not for node split_op' class TestSplitReverseInfer(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/ops/squeeze_test.py b/tools/mo/unit_tests/mo/ops/squeeze_test.py index 714e90928b5..42118250477 100644 --- a/tools/mo/unit_tests/mo/ops/squeeze_test.py +++ b/tools/mo/unit_tests/mo/ops/squeeze_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generate, generator from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -41,9 +40,8 @@ nodes_attributes = { } -@generator -class TestSqueezeInfer(unittest.TestCase): - @generate(*[ +class TestSqueezeInfer(): + @pytest.mark.parametrize("input_value, input_shape, squeeze_dims, ref_value, ref_shape",[ (None, shape_array([1, 2, 1, 4]), shape_array([2]), None, [1, 2, 4]), # allow squeezing dynamic dimensions (None, shape_array([1, 2, dynamic_dimension_value, 4]), shape_array([2]), None, [1, 2, 4]), @@ -67,10 +65,10 @@ class TestSqueezeInfer(unittest.TestCase): }) node = Node(graph, 'squeeze') if ref_shape is None: # the test should fail - with self.assertRaises(Error): + with pytest.raises(Error): Squeeze.infer(node) else: Squeeze.infer(node) if ref_value is not None: - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_value(), ref_value)) - self.assertTrue(strict_compare_tensors(node.out_port(0).data.get_shape(), ref_shape)) + assert strict_compare_tensors(node.out_port(0).data.get_value(), ref_value) + assert strict_compare_tensors(node.out_port(0).data.get_shape(), ref_shape) diff --git a/tools/mo/unit_tests/mo/ops/transpose_test.py b/tools/mo/unit_tests/mo/ops/transpose_test.py index da3968cb378..b28e0d381d1 100644 --- a/tools/mo/unit_tests/mo/ops/transpose_test.py +++ b/tools/mo/unit_tests/mo/ops/transpose_test.py @@ -3,9 +3,8 @@ import itertools import unittest - +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, strict_compare_tensors, \ dynamic_dimension_value @@ -19,8 +18,7 @@ from unit_tests.utils.graph import valued_const_with_data, result, regular_op_wi input_shape = np.array([1, 3, 224, 224]) -@generator -class TestTransposeOp(unittest.TestCase): +class TestTransposeOp(): nodes_attributes = { 'parameter': { 'kind': 'op', @@ -71,7 +69,7 @@ class TestTransposeOp(unittest.TestCase): graph.graph['layout'] = 'NCHW' return graph - @generate(*[list(order) for order in list(itertools.permutations(np.arange(4)))]) + @pytest.mark.parametrize("order",[list(order) for order in list(itertools.permutations(np.arange(4)))]) def test_transpose_infer_1(self, order): graph = self._create_graph_with_transpose(order) transpose_node = Node(graph, 'transpose') @@ -79,7 +77,7 @@ class TestTransposeOp(unittest.TestCase): Transpose.infer(transpose_node) ref = [transpose_node.in_node().shape[i] for i in order] - self.assertTrue(np.array_equal(transpose_node.out_node().shape, np.array(ref))) + assert np.array_equal(transpose_node.out_node().shape, np.array(ref)) def test_transpose_infer_2(self): order = None @@ -89,22 +87,24 @@ class TestTransposeOp(unittest.TestCase): Transpose.infer(transpose_node) ref = np.array([x for x in reversed(transpose_node.in_node().shape)]) - self.assertTrue(np.array_equal(transpose_node.out_node().shape, ref), - "Shapes are not the same: {} and {}".format(transpose_node.out_node().shape, ref)) + assert np.array_equal(transpose_node.out_node().shape, ref),\ + "Shapes are not the same: {} and {}".format(transpose_node.out_node().shape, ref) def test_transpose_infer_neg_1(self): order = np.array([0, 1, 2, 3]) graph = self._create_graph_with_transpose(order) transpose_node = Node(graph, 'transpose') transpose_node['reverse_order'] = True - self.assertRaises(AssertionError, Transpose.infer, transpose_node) + with pytest.raises(AssertionError): + Transpose.infer(transpose_node) def test_transpose_infer_neg_2(self): order = None graph = self._create_graph_with_transpose(order) transpose_node = Node(graph, 'transpose') transpose_node['reverse_order'] = False - self.assertRaises(AssertionError, Transpose.infer, transpose_node) + with pytest.raises(AssertionError): + Transpose.infer(transpose_node) dyn = dynamic_dimension_value diff --git a/tools/mo/unit_tests/mo/ops/unsqueeze_test.py b/tools/mo/unit_tests/mo/ops/unsqueeze_test.py index 72d519dd64c..668bb71d3d1 100644 --- a/tools/mo/unit_tests/mo/ops/unsqueeze_test.py +++ b/tools/mo/unit_tests/mo/ops/unsqueeze_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value, strict_compare_tensors from openvino.tools.mo.graph.graph import Node @@ -13,8 +12,7 @@ from openvino.tools.mo.utils.ir_engine.compare_graphs import compare_graphs from unit_tests.utils.graph import build_graph -@generator -class TestUnsqueezeOp(unittest.TestCase): +class TestUnsqueezeOp(): nodes_attributes = { 'data_1': { 'kind': 'data', @@ -39,7 +37,8 @@ class TestUnsqueezeOp(unittest.TestCase): } } - @generate(*[(shape_array([1, 3, 64, 64]), int64_array([0, 4]), shape_array([1, 1, 3, 64, 1, 64]), + @pytest.mark.parametrize("input_shape, unsq_dims, output_shape, ref_uns_dims, input_value, output_value", + [(shape_array([1, 3, 64, 64]), int64_array([0, 4]), shape_array([1, 1, 3, 64, 1, 64]), int64_array([0, 4]), None, None), (shape_array([2, 3, 64, 64]), int64_array([-1]), shape_array([2, 3, 64, 64, 1]), int64_array([4]), None, None), @@ -75,7 +74,7 @@ class TestUnsqueezeOp(unittest.TestCase): Unsqueeze.infer(unsqueeze_node) (flag, resp) = compare_graphs(graph, graph_ref, 'data_2') - self.assertTrue(flag, resp) - self.assertTrue(strict_compare_tensors(Node(graph, 'data_2').shape, Node(graph_ref, 'data_2').shape)) + assert flag, resp + assert strict_compare_tensors(Node(graph, 'data_2').shape, Node(graph_ref, 'data_2').shape) if Node(graph_ref, 'data_2').value is not None: - self.assertTrue(strict_compare_tensors(Node(graph, 'data_2').value, Node(graph_ref, 'data_2').value)) + assert strict_compare_tensors(Node(graph, 'data_2').value, Node(graph_ref, 'data_2').value) diff --git a/tools/mo/unit_tests/mo/ops/upsample_test.py b/tools/mo/unit_tests/mo/ops/upsample_test.py index e0ae9020372..f70e37a7c2b 100644 --- a/tools/mo/unit_tests/mo/ops/upsample_test.py +++ b/tools/mo/unit_tests/mo/ops/upsample_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.ops.upsample import UpsampleOp from openvino.tools.mo.front.common.partial_infer.utils import shape_array, dynamic_dimension_value, strict_compare_tensors @@ -18,9 +17,8 @@ nodes_attributes = {'node_1': {'type': 'Identity', 'kind': 'op'}, } -@generator -class TestUpsampleOp(unittest.TestCase): - @generate(*[ +class TestUpsampleOp(): + @pytest.mark.parametrize("scales, input_shape, expected_shape",[ (np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])), (np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])), (np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])), @@ -46,9 +44,9 @@ class TestUpsampleOp(unittest.TestCase): upsample_node = Node(graph, 'upsample') UpsampleOp.upsample_infer(upsample_node) res_shape = graph.node['node_3']['shape'] - self.assertTrue(strict_compare_tensors(expected_shape, res_shape)) + assert strict_compare_tensors(expected_shape, res_shape) - @generate(*[ + @pytest.mark.parametrize("scales, input_shape, expected_shape",[ (np.array([1., 1., 2., 2.]), shape_array([1, 3, 227, 227]), shape_array([1, 3, 454, 454])), (np.array([1., 1., 2.5, 1.5]), shape_array([1, 5, 227, 227]), shape_array([1, 5, 567, 340])), (np.array([1., 1., 1.3, 0.7]), shape_array([1, 14, 1023, 713]), shape_array([1, 14, 1329, 499])), @@ -76,4 +74,4 @@ class TestUpsampleOp(unittest.TestCase): upsample_node = Node(graph, 'upsample') UpsampleOp.upsample_infer(upsample_node) res_shape = graph.node['node_3']['shape'] - self.assertTrue(strict_compare_tensors(expected_shape, res_shape)) + assert strict_compare_tensors(expected_shape, res_shape) diff --git a/tools/mo/unit_tests/mo/pipeline/common_test.py b/tools/mo/unit_tests/mo/pipeline/common_test.py index c62a45a5b97..bb71d40b22d 100644 --- a/tools/mo/unit_tests/mo/pipeline/common_test.py +++ b/tools/mo/unit_tests/mo/pipeline/common_test.py @@ -2,17 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 import unittest - -from generator import generator, generate - +import pytest from openvino.tools.mo.graph.graph import Node from openvino.tools.mo.pipeline.common import determined_sort, get_fw_tensor_debug_info, get_sorted_outputs from unit_tests.utils.graph import build_graph_with_edge_attrs -@generator -class TestTopologicalSort(unittest.TestCase): - @generate( +class TestTopologicalSort(): + @pytest.mark.parametrize( "edges",[ [('A', 'Ad', {'out': 0}), ('Ad', 'B', {'in': 0}), ('B', 'Bd', {'out': 0}), @@ -92,7 +89,7 @@ class TestTopologicalSort(unittest.TestCase): ('Hd', 'J', {'in': 1}), ('Dd', 'F', {'in': 1}), ('Fd', 'H', {'in': 1}), - ('Gd', 'H', {'in': 0})] + ('Gd', 'H', {'in': 0})]] ) def test_determined_topological_sort(self, edges): nodes = {'A': {'type': 'Identity', 'kind': 'op'}, @@ -123,8 +120,8 @@ class TestTopologicalSort(unittest.TestCase): outputs = [Node(graph, 'Kd')] for i in range(100): op_order, data_order = determined_sort(outputs) - self.assertListEqual(op_order, ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']) - self.assertListEqual(data_order, ['Ad', 'Bd', 'Cd', 'Dd', 'Ed', 'Fd', 'Gd', 'Hd', 'Id', 'Jd', 'Kd']) + assert op_order == ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'] + assert data_order == ['Ad', 'Bd', 'Cd', 'Dd', 'Ed', 'Fd', 'Gd', 'Hd', 'Id', 'Jd', 'Kd'] class TestGetFWTensorName(unittest.TestCase): diff --git a/tools/mo/unit_tests/mo/utils/broadcasting_test.py b/tools/mo/unit_tests/mo/utils/broadcasting_test.py index f12fa029919..91b79be4de6 100644 --- a/tools/mo/unit_tests/mo/utils/broadcasting_test.py +++ b/tools/mo/unit_tests/mo/utils/broadcasting_test.py @@ -1,19 +1,17 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value, shape_array, strict_compare_tensors from openvino.tools.mo.utils.broadcasting import uni_directional_broadcasting, uni_directional_shape_broadcasting, \ bi_directional_shape_broadcasting -@generator -class TestingBroadcasting(unittest.TestCase): - @generate(*[([], [20, 30, 10], [20, 30, 10]), +class TestingBroadcasting(): + @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]), @@ -24,18 +22,18 @@ class TestingBroadcasting(unittest.TestCase): ([5, 10], [1, 10], None), ]) def test_uni_directional_broadcasting(self, input_shape, target_shape, expected_shape): - self.assertTrue(np.array_equal(uni_directional_shape_broadcasting(input_shape, target_shape), expected_shape)) + assert np.array_equal(uni_directional_shape_broadcasting(input_shape, target_shape), expected_shape) input_value = np.array(np.random.rand(*input_shape)) if expected_shape is not None: expected_value = np.broadcast_to(input_value, int64_array(target_shape)) - self.assertTrue(np.array_equal(uni_directional_broadcasting(input_value, int64_array(target_shape)), - expected_value)) + assert np.array_equal(uni_directional_broadcasting(input_value, int64_array(target_shape)), + expected_value) else: - with self.assertRaisesRegex(Exception, '.*cannot be uni-directionally broadcasted.*'): + with pytest.raises(Exception,match = '.*cannot be uni-directionally broadcasted.*'): uni_directional_broadcasting(input_value, int64_array(target_shape)) - @generate(*[([], [20, 30, 10], [20, 30, 10]), + @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]), @@ -58,11 +56,11 @@ class TestingBroadcasting(unittest.TestCase): def test_uni_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape): result = uni_directional_shape_broadcasting(input_shape, target_shape) if expected_shape is None: - self.assertIsNone(result) + assert result is None else: - self.assertTrue(strict_compare_tensors(result, expected_shape)) + assert strict_compare_tensors(result, expected_shape) - @generate(*[([], [20, 30, 10], [20, 30, 10]), + @pytest.mark.parametrize("input_shape, target_shape, expected_shape",[([], [20, 30, 10], [20, 30, 10]), ([1], [20, 30, 10], [20, 30, 10]), ([1, 1, 10], [20, 30, 10], [20, 30, 10]), ([20, 1, 10], [20, 30, 10], [20, 30, 10]), @@ -85,6 +83,6 @@ class TestingBroadcasting(unittest.TestCase): def test_bi_directional_shape_broadcasting(self, input_shape, target_shape, expected_shape): result = bi_directional_shape_broadcasting(input_shape, target_shape) if expected_shape is None: - self.assertIsNone(result) + assert result is None else: - self.assertTrue(strict_compare_tensors(result, expected_shape)) + assert strict_compare_tensors(result, expected_shape) diff --git a/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py b/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py index 4c846bfe4e5..5fec0f6d0b4 100644 --- a/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py +++ b/tools/mo/unit_tests/mo/utils/ir_reader/layer_to_class_test.py @@ -1,10 +1,9 @@ # Copyright (C) 2018-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -import unittest +import pytest import numpy as np -from generator import generator, generate import openvino.tools.mo.graph.graph from openvino.tools.mo.graph.graph import Node @@ -17,9 +16,8 @@ from unit_tests.utils.graph import connect_data,shaped_parameter, regular_op_wit from openvino.tools.mo.ops.op import Op -@generator -class TestFunction(unittest.TestCase): - @generate(*[([1, 32, 112, 112], [32, 1, 1, 3], [32, 1, 1, 1, 3], 32), +class TestFunction(): + @pytest.mark.parametrize("shape, weights_shape, reshape_shape, group",[([1, 32, 112, 112], [32, 1, 1, 3], [32, 1, 1, 1, 3], 32), ([1, 32, 112, 112], [32, 1, 1, 1, 3], None, 32), ]) def test_groupconv_to_conv(self, shape, weights_shape, reshape_shape, group): @@ -75,7 +73,7 @@ class TestFunction(unittest.TestCase): assert len(reshape_node.in_nodes()) == 0 and len(reshape_node.out_nodes()) == 0 (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_restore_tensor_names(self): @@ -144,7 +142,7 @@ class TestFunction(unittest.TestCase): # Check that graph wasn't changed after shape infer (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_squeeze_no_axes(self): nodes_attributes = { @@ -172,7 +170,7 @@ class TestFunction(unittest.TestCase): # Check that graph wasn't changed after shape infer (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp def test_unsqueeze(self): nodes_attributes = { @@ -205,4 +203,4 @@ class TestFunction(unittest.TestCase): # Check that graph wasn't changed after shape infer (flag, resp) = compare_graphs(graph, graph_ref, 'result', check_op_attrs=True) - self.assertTrue(flag, resp) + assert flag, resp