Skip to content

Commit

Permalink
pytest special test case 3 (openvinotoolkit#20313)
Browse files Browse the repository at this point in the history
* pytest:- freeze_placeholder_test.py

* trying with classmethod

---------

Co-authored-by: Przemyslaw Wysocki <[email protected]>
  • Loading branch information
PRATHAM-SPS and p-wysocki authored Nov 16, 2023
1 parent 4cf85db commit a1416ed
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions tools/mo/unit_tests/mo/utils/freeze_placeholder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
Expand All @@ -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)),
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit a1416ed

Please sign in to comment.