Skip to content

test: add unit tests for grok_python helpers#2151

Open
nuthalapativarun wants to merge 1 commit into
TEN-framework:mainfrom
nuthalapativarun:test/grok-python
Open

test: add unit tests for grok_python helpers#2151
nuthalapativarun wants to merge 1 commit into
TEN-framework:mainfrom
nuthalapativarun:test/grok-python

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Summary

  • Add 24 unit tests for grok_python helper functions: parse_sentences, is_punctuation (from helper.py) and ThinkParser (from openai.py)
  • Add conftest.py that stubs ten_runtime, ten_ai_base, openai, PIL, and requests so pure-Python tests run without a full TEN runtime installation
  • No changes to production code

What is tested

is_punctuation (3 tests)

  • English punctuation (, . ? !) correctly identified
  • Chinese punctuation (,。?!) correctly identified
  • Letters, digits, spaces are not punctuation

parse_sentences (12 tests)

  • Single complete sentence extracted correctly
  • Multiple sentences split at punctuation boundaries
  • Incomplete trailing text held in remain fragment
  • Prefix fragment prepended to next chunk content
  • Chinese punctuation splits
  • Mixed punctuation types
  • Punctuation-only tokens not emitted (no alphanumeric content)
  • Empty inputs handled safely

ThinkParser (9 tests)

  • Initial state is NORMAL
  • <think> token transitions state to THINK, returns True
  • </think> token transitions back to NORMAL, returns True
  • Plain text in NORMAL state returns False, no state change
  • Content in THINK state accumulated in think_content
  • Content in NORMAL state does not accumulate
  • process_by_reasoning_content() opens THINK on non-empty string
  • process_by_reasoning_content("") closes THINK block
  • Empty string in NORMAL state returns False

Test plan

  • python3 -m pytest ai_agents/agents/ten_packages/extension/grok_python/tests/ -v24/24 passed
  • task format — clean (no production code changes)

Add 24 tests covering parse_sentences, is_punctuation, and ThinkParser
in grok_python — functions that control sentence splitting for TTS
output and reasoning-block detection in xAI Grok streaming responses.
Tests run without a TEN runtime via conftest stubs for ten_runtime,
ten_ai_base, openai, PIL, and requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant