Download tests/unit/test_processing_agent.py from Necthrall/AI: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/spaces/Necthrall/AI/resolve/main/tests/unit/test_processing_agent.py
- Command line
-
hf download hf://spaces/Necthrall/AI/tests/unit/test_processing_agent.py
-
curl -L -o test_processing_agent.py https://huggingface.co/spaces/Necthrall/AI/resolve/main/tests/unit/test_processing_agent.py
3.56 kB
| import pytest | |
| from agents.processing_agent import ProcessingAgent | |
| from models.state import Passage, State | |
| def make_state(): | |
| def _make(query: str, passages): | |
| return State(query=query, passages=passages) | |
| return _make | |
| def test_processing_enriches_state_single_passage(make_state): | |
| state = make_state( | |
| "test", | |
| [ | |
| Passage( | |
| paper_id="abc123", | |
| text="# Introduction\n" + "A " * 5000 + "\n# Methods\n" + "B " * 5000, | |
| metadata={ | |
| "title": "Test Paper", | |
| "text_source": "pdf", | |
| "year": 2020, | |
| "venue": "Journal of Testing", | |
| "influentialCitationCount": 2, | |
| }, | |
| ) | |
| ], | |
| ) | |
| agent = ProcessingAgent(chunk_size=500, chunk_overlap=50) | |
| updated_state = agent.process(state) | |
| assert hasattr(updated_state, "chunks") | |
| assert updated_state.chunks is not None | |
| assert len(updated_state.chunks) >= 10 | |
| first_meta = updated_state.chunks[0].metadata | |
| assert first_meta["paper_id"] == "abc123" | |
| assert first_meta["paper_title"] == "Test Paper" | |
| assert first_meta["year"] == 2020 | |
| assert first_meta["venue"] == "Journal of Testing" | |
| assert first_meta["influential_citation_count"] == 2 | |
| def test_processing_multiple_passages_generates_chunks(make_state): | |
| passages = [] | |
| for i in range(3): | |
| passages.append( | |
| Passage( | |
| paper_id=f"p{i}", | |
| text="# Introduction\n" | |
| + ("X " * 4000) | |
| + "\n# Results\n" | |
| + ("Y " * 4000), | |
| metadata={ | |
| "title": f"Paper {i}", | |
| "text_source": "pdf", | |
| "year": 2019 + i, | |
| "venue": "Conf", | |
| "influentialCitationCount": i, | |
| }, | |
| ) | |
| ) | |
| state = make_state("multi", passages) | |
| agent = ProcessingAgent(chunk_size=500, chunk_overlap=50) | |
| updated = agent.process(state) | |
| assert hasattr(updated, "chunks") | |
| assert len(updated.chunks) >= 30 | |
| def test_empty_passage_is_skipped(make_state): | |
| state = make_state( | |
| "empty", | |
| [Passage(paper_id="e1", text="", metadata={"text_source": "pdf"})], | |
| ) | |
| agent = ProcessingAgent(chunk_size=200, chunk_overlap=20) | |
| updated = agent.process(state) | |
| assert hasattr(updated, "chunks") | |
| assert isinstance(updated.chunks, list) | |
| assert len(updated.chunks) == 0 | |
| # No critical error appended (empty passage skipped) | |
| assert all("Zero chunks" not in e for e in updated.errors) | |
| def test_markdown_parser_handles_plain_text(make_state): | |
| # No explicit Markdown headers -> MarkdownNodeParser chunks by size | |
| long_text = "This is a paper without headers. " + ("word " * 3000) | |
| state = make_state( | |
| "plaintext", | |
| [Passage(paper_id="f1", text=long_text, metadata={"text_source": "pdf"})], | |
| ) | |
| agent = ProcessingAgent(chunk_size=400, chunk_overlap=50) | |
| updated = agent.process(state) | |
| assert hasattr(updated, "chunks") | |
| assert len(updated.chunks) > 0 | |
| def test_no_passages_triggers_error(): | |
| state = State(query="none", passages=[]) | |
| agent = ProcessingAgent() | |
| res = agent.process(state) | |
| assert len(res.errors) > 0 | |
| assert any( | |
| "No passages available" in e or "Zero chunks generated" in e for e in res.errors | |
| ) | |