Skip to content

Commit

Permalink
Remove test-generator dependency (openvinotoolkit#18512)
Browse files Browse the repository at this point in the history
* changed from generator to unittest

* common_test.py tested for pylint 7.96/10

* ChangeRandomUniformOutputType_test pylint 10/10

* replaced  generator functionality from compress...

* replaced generator functionality in MatMulNormal..

* replaced generator functionality in ShuffleChan...

* replaced generator functionality in import_from_mo_test.py

* replaced generator functionality in meta_data_test.py

* replaced generator functionality in extractor_test.py

* replaced generator functionality in interpolate_reshape_test.py

* replaced generator functionality in Pack_test.py

* replaced generator functionality in rank_decomposer_test.py

* replaced generator functionality in size_replacer_test.py

* replaced generator functionality in utils_test.py

* replaced generator functionality in eltwise_test.py

* replaced generator functionality in concat_test.py

* replaced generator functionality in tdnn_component_replacer_test.py

* replaced generator functionality in MXFFTToDFT_test.py

* replaced generator functionality in activation_ext_test.py

* replaced generator functionality in AttributedSliceToSlice_test

* replaced generator functionality in squeeze_ext_test.py

* replaced generator functionality in transpose_ext_test.py

* replaced generator functionality in unsqueeze_ext_test.py

* replaced generator functionality in ObjectDetectionAPI_test.py

* replaced generator functionality in  RFFTRealImagToRFFTSplit_test.py

* replaced generator functionality in TFFFTToDFT_test.py

* replaced generator functionality in WhereDecomposition_test.py

* replaced generator functionality in graph_test.py

* replaced generator functionality in ConvertGroupedStridedSlice_test.py

* replaced generator functionality in dequantize_linear_resolver_test.py

* replaced generator functionality in FusedBatchNormTraining_test.py

* replaced generator functionality in L2NormFusing_test.py

* replaced generator functionality in PreserveRuntimeInfo_test.py

* replaced generator functionality in quantize_linear_resolver_test.py

* replaced generator functionality in UpsampleToResample_test.py

* replaced generator functionality in broadcast_test.py

* replaced generator functionality in loader_test.py

* replaced generator functionality in cast_test.py

* replaced generator functionality in Complex_test.py

* replaced generator functionality in dft_signal_size_canonicalization_test.py

* replaced generator functionality in div_value_propagation_test.py

* replaced generator functionality in einsum_test.py

* replaced generator functionality in expand_dims_test.py

* replaced generator functionality in ExtractImagePatches_test.py

* replaced generator functionality in eye_test.py

* replaced generator functionality in gatherelements_test.py

* replaced generator functionality in If_test.py

* replaced generator functionality in interpolate_test.py

* replaced generator functionality in MatMul_test.py

* replaced generator functionality in MatMul_value_propagation_test.py

* replaced generator functionality in one_hot_test.py

* replaced generator functionality in ONNXResize11_test.py

* replaced generator functionality in ReduceOps_test.py

* replaced generator functionality in reshape_test.py

* replaced generator functionality in scatter_test.py

* replaced generator functionality in slice_test.py

* replaced generator functionality in conversion_with_layout_test.py

* replaced generator functionality in conversion_incorrect_models_test.py

* replaced generator functionality in conversion_basic_models_test.py

* replaced generator functionality in split_test.py

* replaced generator functionality in squeeze_test.py

* replaced generator functionality in mo_fallback_test_actual.py

* replaced generator functionality in layer_to_class_test.py

* replaced generator functionality in ir_engine_test.py

* replaced generator functionality in mo_fallback_test_tf_fe.py

* replaced generator functionality in freeze_placeholder_test.py

* replaced generator functionality in broadcasting_test.py

* replaced generator functionality in broadcasting_test.py

* replaced generator functionality in transpose_test.py

* replaced generator functionality in custom_replacement_config_test.py

* replaced generator functionality in unsqueeze_test.py

* replaced generator functionality in upsample_test.py

* replaced generator functionality in upsample_test.py

* Removed test-generator dependency from openvino/tools/constraints.txt

* replaced generator functionality in freeze_placeholder_test.py

* replaced generator functionality in conversion_incorrect_models_test.py

* removed test-generator from requirements_dev,constraints.txt,requirements.txt

* removed import generator from CorrectPaddingsForPadAfterComplex_test.py

* adding test_generator dep..

* revert back constraints.txt

* revert back requirements_dev

* pytest:- MatMulNormalizer_test.py

* pytest:- ShuffleChannelPatternOptimization_test.py

* pytest:- import_from_mo_test.py

* generator_to_pytest interpolate_reshape_test.py

* pytest:- rank_decomposer_test.py

* pytest:- size_replacer_test.py

* pytest:- concat_test.py

* pytest:- eltwise_test.py

* pytest:- utils_test.py

* pytest:- tdnn_component_replacer_test.py

* pytest:- MXFFTToDFT_test.py

* pytest:- activation_ext_test.py

* pytest:- AttributedSliceToSlice_test.py

* pytest:- squeeze_ext_test.py

* pytest:- transpose_ext_test.py

* pytest:- unsqueeze_ext_test.py

* pytest:- ObjectDetectionAPI_test.py

* pytest:- RFFTRealImagToRFFTSplit_test.py

* pytest:- TFFFTToDFT_test.py

* pytest:- WhereDecomposition_test.py

* pytest:- graph_test.py

* pytest:- ConvertGroupedStridedSlice_test.py

* dequantize_linear_resolver_test.py

* pytest:- FusedBatchNormTraining_test.py

* pytest:- L2NormFusing_test.py

* pytest:- PreserveRuntimeInfo_test.py

* pytest:- quantize_linear_resolver_test.py

* pytest:- UpsampleToResample_test.py

* pytest:- broadcast_test.py

* pytest:- cast_test.py

* pytest:- Complex_test.py

* pytest:- dft_signal_size_canonicalization_test.py

* pytest:- div_value_propagation_test.py

* pytest:- einsum_test.py

* pytest:- expand_dims_test.py

* pytest:- ExtractImagePatches_test.py

* pytest:- eye_test.py

* pytest:- gatherelements_test.py

* pytest:- If_test.py

* pytest:- interpolate_test.py

* pytest:- MatMul_test.py

* pytest:- MatMul_value_propagation_test.py

* pytest:- one_hot_test.py

* pytest:- ONNXResize11_test.py

* pytest:- ReduceOps_test.py

* pytest:- reshape_test.py

* scatter_test.py

* pytest:- slice_test.py

* pytest:- split_test.py

* pytest:- squeeze_test.py

* pytest:- transpose_test.py

* pytest:- unsqueeze_test.py

* pytest:- upsample_test.py

* pytest:- common_test.py

* pytest:- broadcasting_test.py

* revert back ir_engine_test.py

* revertback :- custom_replacement_config_test.py

* revertback:- mo_fallback_test_actual.py

* revertback:- mo_fallback_test_tf_fe.py

* pytest:- layer_to_class_test.py

* revertback:- conversion_basic_models_test.py

* revertback:- conversion_incorrect_models_test.py

* revertback:- conversion_with_layout_test

* revertback:- constraints.txt

* revertback:- loader_test.py

* pytest:- Pack_test.py

* revertback:- freeze_placeholder_test.py

---------

Co-authored-by: Andrei Kochin <andrei.kochin@intel.com>
  • Loading branch information
2 people authored and alvoron committed Nov 6, 2023
1 parent 6ba994f commit 7f74bc2
Show file tree
Hide file tree
Showing 59 changed files with 484 additions and 586 deletions.
15 changes: 7 additions & 8 deletions tools/mo/unit_tests/mo/back/MatMulNormalizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand All @@ -19,10 +19,9 @@
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]),
Expand Down Expand Up @@ -59,9 +58,9 @@ def test_reshape_on_the_A_input(self,
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]),
Expand Down Expand Up @@ -97,7 +96,7 @@ def test_reshape_on_the_B_input(self,
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,8 +16,7 @@
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 = {
Expand Down Expand Up @@ -67,7 +64,7 @@ def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, group):

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),
Expand All @@ -77,11 +74,11 @@ def test_fusion(self, input_shape, reshape_0_pattern, order, reshape_1_pattern,
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),
Expand All @@ -91,11 +88,10 @@ def test_negative(self, input_shape, reshape_0_pattern, order, reshape_1_pattern
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 = {
Expand Down Expand Up @@ -145,7 +141,7 @@ def get_graphs(input_shape, reshape_0_pattern, order, reshape_1_pattern, block_s

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),
Expand All @@ -155,11 +151,11 @@ def test_fusion(self, input_shape, reshape_0_pattern, order, reshape_1_pattern,
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),
Expand All @@ -169,4 +165,4 @@ def test_negative(self, input_shape, reshape_0_pattern, order, reshape_1_pattern
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
8 changes: 3 additions & 5 deletions tools/mo/unit_tests/mo/convert/import_from_mo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
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
Expand Down Expand Up @@ -79,7 +77,7 @@ def create_model_ref():
])
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')}}),
Expand Down
2 changes: 0 additions & 2 deletions tools/mo/unit_tests/mo/convert/meta_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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

Expand All @@ -18,7 +17,6 @@
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__))

Expand Down
11 changes: 5 additions & 6 deletions tools/mo/unit_tests/mo/front/Pack_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -34,10 +33,10 @@
}


@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 = []
Expand Down Expand Up @@ -79,4 +78,4 @@ def test_pack_test_all(self, num_inputs: int, num_placeholders: int, axis: list)
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
20 changes: 10 additions & 10 deletions tools/mo/unit_tests/mo/front/common/partial_infer/concat_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,9 +19,9 @@
}


@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),
Expand All @@ -43,9 +42,10 @@ def test_concat_infer(self, shape1, shape2, output_shape, axis):
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),
])
Expand All @@ -65,7 +65,7 @@ def test_concat_value_infer(self, value1, value2, output_value, axis):
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,
Expand All @@ -81,7 +81,7 @@ def test_concat_infer_not_match(self):
})

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):
Expand All @@ -98,5 +98,5 @@ def test_concat_infer_no_shape(self):
})

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)
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand All @@ -24,9 +24,9 @@
}


@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), []),
Expand Down Expand Up @@ -67,8 +67,8 @@ def test_eltwise_infer(self, value1, shape1, value2, shape2, shape_infer, exp_va
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,
Expand All @@ -89,9 +89,9 @@ def test_eltwise_infer_none_val(self):
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,
Expand All @@ -107,7 +107,7 @@ def test_eltwise_infer_none_min_max(self):
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)


Expand Down
Loading

0 comments on commit 7f74bc2

Please sign in to comment.