Skip to content

Commit

Permalink
Merge pull request #218 from lvgig/feature/update_tests_for_update_va…
Browse files Browse the repository at this point in the history
…lue_transformer

updated testing approach for SetValueTransformer
  • Loading branch information
limlam96 authored Apr 11, 2024
2 parents f9ca261 + ae3c916 commit 9cb8314
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions tests/misc/test_SetValueTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,37 @@
import test_aide as ta

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


class TestInit:
"""Tests for the SetValueTransformer.__init__ method."""
class TestInit(ColumnStrListInitTests):
"""Generic tests for SetValueTransformer.init()."""

def test_super_init_call(self, mocker):
"""Test that BaseTransformer.init us called as expected."""
expected_call_args = {
0: {
"args": (),
"kwargs": {"columns": ["a", "b"], "verbose": False, "copy": None},
},
}
@classmethod
def setup_class(cls):
cls.transformer_name = "SetValueTransformer"

with ta.functions.assert_function_call(
mocker,
tubular.base.BaseTransformer,
"__init__",
expected_call_args,
):
SetValueTransformer(columns=["a", "b"], value=1, verbose=False)

def test_value_attribute_set(self):
"""Test that the value passed in the value arg is set as an attribute of the same name."""
x = SetValueTransformer(columns=["a", "b"], value=1)
class TestFit(GenericFitTests):
"""Generic tests for SetValueTransformer.fit()"""

assert x.value == 1, "unexpected value set to value atttribute"
@classmethod
def setup_class(cls):
cls.transformer_name = "SetValueTransformer"


class TestTransform:
"""Tests for the SetValueTransformer.transform method."""
class TestTransform(GenericTransformTests):
"""Tests for SetValueTransformer.transform."""

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

def expected_df_1():
"""Expected output of test_value_set_in_transform."""
Expand All @@ -45,22 +43,6 @@ def expected_df_1():

return df

def test_super_transform_called(self, mocker):
"""Test that BaseTransformer.transform called."""
df = d.create_df_7()

x = SetValueTransformer(columns=["a", "b"], value=1)

expected_call_args = {0: {"args": (d.create_df_7(),), "kwargs": {}}}

with ta.functions.assert_function_call(
mocker,
tubular.base.BaseTransformer,
"transform",
expected_call_args,
):
x.transform(df)

@pytest.mark.parametrize(
("df", "expected"),
ta.pandas.adjusted_dataframe_params(d.create_df_2(), expected_df_1()),
Expand All @@ -76,3 +58,15 @@ def test_value_set_in_transform(self, df, expected):
expected=expected,
msg="incorrect value after SetValueTransformer transform",
)


class TestOtherBaseBehaviour(OtherBaseBehaviourTests):
"""
Class to run tests for SetValueTransformer behaviour 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 = "SetValueTransformer"

0 comments on commit 9cb8314

Please sign in to comment.