Spaces:
Runtime error
Runtime error
Download tests/unit/test_knowledge_import_documents.py from BattleFiven/ai-tester-platform: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/BattleFiven/ai-tester-platform/resolve/main/tests/unit/test_knowledge_import_documents.py
- Command line
-
hf download hf://spaces/BattleFiven/ai-tester-platform/tests/unit/test_knowledge_import_documents.py
-
curl -L -o test_knowledge_import_documents.py https://huggingface.co/spaces/BattleFiven/ai-tester-platform/resolve/main/tests/unit/test_knowledge_import_documents.py
1.79 kB
| from src.api.routes.knowledge_sources import ( | |
| _build_document_row, | |
| _merge_payload_rows, | |
| _parse_txt_file_rows, | |
| _validate_document_rows, | |
| ) | |
| def test_parse_txt_file_rows_detects_url_list_mode(): | |
| rows, mode = _parse_txt_file_rows( | |
| b"https://example.com/a\nhttps://example.com/b\n", | |
| filename="links.txt", | |
| ) | |
| assert mode == "link_list" | |
| assert len(rows) == 2 | |
| assert rows[0]["source_url"] == "https://example.com/a" | |
| def test_parse_txt_file_rows_detects_document_content_mode(): | |
| rows, mode = _parse_txt_file_rows( | |
| b"Guida Napoli\nMusei, castelli e lungomare.\n", | |
| filename="napoli.txt", | |
| ) | |
| assert mode == "document_content" | |
| assert len(rows) == 1 | |
| assert rows[0]["title"] == "napoli.txt" | |
| assert "Musei" in rows[0]["text"] | |
| def test_validate_document_rows_requires_text_and_deduplicates(): | |
| report = _validate_document_rows( | |
| [ | |
| _build_document_row("a.pdf", "Contenuto A"), | |
| _build_document_row("a.pdf", "Contenuto A"), | |
| _build_document_row("b.pdf", ""), | |
| ] | |
| ) | |
| assert report["row_count"] == 3 | |
| assert report["valid_count"] == 1 | |
| assert report["invalid_count"] == 2 | |
| assert report["ingestion_mode"] == "document_content" | |
| def test_merge_payload_rows_is_cumulative_and_deduplicates(): | |
| existing = [ | |
| {"source_url": "file://a.pdf", "title": "a.pdf", "text": "Contenuto A"}, | |
| ] | |
| incoming = [ | |
| {"source_url": "file://a.pdf", "title": "a.pdf", "text": "Contenuto A"}, | |
| {"source_url": "file://b.pdf", "title": "b.pdf", "text": "Contenuto B"}, | |
| ] | |
| merged = _merge_payload_rows(existing, incoming) | |
| assert len(merged) == 2 | |
| titles = {item["title"] for item in merged} | |
| assert titles == {"a.pdf", "b.pdf"} | |