Skip to content

Commit

Permalink
Skip Python frontend tests if mock_py frontend is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
nosovmik committed May 28, 2021
1 parent 70b1106 commit fee065b
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions ngraph/python/tests/test_ngraph/test_frontendmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@
# SPDX-License-Identifier: Apache-2.0

import numpy as np
from ngraph.frontend import FrontEndManager, FrontEndCapabilities, InitializationFailure
import pytest

from ngraph import PartialShape
from ngraph.frontend import FrontEndCapabilities, FrontEndManager, InitializationFailure
from ngraph.utils.types import get_element_type

from pybind_mock_frontend import get_fe_stat, get_mdl_stat, get_place_stat
mock_available = True
try:
from pybind_mock_frontend import get_fe_stat, get_mdl_stat, get_place_stat
except Exception:
print("No mock frontend available")
mock_available = False

# FrontEndManager shall be initialized and destroyed after all tests finished
# This is because destroy of FrontEndManager will unload all plugins, no objects shall exist after this
fem = FrontEndManager()

mock_needed = pytest.mark.skipif(not mock_available,
reason="mock fe is not available")


# ---------- FrontEnd tests ---------------
@mock_needed
def test_load_by_framework_caps():
frontEnds = fem.get_available_front_ends()
assert frontEnds is not None
Expand Down Expand Up @@ -43,6 +54,7 @@ def test_load_by_unknown_framework():
raise AssertionError("Unexpected exception.")


@mock_needed
def test_load_from_file():
fe = fem.load_by_framework(framework="mock_py")
assert fe is not None
Expand All @@ -52,6 +64,7 @@ def test_load_from_file():
assert "abc.bin" in stat.load_paths


@mock_needed
def test_convert_model():
fe = fem.load_by_framework(framework="mock_py")
assert fe is not None
Expand All @@ -62,6 +75,7 @@ def test_convert_model():
assert stat.convert_model == 1


@mock_needed
def test_convert_partially():
fe = fem.load_by_framework(framework="mock_py")
assert fe is not None
Expand All @@ -74,6 +88,7 @@ def test_convert_partially():
assert stat.convert == 1


@mock_needed
def test_decode_and_normalize():
fe = fem.load_by_framework(framework="mock_py")
assert fe is not None
Expand All @@ -88,12 +103,14 @@ def test_decode_and_normalize():


# --------InputModel tests-----------------
@mock_needed
def init_model():
fe = fem.load_by_framework(framework="mock_py")
model = fe.load_from_file(path="")
return model


@mock_needed
def test_model_get_inputs():
model = init_model()
for i in range(1, 10):
Expand All @@ -102,6 +119,7 @@ def test_model_get_inputs():
assert stat.get_inputs == i


@mock_needed
def test_model_get_outputs():
model = init_model()
for i in range(1, 10):
Expand All @@ -110,6 +128,7 @@ def test_model_get_outputs():
assert stat.get_outputs == i


@mock_needed
def test_model_get_place_by_tensor_name():
model = init_model()
for i in range(1, 10):
Expand All @@ -120,6 +139,7 @@ def test_model_get_place_by_tensor_name():
assert stat.lastArgString == name


@mock_needed
def test_model_get_place_by_operation_name():
model = init_model()
for i in range(1, 10):
Expand All @@ -130,6 +150,7 @@ def test_model_get_place_by_operation_name():
assert stat.lastArgString == name


@mock_needed
def test_model_get_place_by_operation_and_input_port():
model = init_model()
for i in range(1, 10):
Expand All @@ -141,6 +162,7 @@ def test_model_get_place_by_operation_and_input_port():
assert stat.lastArgInt == i * 2


@mock_needed
def test_model_get_place_by_operation_and_output_port():
model = init_model()
for i in range(1, 10):
Expand All @@ -152,6 +174,7 @@ def test_model_get_place_by_operation_and_output_port():
assert stat.lastArgInt == i * 2


@mock_needed
def test_model_set_name_for_tensor():
model = init_model()
place = model.get_place_by_tensor_name(tensorName="")
Expand All @@ -162,6 +185,7 @@ def test_model_set_name_for_tensor():
assert stat.lastArgPlace == place


@mock_needed
def test_model_add_name_for_tensor():
model = init_model()
place = model.get_place_by_tensor_name(tensorName="")
Expand All @@ -172,6 +196,7 @@ def test_model_add_name_for_tensor():
assert stat.lastArgPlace == place


@mock_needed
def test_model_set_name_for_operation():
model = init_model()
place = model.get_place_by_operation_name(operationName="")
Expand All @@ -182,6 +207,7 @@ def test_model_set_name_for_operation():
assert stat.lastArgPlace == place


@mock_needed
def test_model_free_name_for_tensor():
model = init_model()
model.free_name_for_tensor(name="2222")
Expand All @@ -190,6 +216,7 @@ def test_model_free_name_for_tensor():
assert stat.lastArgString == "2222"


@mock_needed
def test_model_free_name_for_operation():
model = init_model()
model.free_name_for_operation(name="3333")
Expand All @@ -198,6 +225,7 @@ def test_model_free_name_for_operation():
assert stat.lastArgString == "3333"


@mock_needed
def test_model_set_name_for_dimension():
model = init_model()
place = model.get_place_by_operation_name(operationName="")
Expand All @@ -209,6 +237,7 @@ def test_model_set_name_for_dimension():
assert stat.lastArgPlace == place


@mock_needed
def test_model_cut_and_add_new_input():
model = init_model()
place = model.get_place_by_operation_name("")
Expand All @@ -224,6 +253,7 @@ def test_model_cut_and_add_new_input():
assert stat.lastArgPlace == place


@mock_needed
def test_model_cut_and_add_new_output():
model = init_model()
place = model.get_place_by_operation_name("")
Expand All @@ -239,6 +269,7 @@ def test_model_cut_and_add_new_output():
assert stat.lastArgPlace == place


@mock_needed
def test_model_add_output():
model = init_model()
place = model.get_place_by_operation_name("")
Expand All @@ -249,6 +280,7 @@ def test_model_add_output():
assert stat.lastArgPlace == place


@mock_needed
def test_model_remove_output():
model = init_model()
place = model.get_place_by_operation_name("")
Expand All @@ -258,6 +290,7 @@ def test_model_remove_output():
assert stat.lastArgPlace == place


@mock_needed
def test_model_set_partial_shape():
model = init_model()
place = model.get_place_by_tensor_name(tensorName="")
Expand All @@ -269,6 +302,7 @@ def test_model_set_partial_shape():
assert stat.lastArgPartialShape == test_shape


@mock_needed
def test_model_get_partial_shape():
model = init_model()
place = model.get_place_by_tensor_name(tensorName="")
Expand All @@ -279,6 +313,7 @@ def test_model_get_partial_shape():
assert stat.lastArgPlace == place


@mock_needed
def test_model_override_all_inputs():
model = init_model()
place1 = model.get_place_by_tensor_name(tensorName="p1")
Expand All @@ -291,6 +326,7 @@ def test_model_override_all_inputs():
assert stat.lastArgInputPlaces[1] == place2


@mock_needed
def test_model_override_all_outputs():
model = init_model()
place1 = model.get_place_by_tensor_name(tensorName="p1")
Expand All @@ -303,6 +339,7 @@ def test_model_override_all_outputs():
assert stat.lastArgOutputPlaces[1] == place2


@mock_needed
def test_model_extract_subgraph():
model = init_model()
place1 = model.get_place_by_tensor_name(tensorName="p1")
Expand All @@ -320,6 +357,7 @@ def test_model_extract_subgraph():
assert stat.lastArgOutputPlaces[1] == place4


@mock_needed
def test_model_set_element_type():
model = init_model()
place = model.get_place_by_tensor_name(tensorName="")
Expand All @@ -331,34 +369,39 @@ def test_model_set_element_type():


# ----------- Place test ------------
@mock_needed
def init_place():
fe = fem.load_by_framework(framework="mock_py")
model = fe.load_from_file(path="")
place = model.get_place_by_tensor_name(tensorName="")
return model, place


@mock_needed
def test_place_is_input():
_, place = init_place()
assert place.is_input() is not None
stat = get_place_stat(place)
assert stat.is_input == 1


@mock_needed
def test_place_is_output():
_, place = init_place()
assert place.is_output() is not None
stat = get_place_stat(place)
assert stat.is_output == 1


@mock_needed
def test_place_get_names():
_, place = init_place()
assert place.get_names() is not None
stat = get_place_stat(place)
assert stat.get_names == 1


@mock_needed
def test_place_is_equal():
model, place = init_place()
place2 = model.get_place_by_tensor_name("2")
Expand All @@ -368,6 +411,7 @@ def test_place_is_equal():
assert stat.lastArgPlace == place2


@mock_needed
def test_place_is_equal_data():
model, place = init_place()
place2 = model.get_place_by_tensor_name("2")
Expand All @@ -377,6 +421,7 @@ def test_place_is_equal_data():
assert stat.lastArgPlace == place2


@mock_needed
def test_place_get_consuming_operations():
_, place = init_place()
assert place.get_consuming_operations(outputPortIndex=22) is not None
Expand All @@ -389,6 +434,7 @@ def test_place_get_consuming_operations():
assert stat.lastArgInt == -1


@mock_needed
def test_place_get_target_tensor():
_, place = init_place()
assert place.get_target_tensor(outputPortIndex=22) is not None
Expand All @@ -401,6 +447,7 @@ def test_place_get_target_tensor():
assert stat.lastArgInt == -1


@mock_needed
def test_place_get_producing_operation():
_, place = init_place()
assert place.get_producing_operation(inputPortIndex=22) is not None
Expand All @@ -413,13 +460,15 @@ def test_place_get_producing_operation():
assert stat.lastArgInt == -1


@mock_needed
def test_place_get_producing_port():
_, place = init_place()
assert place.get_producing_port() is not None
stat = get_place_stat(place)
assert stat.get_producing_port == 1


@mock_needed
def test_place_get_input_port():
_, place = init_place()
assert place.get_input_port() is not None
Expand All @@ -432,6 +481,7 @@ def test_place_get_input_port():
assert stat.lastArgInt == 22


@mock_needed
def test_place_get_input_port2():
_, place = init_place()
assert place.get_input_port(inputName="abc") is not None
Expand All @@ -446,6 +496,7 @@ def test_place_get_input_port2():
assert stat.lastArgString == "abcd"


@mock_needed
def test_place_get_output_port():
_, place = init_place()
assert place.get_output_port() is not None
Expand All @@ -458,6 +509,7 @@ def test_place_get_output_port():
assert stat.lastArgInt == 22


@mock_needed
def test_place_get_output_port2():
_, place = init_place()
assert place.get_output_port(outputName="abc") is not None
Expand All @@ -472,13 +524,15 @@ def test_place_get_output_port2():
assert stat.lastArgString == "abcd"


@mock_needed
def test_place_get_consuming_ports():
_, place = init_place()
assert place.get_consuming_ports() is not None
stat = get_place_stat(place)
assert stat.get_consuming_ports == 1


@mock_needed
def test_place_get_source_tensor():
_, place = init_place()
assert place.get_source_tensor() is not None
Expand Down

0 comments on commit fee065b

Please sign in to comment.