def test__get_transformers_raise_valueerror(self): """Test get transformers dict raise ValueError.""" # Run dtypes = { 'string': str } with pytest.raises(ValueError): Metadata._get_transformers(dtypes, None)
def test__get_transformers_no_error( self, numerical_mock, categorical_mock, boolean_mock, datetime_mock): """Test get transformers dict for each data type.""" # Setup numerical_mock.return_value = 'NumericalTransformer' categorical_mock.return_value = 'CategoricalTransformer' boolean_mock.return_value = 'BooleanTransformer' datetime_mock.return_value = 'DatetimeTransformer' # Run dtypes = { 'integer': int, 'float': float, 'categorical': np.object, 'boolean': bool, 'datetime': np.datetime64 } pii_fields = { 'categorical': 'email' } result = Metadata._get_transformers(dtypes, pii_fields) # Asserts expected = { 'integer': 'NumericalTransformer', 'float': 'NumericalTransformer', 'categorical': 'CategoricalTransformer', 'boolean': 'BooleanTransformer', 'datetime': 'DatetimeTransformer' } expected_numerical_calls = [call(dtype=int), call(dtype=float)] assert result == expected assert len(numerical_mock.call_args_list) == len(expected_numerical_calls) for item in numerical_mock.call_args_list: assert item in expected_numerical_calls assert categorical_mock.call_args == call(anonymize='email') assert boolean_mock.call_args == call() assert datetime_mock.call_args == call()