From a1416ed68f467eb0a2e0a11f22b382d9e59ba877 Mon Sep 17 00:00:00 2001 From: Pratham Ingawale <94799826+PRATHAM-SPS@users.noreply.github.com> Date: Thu, 16 Nov 2023 21:18:41 +0530 Subject: [PATCH] pytest special test case 3 (#20313) * pytest:- freeze_placeholder_test.py * trying with classmethod --------- Co-authored-by: Przemyslaw Wysocki --- .../mo/utils/freeze_placeholder_test.py | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py b/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py index 6c9f25c86aa8b6..884e1ef7000999 100644 --- a/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py +++ b/tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py @@ -3,12 +3,11 @@ import argparse import os -import unittest +import pytest from unittest.mock import patch, Mock import numpy as np import onnx -from generator import generator, generate from onnx.helper import make_graph, make_model, make_tensor_value_info from openvino.frontend import ( @@ -61,14 +60,14 @@ def get_test_default_frontends(): return {"onnx": "new", "tf": "legacy"} -@generator -class TestMoFreezePlaceholder(unittest.TestCase): - def setUp(self): +class TestMoFreezePlaceholder(): + @classmethod + def setup_method(cls): tm.Telemetry.__init__ = Mock(return_value=None) tm.Telemetry.send_event = Mock() FrontEnd.add_extension = Mock() - self.models = {} + cls.models = {} add = onnx.helper.make_node("Add", inputs=["in1", "in2"], outputs=["add_out"]) input_tensors = [ make_tensor_value_info("in1", onnx.TensorProto.FLOAT, (2, 2)), @@ -83,7 +82,7 @@ def setUp(self): producer_name="MO tests", opset_imports=[onnx.helper.make_opsetid("", 13)], ) - self.models["test_model.onnx"] = model + cls.models["test_model.onnx"] = model input_tensors_2 = [ make_tensor_value_info("in1", onnx.TensorProto.FLOAT, (1, 1, 3)), @@ -99,7 +98,7 @@ def setUp(self): producer_name="MO tests", opset_imports=[onnx.helper.make_opsetid("", 13)], ) - self.models["test_model_2.onnx"] = model_2 + cls.models["test_model_2.onnx"] = model_2 input_tensors_3 = [ make_tensor_value_info("in1", onnx.TensorProto.INT32, (2, 3)), @@ -115,17 +114,17 @@ def setUp(self): producer_name="MO tests", opset_imports=[onnx.helper.make_opsetid("", 13)], ) - self.models["test_model_int.onnx"] = model_3 + cls.models["test_model_int.onnx"] = model_3 - for name, model in self.models.items(): + for name, model in cls.models.items(): onnx.save(model, name) - - def tearDown(self): - for name in self.models.keys(): + @classmethod + def teardown_method(cls): + for name in cls.models.keys(): os.remove(name) - @generate( - *[ + @pytest.mark.parametrize( + "input_freezing_value, use_new_fe, inputs, expected,dtype",[ ( "in1[1 4]{f32}->[1.0 2.0 3.0 4.0],in2[1 4]{f32}->[1.0 2.0 3.0 4.0]", True, @@ -157,7 +156,7 @@ def tearDown(self): ], ) def test_freeze_placeholder_with_value_onnx_fe(self, input_freezing_value, use_new_fe, inputs, expected, - dtype=None): + dtype): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() args = base_args_config(use_new_fe=use_new_fe) @@ -175,8 +174,8 @@ def test_freeze_placeholder_with_value_onnx_fe(self, input_freezing_value, use_n assert values.dtype == dtype assert np.allclose(values, expected) - @generate( - *[ + @pytest.mark.parametrize( + "input_freezing_value, use_new_fe, inputs, expected, dtype",[ ( "in1{f32}->[1.0 15.0 1.0]", True, @@ -224,7 +223,7 @@ def test_freeze_placeholder_with_value_onnx_fe(self, input_freezing_value, use_n ), ], ) - def test_freeze_placeholder_with_value_mul(self, input_freezing_value, use_new_fe, inputs, expected, dtype=None): + def test_freeze_placeholder_with_value_mul(self, input_freezing_value, use_new_fe, inputs, expected, dtype): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() args = base_args_config(use_new_fe=use_new_fe) @@ -242,8 +241,8 @@ def test_freeze_placeholder_with_value_mul(self, input_freezing_value, use_new_f assert values.dtype == dtype assert np.allclose(values, expected) - @generate( - *[ + @pytest.mark.parametrize( + "input_freezing_value, use_new_fe, inputs, expected,dtype",[ ( "in1->[1.0 15.0 1.0]", True, @@ -254,7 +253,7 @@ def test_freeze_placeholder_with_value_mul(self, input_freezing_value, use_new_f ], ) def test_value_without_type(self, input_freezing_value, use_new_fe, inputs, expected, - dtype=None): + dtype): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() args = base_args_config(use_new_fe=use_new_fe) @@ -272,8 +271,8 @@ def test_value_without_type(self, input_freezing_value, use_new_fe, inputs, expe assert values.dtype == dtype assert np.allclose(values, expected) - @generate( - *[ + @pytest.mark.parametrize( + "input_freezing_value, use_new_fe, inputs, expected,dtype",[ ( "in2->[3 2 5]", True, @@ -284,7 +283,7 @@ def test_value_without_type(self, input_freezing_value, use_new_fe, inputs, expe ], ) def test_value_without_type_int32(self, input_freezing_value, use_new_fe, inputs, expected, - dtype=None): + dtype): with patch("openvino.tools.mo.convert_impl.get_default_frontends") as default_fe: default_fe.return_value = get_test_default_frontends() args = base_args_config(use_new_fe=use_new_fe)