MCPcopy Create free account
hub / github.com/FocoosAI/focoos / test_load_runtime

Function test_load_runtime

tests/test_runtime.py:117–162  ·  view source on GitHub ↗
(mocker: MockerFixture, tmp_path, runtime_type, expected_opts)

Source from the content-addressed store, hash-verified

115 ],
116)
117def test_load_runtime(mocker: MockerFixture, tmp_path, runtime_type, expected_opts):
118 # mock model path
119 model_path = pathlib.Path(tmp_path) / "fakeref" / "model.onnx"
120 model_path.parent.mkdir(parents=True, exist_ok=True)
121 model_path.touch()
122 model_path = model_path.as_posix()
123
124 # mock model metadata
125 mock_model_metadata = MagicMock(spec=ModelInfo)
126
127 # mock opts
128 if runtime_type == RuntimeType.TORCHSCRIPT_32:
129 mocker.patch("focoos.infer.runtimes.load_runtime.TORCH_AVAILABLE", True)
130 mock_runtime_class = mocker.patch("focoos.infer.runtimes.torchscript.TorchscriptRuntime", autospec=True)
131 mock_runtime_class.return_value = MagicMock(spec=TorchscriptRuntime, opts=expected_opts)
132 else:
133 mocker.patch("focoos.infer.runtimes.load_runtime.ORT_AVAILABLE", True)
134 mock_runtime_class = mocker.patch("focoos.infer.runtimes.onnx.ONNXRuntime", autospec=True)
135 mock_runtime_class.return_value = MagicMock(spec=ONNXRuntime, opts=expected_opts)
136
137 # warmup_iter
138 warmup_iter = 2
139
140 # call the function to test
141 runtime = load_runtime(
142 runtime_type=runtime_type,
143 model_path=model_path,
144 model_info=mock_model_metadata,
145 warmup_iter=warmup_iter,
146 )
147
148 # assertions
149 assert runtime is not None
150 if runtime_type == RuntimeType.TORCHSCRIPT_32:
151 mock_runtime_class.assert_called_once_with(
152 model_path=model_path,
153 opts=expected_opts,
154 model_info=mock_model_metadata,
155 device="auto",
156 )
157 else:
158 mock_runtime_class.assert_called_once_with(
159 model_path,
160 expected_opts,
161 mock_model_metadata,
162 )
163
164
165def test_load_unavailable_runtime(mocker: MockerFixture):

Callers

nothing calls this directly

Calls 2

load_runtimeFunction · 0.90
patchMethod · 0.80

Tested by

no test coverage detected