mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-05-04 22:30:38 +00:00
Phase 7: Directory restructuring (messaging/ and tests/)
- Create messaging/platforms/ (base, discord, telegram, factory) - Create messaging/rendering/ (discord_markdown, telegram_markdown) - Create messaging/trees/ (data, repository, processor, queue_manager) - Organize tests/ into api/, providers/, messaging/, cli/, config/ - Add backward-compatible re-exports at old locations - Update handler.py and test_messaging_factory.py imports - Fix Telegram type hints for TELEGRAM_AVAILABLE=False case - Fix Python 3 except syntax in discord_markdown Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
This commit is contained in:
parent
38a7980546
commit
4b4f87515d
76 changed files with 3294 additions and 3124 deletions
|
|
@ -1,108 +0,0 @@
|
|||
"""Tests for extract_text_from_content helper functions."""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from utils.text import extract_text_from_content
|
||||
|
||||
|
||||
class TestExtractTextFromContent:
|
||||
"""Tests for utils.text.extract_text_from_content."""
|
||||
|
||||
def test_string_content(self):
|
||||
"""Return string content as-is."""
|
||||
assert extract_text_from_content("hello world") == "hello world"
|
||||
|
||||
def test_empty_string(self):
|
||||
"""Return empty string for empty string input."""
|
||||
assert extract_text_from_content("") == ""
|
||||
|
||||
def test_list_single_block(self):
|
||||
"""Extract text from a single content block."""
|
||||
block = MagicMock()
|
||||
block.text = "some text"
|
||||
assert extract_text_from_content([block]) == "some text"
|
||||
|
||||
def test_list_multiple_blocks(self):
|
||||
"""Concatenate text from multiple content blocks."""
|
||||
b1 = MagicMock()
|
||||
b1.text = "hello "
|
||||
b2 = MagicMock()
|
||||
b2.text = "world"
|
||||
assert extract_text_from_content([b1, b2]) == "hello world"
|
||||
|
||||
def test_list_with_non_text_block(self):
|
||||
"""Skip blocks without text attribute."""
|
||||
b1 = MagicMock()
|
||||
b1.text = "hello"
|
||||
b2 = MagicMock(spec=[]) # No attributes
|
||||
assert extract_text_from_content([b1, b2]) == "hello"
|
||||
|
||||
def test_list_with_empty_text(self):
|
||||
"""Skip blocks with empty text."""
|
||||
b1 = MagicMock()
|
||||
b1.text = ""
|
||||
b2 = MagicMock()
|
||||
b2.text = "world"
|
||||
assert extract_text_from_content([b1, b2]) == "world"
|
||||
|
||||
def test_list_with_none_text(self):
|
||||
"""Skip blocks with None text."""
|
||||
b1 = MagicMock()
|
||||
b1.text = None
|
||||
b2 = MagicMock()
|
||||
b2.text = "world"
|
||||
assert extract_text_from_content([b1, b2]) == "world"
|
||||
|
||||
def test_empty_list(self):
|
||||
"""Return empty string for empty list."""
|
||||
assert extract_text_from_content([]) == ""
|
||||
|
||||
def test_non_string_non_list(self):
|
||||
"""Return empty string for unexpected types."""
|
||||
assert extract_text_from_content(None) == ""
|
||||
assert extract_text_from_content(42) == ""
|
||||
|
||||
def test_list_with_non_string_text_attr(self):
|
||||
"""Skip blocks where text is not a string."""
|
||||
b1 = MagicMock()
|
||||
b1.text = 123 # Not a string
|
||||
b2 = MagicMock()
|
||||
b2.text = "valid"
|
||||
assert extract_text_from_content([b1, b2]) == "valid"
|
||||
|
||||
|
||||
# --- Parametrized Edge Case Tests ---
|
||||
|
||||
|
||||
def _make_block(text_val):
|
||||
b = MagicMock()
|
||||
b.text = text_val
|
||||
return b
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"content,expected",
|
||||
[
|
||||
("hello world", "hello world"),
|
||||
("", ""),
|
||||
(None, ""),
|
||||
(42, ""),
|
||||
([], ""),
|
||||
(" ", " "),
|
||||
],
|
||||
ids=["string", "empty_str", "none", "int", "empty_list", "whitespace_only"],
|
||||
)
|
||||
def test_extract_text_scalar_and_empty_parametrized(content, expected):
|
||||
"""Parametrized scalar and empty input handling."""
|
||||
assert extract_text_from_content(content) == expected
|
||||
|
||||
|
||||
def test_extract_functions_whitespace_only():
|
||||
"""extract_text_from_content handles whitespace-only string."""
|
||||
assert extract_text_from_content(" ") == " "
|
||||
|
||||
|
||||
def test_extract_functions_unicode():
|
||||
"""extract_text_from_content handles unicode content."""
|
||||
assert extract_text_from_content("日本語テスト") == "日本語テスト"
|
||||
Loading…
Add table
Add a link
Reference in a new issue