Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
18 lines
673 B
Python
18 lines
673 B
Python
import sys, os
|
|
from unittest.mock import MagicMock
|
|
|
|
sys.path.insert(0, os.path.abspath("chapter8/MultilingualReasoning"))
|
|
from gpt_oss_20b_sft import format_chat_template
|
|
|
|
|
|
def test_format_chat_template_handles_non_list_messages():
|
|
mock_tokenizer = MagicMock()
|
|
mock_tokenizer.apply_chat_template.return_value = "formatted text"
|
|
|
|
# Example with missing / non-list messages
|
|
example = {"messages": None}
|
|
res = format_chat_template(example, mock_tokenizer)
|
|
assert res["text"] == "formatted text"
|
|
# apply_chat_template should receive [] when messages is None/invalid
|
|
mock_tokenizer.apply_chat_template.assert_called_once_with([], tokenize=False)
|