From 811459b38f708a4d35e4f4fed454441e87bbf87d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 21 Mar 2026 14:53:45 +0000 Subject: [PATCH] Add tests for `extract_content_string` error handling in `cli/main.py` Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com> --- tests/cli/test_main.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/cli/test_main.py diff --git a/tests/cli/test_main.py b/tests/cli/test_main.py new file mode 100644 index 00000000..dfe8fe01 --- /dev/null +++ b/tests/cli/test_main.py @@ -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"