You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import json
import httpx
from app . llm . ollama import OllamaProvider
def test_ollama_classify_mock ( monkeypatch ) :
fake = {
" message " : {
" content " : json . dumps (
{
" type " : " task " ,
" sphere " : " life " ,
" project_id " : " life-trip " ,
" proj_label " : " 개인 › 여행 — 한국 " ,
" tone " : " coral " ,
" due_text " : " ~6/14 " ,
" when_text " : " 오늘 저녁 " ,
" extra " : " 가격 추적 " ,
" reason " : " 구매 행동이라 작업입니다. " ,
" confidence " : 0.9 ,
}
)
}
}
class R :
status_code = 200
def raise_for_status ( self ) :
pass
def json ( self ) :
return fake
monkeypatch . setattr ( httpx , " post " , lambda * a , * * k : R ( ) )
c = OllamaProvider ( ) . classify_capture ( " 비행기 티켓 사기 " , { " projects " : [ ] } )
assert c . type == " task " and c . sphere == " life "
assert c . model . startswith ( " ollama: " )
def test_ollama_fallback_on_error ( monkeypatch ) :
def boom ( * a , * * k ) :
raise httpx . ConnectError ( " no ollama " )
monkeypatch . setattr ( httpx , " post " , boom )
c = OllamaProvider ( ) . classify_capture ( " 수요일 11시 자전거 수리 " , { " projects " : [ ] } )
assert c . model == " heuristic " # 폴백 동작