Add tests for `extract_content_string` error handling in `cli/main.py`

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-03-21 14:53:45 +00:00
parent 5799bb3f00
commit 811459b38f
1 changed files with 27 additions and 0 deletions

27
tests/cli/test_main.py Normal file
View File

@ -0,0 +1,27 @@
import pytest
from cli.main import extract_content_string
def test_extract_content_string_empty():
assert extract_content_string(None) is None
assert extract_content_string("") is None
assert extract_content_string(" ") is None
def test_extract_content_string_valid_eval():
assert extract_content_string("[]") is None
assert extract_content_string("{}") is None
assert extract_content_string('""') is None
def test_extract_content_string_invalid_eval_valueerror():
# simulating ValueError in literal_eval
assert extract_content_string("not_a_valid_python_literal") == "not_a_valid_python_literal"
def test_extract_content_string_invalid_eval_syntaxerror():
# simulating SyntaxError in literal_eval
assert extract_content_string("{[}") == "{[}"
def test_extract_content_string_dict():
assert extract_content_string({"text": "hello"}) == "hello"
assert extract_content_string({"text": " "}) is None
def test_extract_content_string_list():
assert extract_content_string([{"type": "text", "text": "hello"}, " world"]) == "hello world"