Skip to content

Commit c0d4133

Browse files
committed
add test for batch.score
1 parent 8947bba commit c0d4133

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lenskit/tests/batch/test_batch_pipeline.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pytest import approx, fixture, mark
1414

1515
from lenskit.basic import BiasScorer, PopScorer
16-
from lenskit.batch import BatchPipelineRunner, predict, recommend
16+
from lenskit.batch import BatchPipelineRunner, predict, recommend, score
1717
from lenskit.data import Dataset, ItemList, UserIDKey, from_interactions_df
1818
from lenskit.data.convert import normalize_interactions_df
1919
from lenskit.metrics import NDCG, RBP, RMSE, RunAnalysis
@@ -64,6 +64,21 @@ def test_predict_single(mlb: MLB):
6464
assert preds >= 1 and preds <= 5
6565

6666

67+
def test_score_single(mlb: MLB):
68+
res = score(mlb.pipeline, {1: ItemList([31])}, n_jobs=1)
69+
70+
assert len(res) == 1
71+
uid, result = next(iter(res))
72+
assert isinstance(uid, UserIDKey)
73+
assert uid.user_id == 1
74+
assert len(result) == 1
75+
assert result.ids()[0] == 31
76+
77+
preds = result.field("score")
78+
assert preds is not None
79+
assert preds >= 1 and preds <= 5
80+
81+
6782
def test_recommend_user(mlb: MLB):
6883
user = 5
6984

0 commit comments

Comments
 (0)