Download tests/test_chat_stream_normalize.py from HonzaH/pruvodce: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/HonzaH/pruvodce/resolve/main/tests/test_chat_stream_normalize.py
- Command line
-
hf download hf://spaces/HonzaH/pruvodce/tests/test_chat_stream_normalize.py
-
curl -L -o test_chat_stream_normalize.py https://huggingface.co/spaces/HonzaH/pruvodce/resolve/main/tests/test_chat_stream_normalize.py
1.19 kB
| import pytest | |
| from backend.api.chat_stream import normalize_and_merge | |
| def test_remove_hash_and_punctuation_and_merge_same_agent(): | |
| raw = [ | |
| {"agent": "assistant", "token": "###"}, | |
| {"agent": "assistant", "token": "Hello "}, | |
| {"agent": "assistant", "token": "."}, | |
| {"agent": "assistant", "token": "world"}, | |
| ] | |
| cleaned = normalize_and_merge(raw) | |
| assert isinstance(cleaned, list) | |
| assert cleaned == [{"agent": "assistant", "token": "Hello world"}] | |
| def test_merge_different_agents_and_preserve_spacing(): | |
| raw = [ | |
| {"agent": "assistant", "token": "Hi "}, | |
| {"agent": "planner", "token": "there "}, | |
| {"agent": "assistant", "token": "again"}, | |
| ] | |
| cleaned = normalize_and_merge(raw) | |
| assert cleaned == [ | |
| {"agent": "assistant", "token": "Hi "}, | |
| {"agent": "planner", "token": "there "}, | |
| {"agent": "assistant", "token": "again"}, | |
| ] | |
| def test_handle_plain_strings_and_whitespace_only_tokens(): | |
| raw = ["###", " Hello ", "...", "world"] | |
| cleaned = normalize_and_merge(raw) | |
| assert cleaned == [{"agent": "assistant", "token": " Hello world"}] | |