Skip to content

Commit f5c5a3b

Browse files
committed
fix
1 parent 31bb577 commit f5c5a3b

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/bindings/python/tests/test_runtime/test_core.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
PartialShape,
1616
CompiledModel,
1717
tensor_from_file,
18-
read_tensor_data,
1918
compile_model,
2019
serialize,
2120
)
@@ -176,28 +175,6 @@ def test_read_model_from_tensor(request, tmp_path):
176175
assert isinstance(model, Model)
177176

178177

179-
def test_read_tensor_data_defaults_and_args(tmp_path):
180-
data = np.arange(16, dtype=np.uint8)
181-
bin_path = tmp_path / "tensor.bin"
182-
data.tofile(bin_path)
183-
184-
tensor = read_tensor_data(bin_path)
185-
assert isinstance(tensor, Tensor)
186-
assert tensor.get_element_type() == Tensor(data).get_element_type()
187-
assert tensor.get_shape() == [data.size]
188-
assert np.array_equal(tensor.data, data)
189-
190-
tensor_offset = read_tensor_data(
191-
bin_path,
192-
element_type=Tensor(data).get_element_type(),
193-
shape=PartialShape.dynamic(1),
194-
offset_in_bytes=4,
195-
mmap=False,
196-
)
197-
assert tensor_offset.get_shape() == [data.size - 4]
198-
assert np.array_equal(tensor_offset.data, data[4:])
199-
200-
201178
def test_read_model_with_wrong_input():
202179
core = Core()
203180
with pytest.raises(TypeError) as e:

src/bindings/python/tests/test_runtime/test_read_tensor_data.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ def test_read_tensor_data_too_big_offset_throws(tmp_path: Path, mmap: bool) -> N
9595
file_size = path.stat().st_size
9696
assert file_size == data.nbytes
9797

98-
# offset + data_size > file_size
9998
with pytest.raises(RuntimeError):
100-
ov.read_tensor_data(path, element_type=ov.Type.f32, shape=ov.PartialShape(list(shape)), offset_in_bytes=1, mmap=mmap)
101-
# offset == file_size
99+
ov.read_tensor_data(
100+
path,
101+
element_type=ov.Type.f32,
102+
shape=ov.PartialShape(list(shape)),
103+
offset_in_bytes=1,
104+
mmap=mmap)
105+
102106
with pytest.raises(RuntimeError):
103107
ov.read_tensor_data(
104108
path,
@@ -107,7 +111,7 @@ def test_read_tensor_data_too_big_offset_throws(tmp_path: Path, mmap: bool) -> N
107111
offset_in_bytes=file_size,
108112
mmap=mmap,
109113
)
110-
# offset > file_size
114+
111115
with pytest.raises(RuntimeError):
112116
ov.read_tensor_data(
113117
path,
@@ -118,6 +122,22 @@ def test_read_tensor_data_too_big_offset_throws(tmp_path: Path, mmap: bool) -> N
118122
)
119123

120124

125+
def test_read_tensor_data_default_all_args(tmp_path: Path) -> None:
126+
"""Test main use case: only path specified, all other args use defaults."""
127+
data = np.arange(24, dtype=np.uint8)
128+
path = tmp_path / "tensor.bin"
129+
data.tofile(path)
130+
131+
# Main use case - only specify path
132+
tensor = ov.read_tensor_data(path)
133+
134+
assert isinstance(tensor, ov.Tensor)
135+
assert tensor.get_element_type() == ov.Type.u8 # default element type
136+
assert tensor.get_shape() == [data.size] # dynamic shape inferred from file
137+
assert not tensor.data.flags.writeable # read-only
138+
assert np.array_equal(tensor.data, data)
139+
140+
121141
@pytest.mark.parametrize("mmap", [True, False])
122142
def test_read_tensor_data_dynamic_shape(tmp_path: Path, mmap: bool) -> None:
123143
shape = (1, 2, 3, 4)

0 commit comments

Comments
 (0)