Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing flaky tests test_code and test_minimal_fields_filtering #652

Merged
merged 2 commits into from
Oct 29, 2024
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
16 changes: 12 additions & 4 deletions tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,20 @@ async def test_minimal_fields_filtering() -> None:
"semantic_scholar",
"crossref",
}, "Should be from two sources"
assert details.citation == (
citation_boilerplate = (
"Unknown author(s). Augmenting large language models with chemistry tools."
" Unknown journal, Unknown year. URL:"
" https://doi.org/10.1038/s42256-024-00832-8,"
" doi:10.1038/s42256-024-00832-8."
), "Citation should be populated"
)
assert details.citation in {
( # Match in Nature Machine Intelligence
f"{citation_boilerplate} https://doi.org/10.1038/s42256-024-00832-8,"
" doi:10.1038/s42256-024-00832-8."
),
( # Match in arXiv
f"{citation_boilerplate} https://doi.org/10.48550/arxiv.2304.05376,"
" doi:10.48550/arxiv.2304.05376."
),
}, "Citation should be populated"
assert not details.source_quality, "No source quality data should exist"


Expand Down
18 changes: 11 additions & 7 deletions tests/test_paperqa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import os
import pathlib
import pickle
import textwrap
from collections.abc import AsyncIterable
Expand Down Expand Up @@ -43,6 +44,8 @@
)
from tests.conftest import VCR_DEFAULT_MATCH_ON

THIS_MODULE = pathlib.Path(__file__)


@pytest.fixture
def docs_fixture(stub_data_dir: Path) -> Docs:
Expand Down Expand Up @@ -991,17 +994,18 @@ def test_chunk_metadata_reader(stub_data_dir: Path) -> None:
assert metadata.total_parsed_text_length // 3000 <= len(chunk_text)


@pytest.mark.flaky(reruns=2, only_rerun=["AssertionError"]) # For couldn't answer
def test_code() -> None:
# load this script
doc_path = Path(os.path.abspath(__file__))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side comment: why did you include these changes to the doc path (moving the directory the doc to THIS_MODULE. Does it actually change functionality or is it a cleanup?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was cleanup, mainly I noticed usage of both os.path and pathlib.Path in the same line and smh'd

settings = Settings.from_name("fast")
docs = Docs()
docs.add(doc_path, "test_paperqa.py", docname="test_paperqa.py", disable_check=True)
assert len(docs.docs) == 1
assert (
"test_paperqa.py"
in docs.query("What file is read in by test_code?", settings=settings).answer
# load this script
docs.add(
THIS_MODULE, "test_paperqa.py", docname="test_paperqa.py", disable_check=True
)
assert len(docs.docs) == 1
answer = docs.query("What file is read in by test_code?", settings=settings)
assert not answer.could_not_answer, "Expected an answer"
assert "test_paperqa.py" in answer.answer


def test_zotero() -> None:
Expand Down
Loading