Refacto du code coté Python, java et coté angular afin de mieux séparer les responsabilité et d'avoir moins de répétitivité dans le code.
Some checks failed
E2E Tests / e2e (push) Waiting to run
Tests unitaires / Web (Angular · vitest + couverture) (push) Successful in 26s
Build & Push Images / tests (push) Failing after 13s
Build & Push Images / build (brain) (push) Has been skipped
Build & Push Images / build (core) (push) Has been skipped
Build & Push Images / build (web) (push) Has been skipped
Build & Push Images / build-switcher (push) Has been skipped
Tests unitaires / Brain (Python · pytest + couverture) (push) Successful in 1m12s
Tests unitaires / Core (Java · mvn test + JaCoCo) (push) Failing after 1m28s
Some checks failed
E2E Tests / e2e (push) Waiting to run
Tests unitaires / Web (Angular · vitest + couverture) (push) Successful in 26s
Build & Push Images / tests (push) Failing after 13s
Build & Push Images / build (brain) (push) Has been skipped
Build & Push Images / build (core) (push) Has been skipped
Build & Push Images / build (web) (push) Has been skipped
Build & Push Images / build-switcher (push) Has been skipped
Tests unitaires / Brain (Python · pytest + couverture) (push) Successful in 1m12s
Tests unitaires / Core (Java · mvn test + JaCoCo) (push) Failing after 1m28s
Mise en place de tests unitaires coté Python et Angular Mise en place de la couverture de test directement dans le workflow : le programme ne build pas si jamais un test échoue Passage en v0.16.2 en conséquence
This commit is contained in:
65
brain/tests/test_generate_page.py
Normal file
65
brain/tests/test_generate_page.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""Tests du use case de génération de page (app.application.generate_page)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.application.generate_page import GeneratePageUseCase
|
||||
from app.domain.models import PageGenerationContext
|
||||
from app.domain.ports import LLMProviderError
|
||||
|
||||
_CTX = PageGenerationContext(
|
||||
lore_name="Eldoria",
|
||||
folder_name="PNJ",
|
||||
template_name="Personnage",
|
||||
template_fields=["apparence", "histoire"],
|
||||
page_title="Aragorn",
|
||||
lore_description="un monde sombre",
|
||||
)
|
||||
|
||||
|
||||
def test_build_prompt_includes_context_and_fields():
|
||||
p = GeneratePageUseCase._build_prompt(_CTX, "fr")
|
||||
assert "Eldoria" in p
|
||||
assert "Aragorn" in p
|
||||
assert '"apparence"' in p
|
||||
assert "un monde sombre" in p
|
||||
|
||||
|
||||
def test_build_prompt_omits_lore_description_when_absent():
|
||||
ctx = PageGenerationContext("L", "F", "T", ["a"], "Titre", None)
|
||||
assert "Description de l'univers" not in GeneratePageUseCase._build_prompt(ctx)
|
||||
|
||||
|
||||
def test_parse_values_keeps_only_expected_fields():
|
||||
out = GeneratePageUseCase._parse_values(
|
||||
'{"apparence":"grand","histoire":"longue","extra":"ignoré"}',
|
||||
["apparence", "histoire"])
|
||||
assert out == {"apparence": "grand", "histoire": "longue"}
|
||||
|
||||
|
||||
def test_parse_values_missing_field_becomes_empty_string():
|
||||
out = GeneratePageUseCase._parse_values('{"apparence":"grand"}', ["apparence", "histoire"])
|
||||
assert out == {"apparence": "grand", "histoire": ""}
|
||||
|
||||
|
||||
def test_parse_values_casts_to_str_and_strips():
|
||||
out = GeneratePageUseCase._parse_values('{"n": 42, "s": " x "}', ["n", "s"])
|
||||
assert out == {"n": "42", "s": "x"}
|
||||
|
||||
|
||||
def test_parse_values_bad_json_raises():
|
||||
with pytest.raises(LLMProviderError):
|
||||
GeneratePageUseCase._parse_values("pas du json", ["a"])
|
||||
|
||||
|
||||
def test_parse_values_non_object_raises():
|
||||
with pytest.raises(LLMProviderError):
|
||||
GeneratePageUseCase._parse_values("[1, 2]", ["a"])
|
||||
|
||||
|
||||
async def test_execute_returns_filtered_result():
|
||||
class FakeLLM:
|
||||
async def generate(self, prompt, *, output_format=None, temperature=None):
|
||||
return '{"apparence":"grand","histoire":"épique","parasite":"x"}'
|
||||
result = await GeneratePageUseCase(FakeLLM()).execute(_CTX)
|
||||
assert result.values == {"apparence": "grand", "histoire": "épique"}
|
||||
Reference in New Issue
Block a user