File size: 1,955 Bytes
3f3265f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 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()
|