Skip to content

Commit fd9284a

Browse files
committed
Tightened up assertions to be more readable
1 parent a0e2a3e commit fd9284a

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

tests/test_clients.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def test_bad_init() -> None:
533533
@pytest.mark.vcr
534534
@pytest.mark.asyncio
535535
async def test_ensure_sequential_run(caplog) -> None:
536-
caplog.set_level(logging.DEBUG)
536+
caplog.set_level(logging.DEBUG, logger=paperqa.clients.__name__)
537537
# were using a DOI that is NOT in crossref, but running the crossref client first
538538
# we will ensure that both are run sequentially
539539

@@ -551,14 +551,18 @@ async def test_ensure_sequential_run(caplog) -> None:
551551
fields=["doi", "title"],
552552
)
553553
assert details, "Should find the right DOI in the second client"
554-
record_indices = {"crossref": -1, "semantic_scholar": -1}
554+
record_indices: dict[str, list[int]] = {"crossref": [], "semantic_scholar": []}
555555
for n, record in enumerate(caplog.records):
556+
if not record.name.startswith(paperqa.__name__): # Skip non-PQA logs
557+
continue
556558
if "CrossrefProvider" in record.msg:
557-
record_indices["crossref"] = n
559+
record_indices["crossref"].append(n)
558560
if "SemanticScholarProvider" in record.msg:
559-
record_indices["semantic_scholar"] = n
561+
record_indices["semantic_scholar"].append(n)
562+
assert record_indices["crossref"], "Crossref should run"
563+
assert record_indices["semantic_scholar"], "Semantic Scholar should run"
560564
assert (
561-
record_indices["crossref"] < record_indices["semantic_scholar"]
565+
record_indices["crossref"][-1] < record_indices["semantic_scholar"][-1]
562566
), "Crossref should run first"
563567

564568
non_clobbered_details = await client.query(
@@ -575,7 +579,7 @@ async def test_ensure_sequential_run(caplog) -> None:
575579
@pytest.mark.vcr
576580
@pytest.mark.asyncio
577581
async def test_ensure_sequential_run_early_stop(caplog) -> None:
578-
caplog.set_level(logging.DEBUG)
582+
caplog.set_level(logging.DEBUG, logger=paperqa.clients.__name__)
579583
# now we should stop after hitting s2
580584
async with aiohttp.ClientSession() as session:
581585
client = DocMetadataClient(
@@ -591,21 +595,23 @@ async def test_ensure_sequential_run_early_stop(caplog) -> None:
591595
fields=["doi", "title"],
592596
)
593597
assert details, "Should find the right DOI in the second client"
594-
record_indices = {"crossref": -1, "semantic_scholar": -1, "early_stop": -1}
598+
record_indices: dict[str, list[int]] = {
599+
"crossref": [],
600+
"semantic_scholar": [],
601+
"early_stop": [],
602+
}
595603
for n, record in enumerate(caplog.records):
604+
if not record.name.startswith(paperqa.__name__): # Skip non-PQA logs
605+
continue
596606
if "CrossrefProvider" in record.msg:
597-
record_indices["crossref"] = n
607+
record_indices["crossref"].append(n)
598608
if "SemanticScholarProvider" in record.msg:
599-
record_indices["semantic_scholar"] = n
609+
record_indices["semantic_scholar"].append(n)
600610
if "stopping early." in record.msg:
601-
record_indices["early_stop"] = n
602-
assert (
603-
record_indices["crossref"] == -1
604-
), "Crossref should be index -1 i.e. not found"
605-
assert (
606-
record_indices["semantic_scholar"] != -1
607-
), "Semantic Scholar should be found"
608-
assert record_indices["early_stop"] != -1, "We should stop early."
611+
record_indices["early_stop"].append(n)
612+
assert not record_indices["crossref"], "Crossref should not have run"
613+
assert record_indices["semantic_scholar"], "Semantic Scholar should have run"
614+
assert record_indices["early_stop"], "We should stop early"
609615

610616

611617
@pytest.mark.vcr

0 commit comments

Comments
 (0)