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

Enable linting and import sorting on tests #457

Merged
merged 3 commits into from
Jul 30, 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
2 changes: 1 addition & 1 deletion lenskit-funksvd/tests/test_funksvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

from pytest import approx, mark

from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.funksvd as svd
import lenskit.util.test as lktu
from lenskit.data.dataset import Dataset, from_interactions_df

_log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion lenskit-hpf/tests/test_hpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

from pytest import importorskip, mark

from lenskit.data.dataset import from_interactions_df
import lenskit.util.test as lktu
from lenskit.algorithms import basic
from lenskit.data.dataset import from_interactions_df

hpf = importorskip("lenskit.hpf")

Expand Down
2 changes: 1 addition & 1 deletion lenskit-implicit/tests/test_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

from pytest import mark

from lenskit.data.dataset import from_interactions_df
import lenskit.util.test as lktu
from lenskit import util
from lenskit.data.dataset import from_interactions_df
from lenskit.implicit import ALS, BPR

_log = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions lenskit/tests/test_als_explicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

from pytest import approx, mark

from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.data.movielens import load_movielens_df
import lenskit.util.test as lktu
from lenskit import batch
from lenskit.algorithms import als
from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.data.movielens import load_movielens_df

_log = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions lenskit/tests/test_als_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

from pytest import approx, mark

from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.data.movielens import load_movielens_df
import lenskit.util.test as lktu
from lenskit.algorithms import Recommender, als
from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.data.movielens import load_movielens_df

_log = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions lenskit/tests/test_batch_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import pytest

import lenskit.batch as lkb
from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.util.test as lktu
from lenskit.util.test import ml_ratings, ml_ds # noqa: F401
from lenskit.algorithms.bias import Bias
from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.util.test import ml_ds, ml_ratings # noqa: F401

_log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_batch_recommend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import pytest

import lenskit.crossfold as xf
from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.util.test as lktu
from lenskit import batch, topn
from lenskit.algorithms import Recommender
from lenskit.algorithms.basic import PopScore, TopN
from lenskit.algorithms.bias import Bias
from lenskit.data.dataset import Dataset, from_interactions_df

_log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import numpy as np
import pandas as pd
import torch

from pytest import approx, mark, raises
import torch

from lenskit import util as lku
from lenskit.algorithms.bias import Bias
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_candidate_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import numpy as np
import pandas as pd

from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.util.test as lktu
from lenskit.algorithms import basic
from lenskit.data.dataset import Dataset, from_interactions_df

simple_df = pd.DataFrame(
{"item": [1, 1, 2, 3], "user": [10, 12, 10, 13], "rating": [4.0, 3.0, 5.0, 2.0]}
Expand Down
5 changes: 2 additions & 3 deletions lenskit/tests/test_crossfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
import math

import numpy as np

import pandas as pd

import pytest

import lenskit.crossfold as xf
import lenskit.util.test as lktu


def test_partition_rows(ml_ratings: pd.DataFrame):
Expand Down Expand Up @@ -228,7 +227,7 @@ def test_partition_users(ml_ratings: pd.DataFrame):


def test_partition_may_skip_train(ml_ratings: pd.DataFrame):
"""Partitioning when users may not have enough ml_ratings to be in the train set and test set."""
"Partitioning when users may not have enough ratings to be in the train and test sets."
# make a data set where some users only have 1 rating
ml_ratings = ml_ratings.sample(frac=0.1)
users = ml_ratings.groupby("user")["rating"].count()
Expand Down
1 change: 1 addition & 0 deletions lenskit/tests/test_dataset_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
import pandas as pd

from pytest import approx

from lenskit.data import Dataset
Expand Down
1 change: 1 addition & 0 deletions lenskit/tests/test_dataset_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
import pandas as pd

from pytest import approx

from lenskit.data import Dataset
Expand Down
6 changes: 3 additions & 3 deletions lenskit/tests/test_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

from pytest import approx

from lenskit.data.dataset import Dataset
import lenskit.util.test as lktu
from lenskit import util as lku
from lenskit.algorithms import basic
from lenskit.algorithms.bias import Bias
from lenskit.util.test import ml_ratings, ml_ds # noqa: F401
from lenskit.data.dataset import Dataset
from lenskit.util.test import ml_ds, ml_ratings # noqa: F401

simple_df = pd.DataFrame(
{"item": [1, 1, 2, 3], "user": [10, 12, 10, 13], "rating": [4.0, 3.0, 5.0, 2.0]}
Expand Down Expand Up @@ -71,7 +71,7 @@ def test_fallback_clone(ml_ds):
assert clone is not algo
for a1, a2 in zip(algo.algorithms, clone.algorithms):
assert a1 is not a2
assert type(a2) == type(a1)
assert type(a2) == type(a1) # noqa: E721


def test_fallback_predict(ml_ratings, ml_ds):
Expand Down
8 changes: 4 additions & 4 deletions lenskit/tests/test_knn_item_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
from pytest import approx, fixture, mark

import lenskit.algorithms.knn.item as knn
from lenskit.algorithms.ranking import TopN
from lenskit.data.dataset import from_interactions_df
from lenskit.data.vocab import EntityId, Vocabulary
import lenskit.util.test as lktu
from lenskit import batch
from lenskit.algorithms import Recommender
from lenskit.algorithms.basic import Fallback
from lenskit.algorithms.bias import Bias
from lenskit.algorithms.ranking import TopN
from lenskit.data.dataset import from_interactions_df
from lenskit.data.vocab import EntityId, Vocabulary
from lenskit.diagnostics import ConfigWarning, DataWarning
from lenskit.util import clone
from lenskit.util.test import ml_ratings, ml_ds # noqa: F401
from lenskit.util.test import ml_ds, ml_ratings # noqa: F401

_log = logging.getLogger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions lenskit/tests/test_knn_user_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from pytest import approx, fail, mark

import lenskit.algorithms.knn.user as knn
from lenskit.algorithms.ranking import TopN
from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.util.test as lktu
from lenskit.algorithms import Recommender
from lenskit.algorithms.ranking import TopN
from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.util import clone
from lenskit.util.test import ml_ratings, ml_ds # noqa: F401
from lenskit.util.test import ml_ds, ml_ratings # noqa: F401

_log = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions lenskit/tests/test_load_movielens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
# Licensed under the MIT license, see LICENSE.md for details.
# SPDX-License-Identifier: MIT

from pathlib import Path
from lenskit.data.movielens import load_movielens
import functools
from pathlib import Path

from pytest import mark

from lenskit.data.movielens import load_movielens

ML_LATEST_DIR = Path("data/ml-latest-small")
ML_100K_DIR = Path("data/ml-100k")
ML_1M_DIR = Path("data/ml-1m")
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_popular.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import pandas as pd

import lenskit.util.test as lktu
from lenskit.util.test import ml_ratings, ml_ds # noqa: F401
from lenskit.algorithms import basic
from lenskit.util.test import ml_ds, ml_ratings # noqa: F401

simple_df = pd.DataFrame(
{"item": [1, 1, 2, 3], "user": [10, 12, 10, 13], "rating": [4.0, 3.0, 5.0, 2.0]}
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_predict_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from pytest import approx, mark, raises

from lenskit.data.dataset import from_interactions_df
import lenskit.metrics.predict as pm
import lenskit.util.test as lktu
from lenskit.data.dataset import from_interactions_df


def test_check_missing_empty():
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_rerank.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from lenskit.algorithms.basic import PopScore
from lenskit.algorithms.bias import Bias
from lenskit.algorithms.ranking import PlackettLuce
from lenskit.util.test import ml_ratings, ml_ds # noqa: F401
from lenskit.util.test import ml_ds, ml_ratings # noqa: F401


def test_plackett_luce_rec(ml_ds):
Expand Down
3 changes: 1 addition & 2 deletions lenskit/tests/test_svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

from pytest import approx, mark

from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.util.test as lktu
from lenskit.algorithms import svd
from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.util import clone

_log = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_topn_recs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from pytest import approx

from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.util.test as lktu
from lenskit.algorithms import basic, bias
from lenskit.data.dataset import Dataset, from_interactions_df

simple_df = pd.DataFrame(
{"item": [1, 1, 2, 3], "user": [10, 12, 10, 13], "rating": [4.0, 3.0, 5.0, 2.0]}
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ def func(foo):
def test_clone_core_obj(obj):
o2 = lku.clone(obj)
assert o2 == obj
assert type(o2) == type(obj)
assert type(o2) == type(obj) # noqa: E721
4 changes: 2 additions & 2 deletions lenskit/tests/test_util_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import numpy as np
import pandas as pd

from lenskit.data.dataset import Dataset, from_interactions_df
import lenskit.util.test as lktu
from lenskit.algorithms import basic
from lenskit.util.test import ml_ratings, ml_ds # noqa: F401
from lenskit.data.dataset import Dataset, from_interactions_df
from lenskit.util.test import ml_ds, ml_ratings # noqa: F401

simple_df = pd.DataFrame(
{"item": [1, 1, 2, 3], "user": [10, 12, 10, 13], "rating": [4.0, 3.0, 5.0, 2.0]}
Expand Down
5 changes: 2 additions & 3 deletions lenskit/tests/test_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

from uuid import UUID

import numpy as np

import hypothesis.strategies as st
from hypothesis import assume, given
import numpy as np
from pytest import raises

from lenskit.data import Vocabulary
Expand Down Expand Up @@ -59,7 +60,6 @@ def test_create_nonunique(keys: list[int | str | UUID]):
)
)
def test_equal(keys: list[int | str | UUID]):
uq = set(keys)
vocab = Vocabulary(keys)

v2 = Vocabulary(keys)
Expand Down Expand Up @@ -210,7 +210,6 @@ def test_add_terms(initial: set[int], new: list[int]):

@given(st.one_of(st.sets(st.integers()), st.sets(st.emails())))
def test_all_terms(initial: set[int] | set[str]):
ni = len(initial)
vocab = Vocabulary(initial)

tl = sorted(initial)
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ target-version = "py310"
[tool.ruff.lint]
select = ["E", "F", "I"]
unfixable = ["F401"]
exclude = [".git", "__pycache__", "build", "dist", "*/tests/*"]
exclude = [".git", "__pycache__", "build", "dist"]

[tool.ruff.lint.per-file-ignores]
# Importing PyTest fixtures triggers F811
"*/tests/*.py" = ["F811"]
"*/tests/*.py" = ["F811", "F401"]

[tool.ruff.lint.isort]
section-order = [
Expand All @@ -54,6 +54,7 @@ known-first-party = ["lenskit"]
[tool.ruff.lint.isort.sections]
testing = ["pytest", "hypothesis"]


[tool.pyright]
typeCheckingMode = "basic"
exclude = ["docs/*"]
Expand Down
Loading