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
2 changes: 1 addition & 1 deletion src/cyris/service_layer/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def score_articles_batch(
result: dict[str, tuple[float, str]] = {}
url_to_tags: dict[str, list[str]] = {}
picks: dict[str, AreaPick] = {}
entries = data.get("scores", [])
entries = data.get("scores") or []
for entry in entries:
article_id = entry["id"]
score = float(entry["score"])
Expand Down
6 changes: 3 additions & 3 deletions tests/test_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ async def test_custom_snippet_length_in_batch(self, sample_articles):

@pytest.mark.parametrize(
"reply",
[{}, {"scores": [{"id": 9, "score": 80}]}],
ids=["no scores key", "unknown ids"],
[{}, {"scores": None}, {"scores": [{"id": 9, "score": 80}]}],
ids=["no scores key", "null scores", "unknown ids"],
)
async def test_a_batch_scoring_nothing_warns(self, sample_articles, reply, caplog):
from cyris.service_layer.scoring import score_articles_batch
Expand All @@ -310,7 +310,7 @@ async def test_a_batch_scoring_nothing_warns(self, sample_articles, reply, caplo

assert scores == {}
(record,) = [r for r in caplog.records if r.levelname == "WARNING"]
assert f"{len(reply.get('scores', []))} entries" in record.getMessage()
assert f"{len(reply.get('scores') or [])} entries" in record.getMessage()

async def test_a_batch_scoring_some_does_not_warn(self, sample_articles, caplog):
from cyris.service_layer.scoring import score_articles_batch
Expand Down
Loading