lenskit.testing#

LensKit test harnesses and utilities.

This package contains utility code for testing LensKit and its components, including in derived packages. It relies on PyTest and Hypothesis.

Attributes#

Classes#

BasicComponentTests

ScorerTests

Common tests for scorer components. Many of these just test that the component

DemoRecs

Functions#

coo_arrays([shape, dtype, elements])

scored_lists(*[, n, scores])

Hypothesis generator that produces scored lists.

sparse_arrays(*[, layout])

sparse_tensors(*[, layout])

demo_recs()

A demo set of train, test, and recommendation data.

ml_20m()

ml_100k()

Fixture to load the MovieLens 100K dataset (currently as a data frame). It skips

ml_ds(ml_ds_unchecked)

Fixture to load the MovieLens test dataset. To use this, just include it as

ml_ds_unchecked()

Fixture to load the MovieLens dataset, without checking for modifications.

ml_ratings()

Fixture to load the test MovieLens ratings as a data frame. To use this,

pop_recs()

A demo set of train, test, and recommendation data, from most-popular.

msweb()

set_env_var(var, val)

Set an environment variable & restore it.

Package Contents#

lenskit.testing.coo_arrays(shape=None, dtype=nph.floating_dtypes(endianness='=', sizes=[32, 64]), elements=st.floats(-1000000.0, 1000000.0, allow_nan=False, allow_infinity=False, width=32))#
Return type:

scipy.sparse.coo_array

lenskit.testing.scored_lists(*, n=st.integers(0, 1000), scores=None)#

Hypothesis generator that produces scored lists.

Parameters:
  • n (int | tuple[int, int] | hypothesis.strategies.SearchStrategy[int])

  • scores (hypothesis.strategies.SearchStrategy[float] | Literal['gaussian'] | None)

Return type:

lenskit.data.ItemList

lenskit.testing.sparse_arrays(*, layout='csr', **kwargs)#
lenskit.testing.sparse_tensors(*, layout='csr', **kwargs)#
lenskit.testing.demo_recs()#

A demo set of train, test, and recommendation data.

Return type:

DemoRecs

lenskit.testing.ml_20m()#
Return type:

Generator[lenskit.data.Dataset, None, None]

lenskit.testing.ml_100k()#

Fixture to load the MovieLens 100K dataset (currently as a data frame). It skips the test if the ML100K data is not available.

Return type:

Generator[pandas.DataFrame, None, None]

lenskit.testing.ml_100k_zip#
lenskit.testing.ml_ds(ml_ds_unchecked)#

Fixture to load the MovieLens test dataset. To use this, just include it as a parameter in your test:

def test_thing_with_data(ml_ds: Dataset):
    ...

Note

This is imported in conftest.py so it is always available in LensKit tests.

Parameters:

ml_ds_unchecked (lenskit.data.Dataset)

Return type:

Generator[lenskit.data.Dataset, None, None]

lenskit.testing.ml_ds_unchecked()#

Fixture to load the MovieLens dataset, without checking for modifications.

Usually use ml_ds() instead.

Return type:

Generator[lenskit.data.Dataset, None, None]

lenskit.testing.ml_ratings()#

Fixture to load the test MovieLens ratings as a data frame. To use this, just include it as a parameter in your test:

def test_thing_with_data(ml_ratings: pd.DataFrame):
    ...

Note

This is imported in conftest.py so it is always available in LensKit tests.

Return type:

Generator[pandas.DataFrame, None, None]

lenskit.testing.ml_test_dir#
lenskit.testing.pop_recs()#

A demo set of train, test, and recommendation data, from most-popular.

Return type:

DemoRecs

lenskit.testing.msweb()#
Return type:

lenskit.splitting.TTSplit

lenskit.testing.set_env_var(var, val)#

Set an environment variable & restore it.