reorganization
This commit is contained in:
@@ -20,6 +20,7 @@ def inspect_onnx_metadata(path: str | Path) -> dict[str, Any]:
|
||||
|
||||
try:
|
||||
model = onnx.load(str(path))
|
||||
onnx.checker.check_model(model)
|
||||
except Exception as exc:
|
||||
raise ValueError(f"no es un modelo ONNX válido: {exc}") from exc
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import onnx
|
||||
import onnx.helper
|
||||
import pytest
|
||||
|
||||
from models.export import inspect_onnx_metadata
|
||||
|
||||
@@ -25,6 +26,21 @@ def test_inspect_onnx_metadata_reads_producer_and_io(tmp_path):
|
||||
assert metadata["graph_outputs"] == ["y"]
|
||||
|
||||
|
||||
def test_inspect_onnx_metadata_rejects_structurally_invalid_model(tmp_path):
|
||||
"""A protobuf-valid but structurally broken graph (a node reading an
|
||||
input the graph never declares) must be rejected: `onnx.load` alone
|
||||
only parses the protobuf and would let this through."""
|
||||
node = onnx.helper.make_node("Identity", ["undeclared_input"], ["y"])
|
||||
y = onnx.helper.make_tensor_value_info("y", onnx.TensorProto.FLOAT, [1])
|
||||
graph = onnx.helper.make_graph([node], "broken", [], [y])
|
||||
model = onnx.helper.make_model(graph, producer_name="pytest-fixture")
|
||||
path = tmp_path / "model.onnx"
|
||||
path.write_bytes(model.SerializeToString())
|
||||
|
||||
with pytest.raises(ValueError, match="no es un modelo ONNX válido"):
|
||||
inspect_onnx_metadata(path)
|
||||
|
||||
|
||||
def test_inspect_onnx_metadata_without_onnx_available(monkeypatch, tmp_path):
|
||||
import builtins
|
||||
|
||||
|
||||
Reference in New Issue
Block a user