Reviewed-on: #14 Co-authored-by: Mathias Scheider <mathias2784@web.de>
This commit was merged in pull request #14.
This commit is contained in:
+5
-2
@@ -58,8 +58,11 @@ def test_keywords_command_success(mock_photo_logic, dummy_file):
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "Processing: " in result.stdout
|
||||
assert "Caption: A beautiful test image" in result.stdout
|
||||
assert "Tags: test, mock, image" in result.stdout
|
||||
# The result is printed as a raw dictionary string
|
||||
assert (
|
||||
"{'caption': 'A beautiful test image', 'tags': ['test', 'mock', 'image']}"
|
||||
in result.stdout
|
||||
)
|
||||
|
||||
|
||||
def test_keywords_command_file_not_found():
|
||||
|
||||
@@ -7,7 +7,7 @@ from photools3.llm_session import LlmSession
|
||||
not LlmSession(system_prompt="").is_api_reachable(), reason="API not available"
|
||||
)
|
||||
def test_llm_session(llm_session, test_photo):
|
||||
llm_session.system_prompt = "Return only JSON format: {'keywords': ['...']}"
|
||||
llm_session.system_prompt = "Return only JSON format: {'text': '...'}"
|
||||
result = llm_session.call(
|
||||
prompt="keywords for the attached picture", photos=[test_photo]
|
||||
)
|
||||
@@ -21,7 +21,7 @@ def test_llm_session_captions_and_keywords(
|
||||
llm_session_captions_and_keywords, test_photo
|
||||
):
|
||||
result = llm_session_captions_and_keywords.call(photos=[test_photo])
|
||||
assert "caption" in result
|
||||
assert "tags" in result
|
||||
assert isinstance(result["caption"], str)
|
||||
assert isinstance(result["tags"], list)
|
||||
assert result.caption
|
||||
assert result.tags
|
||||
assert isinstance(result.caption, str)
|
||||
assert isinstance(result.tags, list)
|
||||
|
||||
@@ -21,9 +21,7 @@ def test_llm_session_mocked(test_photo):
|
||||
mock_choice = MagicMock()
|
||||
mock_message = MagicMock()
|
||||
|
||||
mock_message.content = (
|
||||
'{"caption": "A beautiful sunset", "tags": ["sunset", "nature"]}'
|
||||
)
|
||||
mock_message.content = '{"text": "some text"}'
|
||||
mock_choice.message = mock_message
|
||||
mock_response.choices = [mock_choice]
|
||||
|
||||
@@ -39,11 +37,9 @@ def test_llm_session_mocked(test_photo):
|
||||
)
|
||||
|
||||
# Verify the results
|
||||
assert result["caption"] == "A beautiful sunset"
|
||||
assert "sunset" in result["tags"]
|
||||
assert "nature" in result["tags"]
|
||||
assert result.text == "some text"
|
||||
|
||||
# Verify that the mock was called
|
||||
# Verify that the mock was enough
|
||||
assert mock_client.chat.completions.create.called
|
||||
|
||||
|
||||
@@ -65,7 +61,9 @@ def test_llm_session_captions_and_keywords_mocked(test_photo):
|
||||
mock_choice = MagicMock()
|
||||
mock_message = MagicMock()
|
||||
|
||||
mock_message.content = '{"caption": "A mocked caption", "tags": ["mocked_tag"]}'
|
||||
mock_message.content = (
|
||||
'{"caption": "A mocked caption", "tags": ["architektur"]}'
|
||||
)
|
||||
mock_choice.message = mock_message
|
||||
mock_response.choices = [mock_choice]
|
||||
|
||||
@@ -81,8 +79,8 @@ def test_llm_session_captions_and_keywords_mocked(test_photo):
|
||||
result = mocked_session.call(photos=[test_photo])
|
||||
|
||||
# Verify the results
|
||||
assert result["caption"] == "A mocked caption"
|
||||
assert "mocked_tag" in result["tags"]
|
||||
assert result.caption == "A mocked caption"
|
||||
assert "architektur" in result.tags
|
||||
|
||||
# Verify that the mock was called
|
||||
assert mock_client.chat.completions.create.called
|
||||
|
||||
Reference in New Issue
Block a user