Files
kserve/python/autogluonserver/tests/test_predictor_factory.py
0cc7b33d97 feat: add AutoGluon Server for KServe (#5269)
Signed-off-by: ZabinskiMichal <[email protected]>
Signed-off-by: Michał Żabiński <[email protected]>
Signed-off-by: Spolti <[email protected]>
Co-authored-by: Spolti <[email protected]>
2026-06-18 17:06:51 -04:00

94 lines
3.1 KiB
Python

# Copyright 2026 The KServe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from unittest.mock import MagicMock
from autogluonserver.predictor_factory import (
AutoGluonDetectedModel,
create_autogluon_model,
)
from autogluonserver.tabular_model import AutoGluonTabularModel
from autogluonserver.timeseries_model import AutoGluonTimeSeriesModel
def test_factory_returns_detected_model(tmp_path):
m = create_autogluon_model("n", str(tmp_path))
assert isinstance(m, AutoGluonDetectedModel)
def test_load_delegates_to_tabular(monkeypatch, tmp_path):
fake = MagicMock()
monkeypatch.setattr(
"autogluonserver.predictor_factory.detect_and_load_predictor",
lambda _: ("tabular", fake),
)
monkeypatch.setattr(
"autogluonserver.predictor_factory.Storage.download", lambda _: str(tmp_path)
)
m = create_autogluon_model("n", str(tmp_path))
assert m.load()
assert isinstance(m._impl, AutoGluonTabularModel)
assert m._impl._predictor is fake
def test_load_delegates_to_timeseries_without_metadata_json(monkeypatch, tmp_path):
fake = MagicMock()
fake.target = "y"
fake.prediction_length = 1
fake.known_covariates_names = []
monkeypatch.setattr(
"autogluonserver.predictor_factory.detect_and_load_predictor",
lambda _: ("timeseries", fake),
)
monkeypatch.setattr(
"autogluonserver.predictor_factory.Storage.download", lambda _: str(tmp_path)
)
m = create_autogluon_model("n", str(tmp_path))
assert m.load()
assert isinstance(m._impl, AutoGluonTimeSeriesModel)
assert m._impl._predictor is fake
assert m._impl._metadata.target == "y"
assert m._impl._metadata.id_column == "item_id"
assert m._impl._metadata.timestamp_column == "timestamp"
def test_load_delegates_to_timeseries(monkeypatch, tmp_path):
fake = MagicMock()
fake.target = "y"
fake.prediction_length = 1
fake.known_covariates_names = []
(tmp_path / "predictor_metadata.json").write_text(
json.dumps(
{
"target": "y",
"id_column": "item_id",
"timestamp_column": "timestamp",
}
),
encoding="utf-8",
)
monkeypatch.setattr(
"autogluonserver.predictor_factory.detect_and_load_predictor",
lambda _: ("timeseries", fake),
)
monkeypatch.setattr(
"autogluonserver.predictor_factory.Storage.download", lambda _: str(tmp_path)
)
m = create_autogluon_model("n", str(tmp_path))
assert m.load()
assert isinstance(m._impl, AutoGluonTimeSeriesModel)
assert m._impl._predictor is fake
assert m._impl._metadata.target == "y"