Spaces:
Running
Running
Download tests/test_ui_components.py from nvikou/polyglot-rag: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/spaces/nvikou/polyglot-rag/resolve/main/tests/test_ui_components.py
- Command line
-
hf download hf://spaces/nvikou/polyglot-rag/tests/test_ui_components.py
-
curl -L -o test_ui_components.py https://huggingface.co/spaces/nvikou/polyglot-rag/resolve/main/tests/test_ui_components.py
2.27 kB
| """Rendu HTML des composants : traduction, échappement, cas vides.""" | |
| from core.ui import components as c | |
| from core.ui.i18n import UI_LANGUAGES | |
| def _dashboard_data(): | |
| return { | |
| "metrics": { | |
| "total_queries": 3, "abstention_rate": 0.33, "avg_confidence": 0.61, | |
| "avg_latency_ms": 812.4, "cross_lingual_rate": 0.5, | |
| "by_query_language": {"fr": 2, "ru": 1}, "by_target_language": {"fr": 2, "ru": 1}, | |
| }, | |
| "corpus": {"total_chunks": 18, "documents": 6, "by_language": {"fr": 3, "ar": 3}, "ann_index_type": "hnsw"}, | |
| "answer_cache": {"enabled": True, "size": 2, "maxsize": 512}, | |
| "embedding_cache": {"enabled": False, "size": 0, "maxsize": 0}, | |
| "recent": [{ | |
| "question": "<script>alert(1)</script>", "query_language": "fr", "target_language": "fr", | |
| "confidence_score": 0.7, "used_fallback": 0, "total_latency_ms": 900.0, | |
| }], | |
| } | |
| def test_all_renderers_work_in_every_language(): | |
| data = _dashboard_data() | |
| insight = { | |
| "query_language": "ru", "query_language_confidence": 0.9, "target_language": "ru", | |
| "confidence": 0.71, "latency_ms": 640.0, "from_cache": True, "used_fallback": False, | |
| "sources": [{"file": "faq_ru.md", "language": "ru", "page": 1, "score": 0.71, "title": None}], | |
| } | |
| for lang in UI_LANGUAGES: | |
| assert "PolyglotRAG" in c.render_brand(lang) | |
| assert c.render_architecture(lang).count("pg-step-t") == 10 | |
| assert "pg-kpi" in c.render_admin_dashboard(lang, data) | |
| assert "pg-stats" in c.render_insights(lang, insight) | |
| assert "faq_ru.md" in c.render_sources(lang, insight["sources"]) | |
| assert c.render_insights(lang, None) | |
| assert c.render_welcome(lang) | |
| def test_user_content_is_escaped(): | |
| html = c.render_admin_dashboard("en", _dashboard_data()) | |
| assert "<script>" not in html | |
| assert "<script>" in html | |
| def test_status_states(): | |
| assert "pg-status-ok" in c.render_status("en", {"total_chunks": 4, "documents": 2}, True) | |
| assert "pg-status-warn" in c.render_status("en", {"total_chunks": 0}, True) | |
| assert "pg-status-warn" in c.render_status("en", {"total_chunks": 4}, False) | |
| assert c.render_config_banner("en", True) == "" | |