Skip to content

Commit 2073725

Browse files
justinchubyCopilot
andauthored
Fix merged unit and lint regressions (#484)
## Summary - update the diffusers fallback test for the current `execution_provider="default"` contract - apply the pinned Ruff formatting and RUF043 fixes reported by CI - replace invalid `MagicMock` package components in ORT GenAI tests with minimal real `onnx_ir.Model` fixtures No model behavior or test tolerances change. ## Validation - targeted repair tests: 137 passed - canonical non-integration suite: 3923 passed, 58 skipped - `lintrunner -a`: clean - pinned Ruff check/format across all tracked Python files: clean Refs #483 Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent 9b07f09 commit 2073725

4 files changed

Lines changed: 54 additions & 51 deletions

File tree

‎src/mobius/_builder_test.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def fake_build_diffusers(*args, **kwargs):
225225
"revision": "pinned-revision",
226226
"dtype": None,
227227
"load_weights": False,
228+
"execution_provider": "default",
228229
},
229230
)
230231
]

‎src/mobius/_model_package.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def __repr__(self) -> str:
5858
def __setitem__(self, name: str, model: ir.Model) -> None:
5959
"""Store a component whose ONNX graph is available for downstream tooling."""
6060
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")
61+
raise TypeError(
62+
f"ModelPackage component {name!r} must be an ir.Model with a graph"
63+
)
6264
super().__setitem__(name, model)
6365

6466
# -- Persistence -------------------------------------------------------

‎src/mobius/_model_package_test.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def test_setitem(self):
3939
assert pkg["new"] is m
4040

4141
def test_rejects_component_without_graph(self):
42-
with pytest.raises(TypeError, match="must be an ir.Model with a graph"):
42+
with pytest.raises(TypeError, match=r"must be an ir\.Model with a graph"):
4343
ModelPackage({"invalid": object()}) # type: ignore[arg-type]
4444

4545
pkg = ModelPackage()
46-
with pytest.raises(TypeError, match="must be an ir.Model with a graph"):
46+
with pytest.raises(TypeError, match=r"must be an ir\.Model with a graph"):
4747
pkg["invalid"] = object() # type: ignore[assignment]
4848

4949
def test_delitem(self):

‎src/mobius/integrations/ort_genai/auto_export_test.py‎

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from unittest import mock
1212

1313
import numpy as np
14+
import onnx_ir as ir
1415
import pytest
1516

1617
from mobius.integrations.ort_genai.auto_export import (
@@ -32,28 +33,27 @@
3233
)
3334

3435

35-
def _mock_model_with_inputs(names):
36-
"""Create a mock ir.Model whose graph.inputs have the given names."""
37-
inputs = []
38-
for n in names:
39-
inp = mock.MagicMock()
40-
inp.name = n
41-
inputs.append(inp)
42-
m = mock.MagicMock()
43-
m.graph.inputs = inputs
44-
return m
36+
def _mock_model(
37+
*, inputs: list[str] | None = None, outputs: list[str] | None = None
38+
) -> ir.Model:
39+
"""Create a minimal ir.Model for package and graph-introspection tests."""
40+
graph = ir.Graph(
41+
inputs=[ir.Value(name=name) for name in inputs or []],
42+
outputs=[ir.Value(name=name) for name in outputs or []],
43+
nodes=[],
44+
name="mock_model",
45+
)
46+
return ir.Model(graph, ir_version=10)
47+
48+
49+
def _mock_model_with_inputs(names: list[str]) -> ir.Model:
50+
"""Create a minimal ir.Model whose graph inputs have the given names."""
51+
return _mock_model(inputs=names)
4552

4653

47-
def _mock_model_with_outputs(names):
48-
"""Create a mock ir.Model whose graph.outputs have the given names."""
49-
outputs = []
50-
for n in names:
51-
out = mock.MagicMock()
52-
out.name = n
53-
outputs.append(out)
54-
m = mock.MagicMock()
55-
m.graph.outputs = outputs
56-
return m
54+
def _mock_model_with_outputs(names: list[str]) -> ir.Model:
55+
"""Create a minimal ir.Model whose graph outputs have the given names."""
56+
return _mock_model(outputs=names)
5757

5858

5959
def test_moonshine_native_runtime_is_rejected(tmp_path):
@@ -62,7 +62,7 @@ def test_moonshine_native_runtime_is_rejected(tmp_path):
6262
config = mock.MagicMock()
6363
config.model_type = "moonshine"
6464
package = ModelPackage(
65-
{"encoder": mock.MagicMock(), "decoder": mock.MagicMock()},
65+
{"encoder": _mock_model(), "decoder": _mock_model()},
6666
config=config,
6767
)
6868

@@ -93,7 +93,7 @@ class FakeConfig:
9393
max_position_embeddings: int = 128
9494

9595
return ModelPackage(
96-
{"model": mock.MagicMock()},
96+
{"model": _mock_model()},
9797
config=FakeConfig(model_type=model_type),
9898
)
9999

@@ -1053,8 +1053,8 @@ class FakeConfig:
10531053

10541054
pkg = ModelPackage(
10551055
{
1056-
"vision_encoder": mock.MagicMock(),
1057-
"decoder": mock.MagicMock(),
1056+
"vision_encoder": _mock_model(),
1057+
"decoder": _mock_model(),
10581058
},
10591059
config=FakeConfig(),
10601060
)
@@ -1093,9 +1093,9 @@ class FakeConfig:
10931093

10941094
pkg = ModelPackage(
10951095
{
1096-
"model": mock.MagicMock(),
1097-
"vision_encoder": mock.MagicMock(),
1098-
"embedding": mock.MagicMock(),
1096+
"model": _mock_model(),
1097+
"vision_encoder": _mock_model(),
1098+
"embedding": _mock_model(),
10991099
},
11001100
config=FakeConfig(),
11011101
)
@@ -1145,9 +1145,9 @@ class FakeConfig:
11451145

11461146
pkg = ModelPackage(
11471147
{
1148-
"decoder": mock.MagicMock(),
1149-
"vision_encoder": mock.MagicMock(),
1150-
"embedding": mock.MagicMock(),
1148+
"decoder": _mock_model(),
1149+
"vision_encoder": _mock_model(),
1150+
"embedding": _mock_model(),
11511151
},
11521152
config=FakeConfig(),
11531153
)
@@ -1191,9 +1191,9 @@ class FakeConfig:
11911191

11921192
pkg = ModelPackage(
11931193
{
1194-
"decoder": mock.MagicMock(),
1195-
"vision_encoder": mock.MagicMock(),
1196-
"embedding": mock.MagicMock(),
1194+
"decoder": _mock_model(),
1195+
"vision_encoder": _mock_model(),
1196+
"embedding": _mock_model(),
11971197
},
11981198
config=FakeConfig(),
11991199
)
@@ -1243,9 +1243,9 @@ class FakeConfig:
12431243

12441244
pkg = ModelPackage(
12451245
{
1246-
"model": mock.MagicMock(),
1247-
"vision": mock.MagicMock(),
1248-
"embedding": mock.MagicMock(),
1246+
"model": _mock_model(),
1247+
"vision": _mock_model(),
1248+
"embedding": _mock_model(),
12491249
},
12501250
config=FakeConfig(),
12511251
)
@@ -1303,9 +1303,9 @@ class FakeConfig:
13031303

13041304
pkg = ModelPackage(
13051305
{
1306-
"model": mock.MagicMock(),
1307-
"audio_encoder": mock.MagicMock(),
1308-
"embedding": mock.MagicMock(),
1306+
"model": _mock_model(),
1307+
"audio_encoder": _mock_model(),
1308+
"embedding": _mock_model(),
13091309
},
13101310
config=FakeConfig(),
13111311
)
@@ -1353,7 +1353,7 @@ class FakeConfig:
13531353
num_key_value_heads: int = 1
13541354
head_dim: int = 256
13551355

1356-
pkg = ModelPackage({"model": mock.MagicMock()}, config=FakeConfig())
1356+
pkg = ModelPackage({"model": _mock_model()}, config=FakeConfig())
13571357
result = write_ort_genai_config(pkg, str(tmp_path))
13581358

13591359
assert "audio_processor" not in result
@@ -1385,9 +1385,9 @@ class FakeConfig:
13851385

13861386
pkg = ModelPackage(
13871387
{
1388-
"model": mock.MagicMock(),
1389-
"audio_encoder": mock.MagicMock(),
1390-
"embedding": mock.MagicMock(),
1388+
"model": _mock_model(),
1389+
"audio_encoder": _mock_model(),
1390+
"embedding": _mock_model(),
13911391
},
13921392
config=FakeConfig(),
13931393
)
@@ -1507,7 +1507,7 @@ def test_raises_when_pkg_config_is_none(self, tmp_path):
15071507
from mobius._model_package import ModelPackage
15081508
from mobius.integrations.ort_genai.auto_export import write_ort_genai_config
15091509

1510-
pkg = ModelPackage({"model": mock.MagicMock()}, config=None)
1510+
pkg = ModelPackage({"model": _mock_model()}, config=None)
15111511
with pytest.raises(ValueError, match="config"):
15121512
write_ort_genai_config(pkg, str(tmp_path))
15131513

@@ -1547,7 +1547,7 @@ class FakeConfig:
15471547
head_dim: int = 16
15481548
max_position_embeddings: int = 128
15491549

1550-
pkg = ModelPackage({"model": mock.MagicMock()}, config=FakeConfig())
1550+
pkg = ModelPackage({"model": _mock_model()}, config=FakeConfig())
15511551
result = write_ort_genai_config(pkg, str(tmp_path), hf_model_id=None)
15521552

15531553
with open(result["genai_config"]) as f:
@@ -1868,7 +1868,7 @@ class FakeConfig:
18681868
eos_token_id: int = 2
18691869
pad_token_id: int = 0
18701870

1871-
pkg = ModelPackage({"model": mock.MagicMock()}, config=FakeConfig())
1871+
pkg = ModelPackage({"model": _mock_model()}, config=FakeConfig())
18721872
result = write_ort_genai_config(pkg, str(tmp_path), hf_model_id=None)
18731873

18741874
with open(result["genai_config"]) as f:
@@ -1898,7 +1898,7 @@ class FakeConfig:
18981898
eos_token_id: list = dataclasses.field(default_factory=lambda: [1, 106])
18991899
pad_token_id: int = 0
19001900

1901-
pkg = ModelPackage({"model": mock.MagicMock()}, config=FakeConfig())
1901+
pkg = ModelPackage({"model": _mock_model()}, config=FakeConfig())
19021902
result = write_ort_genai_config(pkg, str(tmp_path), hf_model_id=None)
19031903

19041904
with open(result["genai_config"]) as f:
@@ -2001,7 +2001,7 @@ def test_preflights_missing_config(self, tmp_path, monkeypatch):
20012001
from mobius._model_package import ModelPackage
20022002
from mobius.integrations.ort_genai.auto_export import export_package
20032003

2004-
pkg = ModelPackage({"model": mock.MagicMock()}, config=None)
2004+
pkg = ModelPackage({"model": _mock_model()}, config=None)
20052005
save_called = []
20062006

20072007
def fake_save(self, *a, **kw):

0 commit comments

Comments
 (0)