Orienter / tests /test_vlm_adapter.py
stereoid's picture
Add files using upload-large-folder tool
3f3265f verified
Raw
History Blame Contribute Delete
1.96 kB
import tempfile
import unittest
import json
from pathlib import Path
from unittest import mock
from approach.vlm.gpt4v import gpt4v
class VlmAdapterTests(unittest.TestCase):
def test_app_metadata_cache_fails_on_missing_app_id(self):
with tempfile.TemporaryDirectory() as tmpdir:
cache_path = Path(tmpdir) / "apps.json"
cache_path.write_text(json.dumps({"123": {"app_name": "App", "app_description": "Desc"}}))
cache = gpt4v.load_app_metadata_cache(cache_path)
self.assertEqual(gpt4v.get_steam_app_data("123", "123_4.jpg", cache), ("App", "Desc"))
with self.assertRaises(KeyError):
gpt4v.get_steam_app_data("456", "456_1.jpg", cache)
def test_process_image_uses_selected_openrouter_profile_and_real_mime_type(self):
client = mock.Mock()
client.complete_json.return_value = {"objects": {"button": "round red"}}
with tempfile.TemporaryDirectory() as tmpdir:
image_path = Path(tmpdir) / "123_4.png"
image_path.write_bytes(b"not-decoded-by-the-adapter")
with mock.patch.object(
gpt4v,
"get_steam_app_data",
return_value=("Test App", "Test description"),
), mock.patch.object(
gpt4v,
"OpenAICompatibleChatClient",
return_value=client,
) as client_class:
result = gpt4v.process_image(
"default",
"describe",
str(image_path),
False,
0,
)
self.assertEqual(result["objects"]["button"], "round red")
self.assertEqual(client_class.call_args.args[0].provider, "openrouter")
encoded_image = client.complete_json.call_args.args[1][0]
self.assertEqual(encoded_image.media_type, "image/png")
if __name__ == "__main__":
unittest.main()