Skip to content

Commit

Permalink
fixed test with unsupported targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Daria Tikhonovich committed Aug 13, 2024
1 parent 7b7cc43 commit fabb5a9
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions tests/models/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,26 @@ def test_full_model_works_for_all_without_features(self, kind: str) -> None:
@pytest.mark.parametrize("dataset_key", ("no_features", "with_features"))
@pytest.mark.parametrize("kind", ("u2i", "i2i"))
@pytest.mark.parametrize("model_key", ("hot", "hot_warm"))
def test_not_cold_models_with_cold_targets(self, dataset_key: str, kind: str, model_key: str) -> None:
def test_not_cold_models_with_cold_targets_raise(self, dataset_key: str, kind: str, model_key: str) -> None:
targets = self.colds[kind] + self.hots[kind]

# raise
with pytest.raises(ValueError, match="doesn't support recommendations for cold"):
self._get_reco(targets, model_key, dataset_key, kind, on_unsupported_targets="raise")

# ignore
@pytest.mark.parametrize("dataset_key", ("no_features", "with_features"))
@pytest.mark.parametrize("kind", ("u2i", "i2i"))
@pytest.mark.parametrize("model_key", ("hot", "hot_warm"))
def test_not_cold_models_with_cold_targets_ignore(self, dataset_key: str, kind: str, model_key: str) -> None:
targets = self.colds[kind] + self.hots[kind]
actual = self._get_reco(targets, model_key, dataset_key, kind, on_unsupported_targets="ignore")
expected_targets = self.hots[kind]
expected = self._get_reco(expected_targets, model_key, dataset_key, kind)
pd.testing.assert_frame_equal(actual, expected)

# warn
@pytest.mark.parametrize("dataset_key", ("no_features", "with_features"))
@pytest.mark.parametrize("kind", ("u2i", "i2i"))
@pytest.mark.parametrize("model_key", ("hot", "hot_warm"))
def test_not_cold_models_with_cold_targets_warn(self, dataset_key: str, kind: str, model_key: str) -> None:
targets = self.colds[kind] + self.hots[kind]
with warnings.catch_warnings(record=True) as w:
self._get_reco(targets, model_key, dataset_key, kind, on_unsupported_targets="warn")
assert len(w) == 1
Expand All @@ -364,20 +370,24 @@ def test_not_cold_models_with_cold_targets(self, dataset_key: str, kind: str, mo
assert "warm" not in str(w[-1].message)

@pytest.mark.parametrize("kind", ("u2i", "i2i"))
def test_warm_only_model_with_warm_targets_without_features(self, kind: str) -> None:
def test_warm_only_model_with_warm_targets_without_features_raise(self, kind: str) -> None:
targets = self.warms[kind] + self.hots[kind]

# raise
with pytest.raises(ValueError, match="doesn't support recommendations for cold"):
self._get_reco(targets, "hot_warm", "no_features", kind, on_unsupported_targets="raise")

@pytest.mark.parametrize("kind", ("u2i", "i2i"))
def test_warm_only_model_with_warm_targets_without_features_ignore(self, kind: str) -> None:
targets = self.warms[kind] + self.hots[kind]

# ignore
actual = self._get_reco(targets, "hot_warm", "no_features", kind, on_unsupported_targets="ignore")
expected_targets = self.hots[kind]
expected = self._get_reco(expected_targets, "hot_warm", "no_features", kind)
pd.testing.assert_frame_equal(actual, expected)

# warn
@pytest.mark.parametrize("kind", ("u2i", "i2i"))
def test_warm_only_model_with_warm_targets_without_features_warn(self, kind: str) -> None:
targets = self.warms[kind] + self.hots[kind]
with warnings.catch_warnings(record=True) as w:
self._get_reco(targets, "hot_warm", "no_features", kind, on_unsupported_targets="warn")
assert len(w) == 1
Expand All @@ -386,20 +396,22 @@ def test_warm_only_model_with_warm_targets_without_features(self, kind: str) ->
assert "warm" not in str(w[-1].message)

@pytest.mark.parametrize("kind", ("u2i", "i2i"))
def test_hot_only_model_with_warm_targets(self, kind: str) -> None:
def test_hot_only_model_with_warm_targets_raise(self, kind: str) -> None:
targets = self.warms[kind] + self.hots[kind]

# raise
with pytest.raises(ValueError, match="doesn't support recommendations for warm"):
self._get_reco(targets, "hot", "with_features", kind, on_unsupported_targets="raise")

# ignore
@pytest.mark.parametrize("kind", ("u2i", "i2i"))
def test_hot_only_model_with_warm_targets_ignore(self, kind: str) -> None:
targets = self.warms[kind] + self.hots[kind]
actual = self._get_reco(targets, "hot", "with_features", kind, on_unsupported_targets="ignore")
expected_targets = self.hots[kind]
expected = self._get_reco(expected_targets, "hot", "with_features", kind)
pd.testing.assert_frame_equal(actual, expected)

# warn
@pytest.mark.parametrize("kind", ("u2i", "i2i"))
def test_hot_only_model_with_warm_targets_warn(self, kind: str) -> None:
targets = self.warms[kind] + self.hots[kind]
with warnings.catch_warnings(record=True) as w:
self._get_reco(targets, "hot", "with_features", kind, on_unsupported_targets="warn")
assert len(w) == 1
Expand Down

0 comments on commit fabb5a9

Please sign in to comment.