1+ # -*- coding: utf-8 -*-
12# Copyright (C) 2018-2026 Intel Corporation
23# SPDX-License-Identifier: Apache-2.0
34
1011
1112import numpy as np
1213import pytest
13- from tests .utils .helpers import (
14- create_filenames_for_ir ,
15- generate_add_model ,
16- generate_model_with_memory ,
17- generate_multi_input_model ,
18- generate_single_input_model ,
19- generate_two_input_model ,
20- )
14+ from tests .utils .helpers import (create_filenames_for_ir , generate_add_model ,
15+ generate_model_with_memory ,
16+ generate_multi_input_model ,
17+ generate_single_input_model ,
18+ generate_two_input_model )
2119
2220import openvino .opset13 as ops
23- from openvino import Core , Dimension , Layout , Model , Output , OVAny , \
24- PartialShape , Shape , Tensor , Type , get_batch , save_model , serialize , set_batch
21+ from openvino import (Core , Dimension , Layout , Model , Output , OVAny ,
22+ PartialShape , Shape , Tensor , Type , get_batch , save_model ,
23+ serialize , set_batch )
2524from openvino .op .util import Variable , VariableInfo
2625
2726
@@ -261,16 +260,16 @@ def test_model_sink_ctors():
261260
262261 # Model(list[openvino._pyopenvino.op.Result], list[ov::Output<ov::Node>],
263262 # list[openvino._pyopenvino.op.Parameter], list[openvino._pyopenvino.op.util.Variable], str = '')
264- model = Model (results = [res ], sinks = [assign .output (0 )],
265- parameters = [ input_data ], variables = [variable_1 ], name = "TestModel" )
263+ model = Model (results = [res ], sinks = [assign .output (0 )], parameters = [
264+ input_data ], variables = [variable_1 ], name = "TestModel" )
266265 model .validate_nodes_and_infer_types ()
267266 assert model .sinks [0 ].get_output_shape (0 ) == Shape ([2 , 2 ])
268267 assert sinks == [sink .get_type_name () for sink in model .get_sinks ()]
269268
270269 # Model(list[ov::Output<ov::Node>, list[ov::Output<ov::Node>],
271270 # list[openvino._pyopenvino.op.Parameter], list[openvino._pyopenvino.op.util.Variable], str = '')
272- model = Model (results = [res .output (0 )], sinks = [assign .output (0 )],
273- parameters = [ input_data ], variables = [variable_1 ], name = "TestModel" )
271+ model = Model (results = [res .output (0 )], sinks = [assign .output (0 )], parameters = [
272+ input_data ], variables = [variable_1 ], name = "TestModel" )
274273 model .validate_nodes_and_infer_types ()
275274 assert model .sinks [0 ].get_output_shape (0 ) == Shape ([2 , 2 ])
276275 assert sinks == [sink .get_type_name () for sink in model .get_sinks ()]
@@ -509,15 +508,13 @@ def check_shape(new_shape):
509508 shape10 = [1 , 1 , 1 , 1 ]
510509 with pytest .raises (TypeError ) as e :
511510 model .reshape ({model .input ().node : shape10 })
512- expected_msg = "Incorrect key type <class 'openvino._pyopenvino.op.Parameter'> to reshape a model, " \
513- "expected keys as openvino.Output, int or str."
514- assert expected_msg in str (e .value )
511+ assert "Incorrect key type <class 'openvino._pyopenvino.op.Parameter'> to reshape a model, " "expected keys as openvino.Output, int or str." in str (
512+ e .value )
515513
516514 with pytest .raises (TypeError ) as e :
517515 model .reshape ({0 : range (1 , 9 )})
518- expected_msg = "Incorrect value type <class 'range'> to reshape a model, " \
519- "expected values as openvino.PartialShape, str, list or tuple."
520- assert expected_msg in str (e .value )
516+ assert "Incorrect value type <class 'range'> to reshape a model, " "expected values as openvino.PartialShape, str, list or tuple." in str (
517+ e .value )
521518
522519
523520def test_reshape_with_python_types_for_variable ():
@@ -590,31 +587,31 @@ def check_shape(new_shape):
590587
591588 with pytest .raises (TypeError ) as e :
592589 model .reshape ({0 : shape10 }, {var_id : range (1 , 9 )})
593- assert "Incorrect value type <class 'range'> to reshape a model, " \
594- "expected values as openvino.PartialShape, str, list or tuple." in str ( e .value )
590+ assert "Incorrect value type <class 'range'> to reshape a model, " "expected values as openvino.PartialShape, str, list or tuple." in str (
591+ e .value )
595592
596593
597594@pytest .fixture
598- def multi_input_model ():
595+ def model ():
599596 return generate_multi_input_model ()
600597
601598
602- def test_reshape_list_of_shapes (multi_input_model ):
599+ def test_reshape_list_of_shapes (model ):
603600 """Multi-input: list-of-lists reshapes all inputs in order."""
604601 input_shapes = [[2 , 2 ], [1 , 3 , 224 , 244 ], [10 ]]
605602
606- multi_input_model .reshape (input_shapes )
603+ model .reshape (input_shapes )
607604
608- assert multi_input_model .input ("A" ).shape == (2 , 2 )
609- assert multi_input_model .input ("B" ).shape == (1 , 3 , 224 , 244 )
610- assert multi_input_model .input ("C" ).shape == (10 ,)
605+ assert model .input ("A" ).shape == (2 , 2 )
606+ assert model .input ("B" ).shape == (1 , 3 , 224 , 244 )
607+ assert model .input ("C" ).shape == (10 ,)
611608
612609
613- def test_reshape_list_of_shapes_wrong_size (multi_input_model ):
610+ def test_reshape_list_of_shapes_wrong_size (model ):
614611 """Providing wrong number of shapes should raise an error."""
615612 input_shapes = [[2 , 2 ], [1 , 3 , 224 , 244 ]] # Missing third input
616613 with pytest .raises (RuntimeError , match = "Number of shapes does not match" ):
617- multi_input_model .reshape (input_shapes )
614+ model .reshape (input_shapes )
618615
619616
620617def test_reshape_single_input_flat_list ():
@@ -633,22 +630,15 @@ def test_reshape_with_dynamic_dimensions():
633630 model .reshape (input_shapes )
634631
635632 assert model .input ("A" ).shape == (2 , 2 )
636-
637-
638- def test_reshape_single_input_flat_list_with_list_intervals ():
639- """Single-input flat list: ensure list-based dim intervals are treated as flat."""
640- param = ops .parameter ([1 , 3 , 224 , 224 ])
641- model = Model (ops .relu (param ), [param ])
642-
643- # Use list-based intervals (inner lists) for dimensions — should be treated
644- # as a flat shape for single-input models and parsed as PartialShape.
645- shape = [1 , 3 , [224 , 256 ], [224 , 256 ]]
646- model .reshape (shape )
647-
648- expected = PartialShape ([Dimension (1 ), Dimension (3 ), Dimension (224 , 256 ), Dimension (224 , 256 )])
649- for inp in model .inputs :
650- assert inp .partial_shape == expected
651- # single-input model: no inputs named "B", further checks not applicable
633+ b_shape = model .input ("B" ).get_partial_shape ()
634+ assert b_shape [0 ] == 1
635+ assert b_shape [1 ] == 3
636+ assert b_shape [2 ].is_dynamic
637+ assert b_shape [2 ].get_min_length () == 224
638+ assert b_shape [2 ].get_max_length () == 256
639+ assert b_shape [3 ].is_dynamic
640+ assert b_shape [3 ].get_min_length () == 224
641+ assert b_shape [3 ].get_max_length () == 256
652642
653643
654644def test_reshape_with_tuple_shapes_multi_input ():
@@ -837,20 +827,20 @@ def check_rt_info(model):
837827
838828 assert model .get_rt_info (["config" , "type_of_model" ]).astype (str ) == "classification"
839829 assert model .get_rt_info (["config" , "converter_type" ]).astype (str ) == "classification"
840- assert math .isclose (model .get_rt_info (
841- [ "config" , "model_parameters" , "threshold" ]).astype (float ), 13.23 , rel_tol = 0.0001 )
842- assert math .isclose (model .get_rt_info (
843- [ "config" , "model_parameters" , "min" ]).astype (float ), - 3.24543 , rel_tol = 0.0001 )
844- assert math .isclose (model .get_rt_info (
845- [ "config" , "model_parameters" , "max" ]).astype (float ), 3.234223 , rel_tol = 0.0001 )
830+ assert math .isclose (model .get_rt_info ([ "config" , "model_parameters" ,
831+ "threshold" ]).astype (float ), 13.23 , rel_tol = 0.0001 )
832+ assert math .isclose (model .get_rt_info ([ "config" , "model_parameters" ,
833+ "min" ]).astype (float ), - 3.24543 , rel_tol = 0.0001 )
834+ assert math .isclose (model .get_rt_info ([ "config" , "model_parameters" ,
835+ "max" ]).astype (float ), 3.234223 , rel_tol = 0.0001 )
846836 assert model .get_rt_info (["config" , "model_parameters" , "labels" , "label_tree" , "type" ]).astype (str ) == "tree"
847- assert model .get_rt_info (
848- [ "config" , "model_parameters" , "labels" , "label_tree" , "directed" ]).astype (bool ) is True
837+ assert model .get_rt_info ([ "config" , "model_parameters" , "labels" ,
838+ "label_tree" , "directed" ]).astype (bool ) is True
849839
850840 assert model .get_rt_info (["config" , "model_parameters" , "labels" , "label_tree" , "float_empty" ]).aslist () == []
851841 assert model .get_rt_info (["config" , "model_parameters" , "labels" , "label_tree" , "nodes" ]).aslist () == []
852- assert model .get_rt_info (
853- [ "config" , "model_parameters" , "labels" , "label_groups" , "ids" ]).aslist (str ) == ["sasd" , "fdfdfsdf" ]
842+ assert model .get_rt_info ([ "config" , "model_parameters" , "labels" , "label_groups" ,
843+ "ids" ]).aslist (str ) == ["sasd" , "fdfdfsdf" ]
854844 assert model .get_rt_info (["config" , "model_parameters" , "mean_values" ]).aslist (float ) == [22.3 , 33.11 , 44.0 ]
855845 assert model .get_rt_info ("enum_info_int" ).astype (int ) == 1
856846 assert model .get_rt_info ("enum_info_str" ).astype (str ) == "info_str"
0 commit comments