Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,25 @@ def fixture_vcr_config() -> dict[str, Any]:
}


@pytest.fixture
def tmp_path_cleanup(tmp_path: Path) -> Iterator[Path]:
@pytest.fixture(name="tmp_path_cleanup")
def fixture_tmp_path_cleanup(tmp_path: Path) -> Iterator[Path]:
yield tmp_path
# Cleanup after the test
if tmp_path.exists():
shutil.rmtree(tmp_path, ignore_errors=True)


@pytest.fixture
def agent_home_dir(tmp_path_cleanup: str | os.PathLike) -> Iterator[str | os.PathLike]:
@pytest.fixture(name="agent_home_dir")
def fixture_agent_home_dir(
tmp_path_cleanup: str | os.PathLike,
) -> Iterator[str | os.PathLike]:
"""Set up a unique temporary folder for the agent module."""
with patch.dict("os.environ", {"PQA_HOME": str(tmp_path_cleanup)}):
yield tmp_path_cleanup


@pytest.fixture
def agent_index_dir(agent_home_dir: Path) -> Path:
@pytest.fixture(name="agent_index_dir")
def fixture_agent_index_dir(agent_home_dir: Path) -> Path:
return agent_home_dir / ".pqa" / "indexes"


Expand Down
12 changes: 3 additions & 9 deletions tests/test_paperqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
THIS_MODULE = pathlib.Path(__file__)


@pytest_asyncio.fixture
async def docs_fixture(stub_data_dir: Path) -> Docs:
@pytest_asyncio.fixture(name="docs_fixture")
async def fixture_docs_fixture(stub_data_dir: Path) -> Docs:
docs = Docs()
with (stub_data_dir / "paper.pdf").open("rb") as f:
await docs.aadd_file(f, "Wellawatte et al, XAI Review, 2023")
Expand Down Expand Up @@ -929,12 +929,6 @@ async def test_repeat_keys(stub_data_dir) -> None:
assert ds[1].docname == "Wiki2023a"


@pytest.mark.asyncio
async def test_can_read_normal_pdf_reader(docs_fixture) -> None:
answer = await docs_fixture.aquery("Are counterfactuals actionable? [yes/no]")
assert "yes" in answer.answer or "Yes" in answer.answer


@pytest.mark.asyncio
async def test_pdf_reader_w_no_match_doc_details(stub_data_dir: Path) -> None:
docs = Docs()
Expand Down Expand Up @@ -1088,8 +1082,8 @@ async def test_pdf_reader_match_doc_details(stub_data_dir: Path) -> None:

@pytest.mark.asyncio
async def test_fileio_reader_pdf(stub_data_dir: Path) -> None:
docs = Docs()
with (stub_data_dir / "paper.pdf").open("rb") as f:
docs = Docs()
await docs.aadd_file(f, "Wellawatte et al, XAI Review, 2023")
num_retries = 3
for _ in range(num_retries):
Expand Down