예제 #1
0
    def test_arguments(self):
        """Test that init has expected arguments."""

        h.test_function_arguments(
            func=CappingTransformer.__init__,
            expected_arguments=[
                "self",
                "capping_values",
                "quantiles",
                "weights_column",
            ],
            expected_default_values=(None, None, None),
        )
예제 #2
0
def test_getfullargspec_call_count():
    """Test the call to inspect.getfullargspec."""

    with mock.patch(
            target="inspect.getfullargspec",
            return_value=inspect.getfullargspec(h.check_is_class),
    ) as mocked_method:

        h.test_function_arguments(h.check_is_class,
                                  expected_arguments=["class_to_check"])

        assert (
            mocked_method.call_count == 1
        ), f"Unexpected number of calls to inspect.getfullargspec -\n  Expected: 1\n  Actual: {mocked_method.call_count}"
예제 #3
0
    def test_arguments(self):
        """Test that init has expected arguments."""

        h.test_function_arguments(
            func=SeriesStrMethodTransformer.__init__,
            expected_arguments=[
                "self",
                "new_column_name",
                "pd_method_name",
                "columns",
                "pd_method_kwargs",
            ],
            expected_default_values=({}, ),
        )
예제 #4
0
    def test_arguments(self):
        """Test that init has expected arguments."""

        h.test_function_arguments(
            func=GroupRareLevelsTransformer.__init__,
            expected_arguments=[
                "self",
                "columns",
                "cut_off_percent",
                "weight",
                "rare_level_name",
                "record_rare_levels",
            ],
            expected_default_values=(None, 0.01, None, "rare", True),
        )
예제 #5
0
    def test_arguments(self):
        """Test that init has expected arguments."""

        h.test_function_arguments(
            func=DateDiffLeapYearTransformer.__init__,
            expected_arguments=[
                "self",
                "column_lower",
                "column_upper",
                "new_column_name",
                "drop_cols",
                "missing_replacement",
            ],
            expected_default_values=(None, ),
        )
예제 #6
0
    def test_arguments(self):
        """Test that init has expected arguments."""

        h.test_function_arguments(
            func=OneHotEncodingTransformer.__init__,
            expected_arguments=[
                "self",
                "columns",
                "separator",
                "drop_original",
                "copy",
                "verbose",
            ],
            expected_default_values=(None, "_", False, True, False),
        )
예제 #7
0
def test_different_number_arguments_error():
    """Test that an AssertException is raised if the actual and expected positional args have different lengths."""

    incorrect_expected_args = ["actual", "expected", "msg_tag"]

    with pytest.raises(
            AssertionError,
            match=
            f"Incorrect number of arguments -\n  Expected: {len(incorrect_expected_args)}\n  Actual: 4",
    ):

        h.test_function_arguments(
            h.assert_frame_equal_msg,
            expected_arguments=incorrect_expected_args,
            expected_default_values=(False, ),
        )
    def test_arguments(self):
        """Test that init has expected arguments."""

        h.test_function_arguments(
            func=BetweenDatesTransformer.__init__,
            expected_arguments=[
                "self",
                "column_lower",
                "column_between",
                "column_upper",
                "new_column_name",
                "lower_inclusive",
                "upper_inclusive",
            ],
            expected_default_values=(True, True),
        )
    def test_arguments(self):
        """Test that init has expected arguments."""

        h.test_function_arguments(
            func=DateDifferenceTransformer.__init__,
            expected_arguments=[
                "self",
                "column_lower",
                "column_upper",
                "new_column_name",
                "units",
                "copy",
                "verbose",
            ],
            expected_default_values=(None, "D", True, False),
        )
예제 #10
0
def test_assert_equal_msg_calls_for_default_values():
    """Test the calls to assert_equal_msg for the keyword arguments."""

    with mock.patch(target="tubular.testing.helpers.assert_equal_msg"
                    ) as mocked_method:

        expected_args = ["self", "data", "index", "columns", "dtype", "copy"]
        expected_default_values = (None, None, None, None, False)

        h.test_function_arguments(
            pd.DataFrame,
            expected_arguments=expected_args,
            expected_default_values=expected_default_values,
        )

        assert mocked_method.call_count == (
            len(expected_args) + len(expected_default_values)
        ), f"Unexpected number of calls to tubular.testing.helpers.assert_equal_msg -\n  Expected: {len(expected_args) + len(expected_default_values)}\n  Actual: {mocked_method.call_count}"

        for call_n in range(len(expected_args), mocked_method.call_count):

            call_n_args = mocked_method.call_args_list[call_n]
            call_n_pos_args = call_n_args[0]
            call_n_kwargs = call_n_args[1]

            call_n_expected_pos_arg = (
                expected_default_values[call_n - len(expected_args)],
                expected_default_values[call_n - len(expected_args)],
                f"Incorrect default value at index {call_n - len(expected_args)} of default values",
            )

            assert len(call_n_pos_args) == len(
                call_n_expected_pos_arg
            ), f"Unexpected number of positional args in call {call_n} to tubular.testing.helpers.assert_equal_msg -\n  Expected: {len(call_n_expected_pos_arg)}\n  Actual:  {len(call_n_pos_args)}"

            for i, (e, a) in enumerate(
                    zip(call_n_expected_pos_arg, call_n_pos_args)):

                assert (
                    e == a
                ), f"Unexpected default value at index {i} -\n  Expected: {e}\n  Actual: {a}"

            assert (
                call_n_kwargs == {}
            ), f"Unexpected keyword args in call {call_n} to tubular.testing.helpers.assert_equal_msg -\n  Expected: None\n  Actual:  {call_n_kwargs}"
예제 #11
0
def test_default_values_non_mismatch_1_error():
    """Test that an exception is raised if the actual default values are none but the expected default values
    are not.
    """

    incorrect_defualt_value = ("a", )

    with pytest.raises(
            AssertionError,
            match=
            r"Incorrect default values -\n  Expected: .*\n  Actual: No default values",
    ):

        h.test_function_arguments(
            h.assert_inheritance,
            expected_arguments=["obj", "cls"],
            expected_default_values=incorrect_defualt_value,
        )
예제 #12
0
def test_assert_equal_msg_calls_for_positional_arguments():
    """Test the calls to assert_equal_msg for the positional arguments."""

    with mock.patch(target="tubular.testing.helpers.assert_equal_msg"
                    ) as mocked_method:

        expected_args = ["obj", "expected_method", "msg"]

        h.test_function_arguments(h.test_object_method,
                                  expected_arguments=expected_args)

        assert mocked_method.call_count == len(
            expected_args
        ), f"Unexpected number of calls to tubular.testing.helpers.assert_equal_msg -\n  Expected: {len(expected_args)}\n  Actual: {mocked_method.call_count}"

        for call_n in range(mocked_method.call_count):

            call_n_args = mocked_method.call_args_list[call_n]
            call_n_pos_args = call_n_args[0]
            call_n_kwargs = call_n_args[1]

            call_n_expected_pos_arg = (
                expected_args[call_n],
                expected_args[call_n],
                f"Incorrect arg at index {call_n}",
            )

            assert len(call_n_pos_args) == len(
                call_n_expected_pos_arg
            ), f"Unexpected number of positional args in call {call_n} to tubular.testing.helpers.assert_equal_msg -\n  Expected: {len(call_n_expected_pos_arg)}\n  Actual:  {len(call_n_pos_args)}"

            for i, (e, a) in enumerate(
                    zip(call_n_expected_pos_arg, call_n_pos_args)):

                assert (
                    e == a
                ), f"Unexpected positional arg at index {i} -\n  Expected: {e}\n  Actual: {a}"

            assert (
                call_n_kwargs == {}
            ), f"Unexpected keyword args in call {call_n} to tubular.testing.helpers.assert_equal_msg -\n  Expected: None\n  Actual:  {call_n_kwargs}"
예제 #13
0
def test_different_number_default_values_error():
    """Test that an AssertException is raised if the actual and expected default values have different lengths."""

    incorrect_defualt_value = ("a", "b", "c")

    with pytest.raises(
            AssertionError,
            match=
            f"Incorrect number of default values -\n  Expected: {len(incorrect_defualt_value)}\n  Actual: 1",
    ):

        h.test_function_arguments(
            h.assert_frame_equal_msg,
            expected_arguments=[
                "actual",
                "expected",
                "msg_tag",
                "print_actual_and_expected",
            ],
            expected_default_values=incorrect_defualt_value,
        )
예제 #14
0
def test_default_values_non_mismatch_2_error():
    """Test that an exception is raised if the actual default values are not none but the expected default values
    are.
    """

    incorrect_defualt_value = None

    with pytest.raises(
            AssertionError,
            match=
            "Incorrect default values -\n  Expected: No default values\n  Actual: .*",
    ):

        h.test_function_arguments(
            h.assert_frame_equal_msg,
            expected_arguments=[
                "actual",
                "expected",
                "msg_tag",
                "print_actual_and_expected",
            ],
            expected_default_values=incorrect_defualt_value,
        )
예제 #15
0
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=SeriesStrMethodTransformer.transform,
                                  expected_arguments=["self", "X"])
예제 #16
0
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=OrdinalEncoderTransformer.transform,
                                  expected_arguments=["self", "X"])
예제 #17
0
def test_expected_arguments_not_list_error():
    """Test that an exception is raised if expected_arguments is not a list."""

    with pytest.raises(TypeError):

        h.test_function_arguments(h.check_is_class, expected_arguments=1)
예제 #18
0
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=NullIndicator.transform,
                                  expected_arguments=["self", "X"])
    def test_arguments(self):
        """Test that columns_set_or_check has expected arguments."""

        h.test_function_arguments(
            func=BaseTransformer.columns_set_or_check, expected_arguments=["self", "X"]
        )
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=NominalToIntegerTransformer.transform,
                                  expected_arguments=["self", "X"])
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=ArbitraryImputer.transform,
                                  expected_arguments=["self", "X"])
예제 #22
0
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=ToDatetimeTransformer.transform,
                                  expected_arguments=["self", "X"])
예제 #23
0
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=GroupRareLevelsTransformer.transform,
                                  expected_arguments=["self", "X"])
예제 #24
0
    def test_arguments(self):
        """Test that transform has expected arguments."""

        h.test_function_arguments(func=DateDiffLeapYearTransformer.transform,
                                  expected_arguments=["self", "X"])