fix(test): correct mock target for fetch_api_models in custom provider tests

fetch_api_models is imported locally inside _model_flow_named_custom from
hermes_cli.models, not defined as a module-level attribute of hermes_cli.main.
Patch the source module so the local import picks up the mock.

Also force simple_term_menu ImportError so tests reliably use the input()
fallback path regardless of environment.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
r266-tech
2026-04-10 09:16:16 +08:00
committed by Teknium
parent e3b395e17d
commit 1662b7f82a

View File

@@ -45,7 +45,8 @@ class TestCustomProviderModelSwitch:
"model": "model-A", # already saved
}
with patch("hermes_cli.main.fetch_api_models", return_value=["model-A", "model-B"]) as mock_fetch, \
with patch("hermes_cli.models.fetch_api_models", return_value=["model-A", "model-B"]) as mock_fetch, \
patch.dict("sys.modules", {"simple_term_menu": None}), \
patch("builtins.input", return_value="2"), \
patch("builtins.print"):
_model_flow_named_custom({}, provider_info)
@@ -65,7 +66,8 @@ class TestCustomProviderModelSwitch:
"model": "model-A",
}
with patch("hermes_cli.main.fetch_api_models", return_value=["model-A", "model-B"]), \
with patch("hermes_cli.models.fetch_api_models", return_value=["model-A", "model-B"]), \
patch.dict("sys.modules", {"simple_term_menu": None}), \
patch("builtins.input", return_value="2"), \
patch("builtins.print"):
_model_flow_named_custom({}, provider_info)
@@ -88,7 +90,7 @@ class TestCustomProviderModelSwitch:
}
# fetch returns empty list (probe failed), user presses Enter (empty input)
with patch("hermes_cli.main.fetch_api_models", return_value=[]), \
with patch("hermes_cli.models.fetch_api_models", return_value=[]), \
patch("builtins.input", return_value=""), \
patch("builtins.print"):
_model_flow_named_custom({}, provider_info)
@@ -110,7 +112,8 @@ class TestCustomProviderModelSwitch:
# no "model" key
}
with patch("hermes_cli.main.fetch_api_models", return_value=["model-X"]), \
with patch("hermes_cli.models.fetch_api_models", return_value=["model-X"]), \
patch.dict("sys.modules", {"simple_term_menu": None}), \
patch("builtins.input", return_value="1"), \
patch("builtins.print"):
_model_flow_named_custom({}, provider_info)