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

updated testing approach for SetValueTransformer #218

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
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"
Loading