mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00
test: fix test_list_models_with_direct_resource_patch to mock correct resource loading
This commit is contained in:
parent
899972e22f
commit
a6cbaad5a2
1 changed files with 19 additions and 9 deletions
|
@ -1164,16 +1164,26 @@ class TestMain(TestCase):
|
||||||
def test_list_models_with_direct_resource_patch(self):
|
def test_list_models_with_direct_resource_patch(self):
|
||||||
# Test that models from resources/model-metadata.json are included in list-models output
|
# Test that models from resources/model-metadata.json are included in list-models output
|
||||||
with GitTemporaryDirectory():
|
with GitTemporaryDirectory():
|
||||||
# Mock the importlib.resources.open_text to return a custom model-metadata.json
|
# Create a temporary file with test model metadata
|
||||||
|
test_file = Path(self.tempdir) / "test-model-metadata.json"
|
||||||
test_resource_models = {
|
test_resource_models = {
|
||||||
"special-model": {"max_input_tokens": 8192, "litellm_provider": "resource-provider"}
|
"special-model": {
|
||||||
|
"max_input_tokens": 8192,
|
||||||
|
"litellm_provider": "resource-provider",
|
||||||
|
"mode": "chat"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
test_file.write_text(json.dumps(test_resource_models))
|
||||||
|
|
||||||
mock_file = MagicMock()
|
# Create a mock for the resource file path
|
||||||
mock_file.read.return_value = json.dumps(test_resource_models)
|
mock_resource_path = MagicMock()
|
||||||
mock_file.__enter__.return_value = mock_file
|
mock_resource_path.__str__.return_value = str(test_file)
|
||||||
|
|
||||||
with patch("importlib.resources.open_text", return_value=mock_file):
|
# Create a mock for the files function that returns an object with joinpath
|
||||||
|
mock_files = MagicMock()
|
||||||
|
mock_files.joinpath.return_value = mock_resource_path
|
||||||
|
|
||||||
|
with patch("aider.main.importlib_resources.files", return_value=mock_files):
|
||||||
# Capture stdout to check the output
|
# Capture stdout to check the output
|
||||||
with patch("sys.stdout", new_callable=StringIO) as mock_stdout:
|
with patch("sys.stdout", new_callable=StringIO) as mock_stdout:
|
||||||
main(
|
main(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue