Skip to content

Commit

Permalink
🚧 adds inherited tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhopkinson26 committed Jun 27, 2024
1 parent a7ff0e7 commit e0ca8d2
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions tests/nominal/test_GroupRareLevelsTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@

import tests.test_data as d
import tubular
from tests.base_tests import (
ColumnStrListInitTests,
GenericFitTests,
GenericTransformTests,
OtherBaseBehaviourTests,
)
from tubular.nominal import GroupRareLevelsTransformer


class TestInit:
class TestInit(ColumnStrListInitTests):
"""Tests for GroupRareLevelsTransformer.init()."""

@classmethod
def setup_class(cls):
cls.transformer_name = "GroupRareLevelsTransformer"

def test_super_init_called(self, mocker):
"""Test that init calls BaseTransformer.init."""
expected_call_args = {
Expand Down Expand Up @@ -74,9 +84,13 @@ def test_unseen_levels_to_rare_not_bool_error(self):
GroupRareLevelsTransformer(columns="a", unseen_levels_to_rare=2)


class TestFit:
class TestFit(GenericFitTests):
"""Tests for GroupRareLevelsTransformer.fit()."""

@classmethod
def setup_class(cls):
cls.transformer_name = "GroupRareLevelsTransformer"

def test_super_fit_called(self, mocker):
"""Test that fit calls BaseTransformer.fit."""
df = d.create_df_5()
Expand Down Expand Up @@ -221,9 +235,13 @@ def test_training_data_levels_stored(self):
)


class TestTransform:
class TestTransform(GenericTransformTests):
"""Tests for GroupRareLevelsTransformer.transform()."""

@classmethod
def setup_class(cls):
cls.transformer_name = "GroupRareLevelsTransformer"

def expected_df_1():
"""Expected output for test_expected_output_no_weight."""
df = pd.DataFrame({"a": [1, 2, 3, 4, 5, 6, 7, 8, 9, np.nan]})
Expand Down Expand Up @@ -471,3 +489,15 @@ def test_rare_categories_forgotten(self):
assert (
cat not in output_categories
), f"{x.classname} output columns should forget rare encoded categories, expected {cat} to be forgotten from column {column}"


class TestOtherBaseBehaviour(OtherBaseBehaviourTests):
"""
Class to run tests for BaseTransformerBehaviour outside the three standard methods.
May need to overwite specific tests in this class if the tested transformer modifies this behaviour.
"""

@classmethod
def setup_class(cls):
cls.transformer_name = "BaseNominalTransformer"

0 comments on commit e0ca8d2

Please sign in to comment.