Files
Athena-Deck/test_api_compat.py
T

26 lines
1.4 KiB
Python

import unittest
from api_compat import normalize_chat,CompatibilityError
class CompatibilityTests(unittest.TestCase):
def test_levels_and_alias_without_mutation(self):
for value in ['none','minimal','low','medium','high','xhigh','max','ultra']:
request={'model':'any','reasoning_effort':value};body,info=normalize_chat(request)
self.assertEqual(request['reasoning_effort'],value)
self.assertEqual(body['reasoning_effort'],{'minimal':'low','max':'xhigh','ultra':'xhigh'}.get(value,value))
self.assertEqual(info['requested'],value)
def test_unset_and_null_do_not_invent_defaults(self):
for request in [{},{'reasoning_effort':None}]:
self.assertEqual(normalize_chat(request),({},{}))
def test_invalid_inputs(self):
for value in [True,1,{},[], '', 'MAX', 'x\r\ny']:
with self.assertRaises(CompatibilityError):normalize_chat({'reasoning_effort':value})
with self.assertRaises(CompatibilityError):normalize_chat({'unknown':1})
def test_template_thinking_options(self):
original={'chat_template_kwargs':{'enable_thinking':False,'preserve_thinking':True}}
body,_=normalize_chat(original)
self.assertEqual(body,original)
body['chat_template_kwargs']['enable_thinking']=True
self.assertFalse(original['chat_template_kwargs']['enable_thinking'])
for bad in [None,[],{'enable_thinking':'false'},{'template':'custom'},{'preserve_thinking':1}]:
with self.assertRaises(CompatibilityError):normalize_chat({'chat_template_kwargs':bad})