File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ def __repr__(self) -> str:
5555 names = ", " .join (repr (k ) for k in self .data )
5656 return f"ModelPackage({{{ names } }})"
5757
58+ def __setitem__ (self , name : str , model : ir .Model ) -> None :
59+ """Store a component whose ONNX graph is available for downstream tooling."""
60+ if not isinstance (model , ir .Model ) or model .graph is None :
61+ raise TypeError (f"ModelPackage component { name !r} must be an ir.Model with a graph" )
62+ super ().__setitem__ (name , model )
63+
5864 # -- Persistence -------------------------------------------------------
5965
6066 def save (
Original file line number Diff line number Diff line change 88import logging
99
1010import onnx_ir as ir
11+ import pytest
1112import torch
1213
1314from mobius ._builder import build_from_module
@@ -37,6 +38,14 @@ def test_setitem(self):
3738 pkg ["new" ] = m
3839 assert pkg ["new" ] is m
3940
41+ def test_rejects_component_without_graph (self ):
42+ with pytest .raises (TypeError , match = "must be an ir.Model with a graph" ):
43+ ModelPackage ({"invalid" : object ()}) # type: ignore[arg-type]
44+
45+ pkg = ModelPackage ()
46+ with pytest .raises (TypeError , match = "must be an ir.Model with a graph" ):
47+ pkg ["invalid" ] = object () # type: ignore[assignment]
48+
4049 def test_delitem (self ):
4150 pkg = ModelPackage ({"a" : _make_simple_model ()})
4251 del pkg ["a" ]
@@ -99,6 +108,7 @@ def test_roundtrip(self, tmp_path):
99108
100109 assert len (loaded ) == 1
101110 assert "model" in loaded
111+ assert pkg ["model" ].graph is not None
102112 assert loaded ["model" ].graph .num_nodes () == pkg ["model" ].graph .num_nodes ()
103113
104114 def test_load_multiple (self , tmp_path ):
You can’t perform that action at this time.
0 commit comments