From dfed8494f7e4be31cbc76fe3e67f4938e6a61eee Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 19:09:13 -0800 Subject: [PATCH] Add test --- setup.cfg | 2 +- tests/unit/transformers/pii/test_anonymizer.py | 13 +++++++++++-- tests/unit/transformers/test_utils.py | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 9199ce47..077a5ffb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,7 +65,7 @@ max-attributes = 11 ignore-comments = yes ignore-docstrings = yes ignore-imports = yes -disable = R0801, R0903, R0913, R0914, R1708, C0209, W0223, W0221, W0237, C0411, +disable = R0801, R0902, R0903, R0913, R0914, R1708, C0209, W0223, W0221, W0237, C0411, W0231 # __init__ method from base class is not called on a child class ignored-classes = sre_parse diff --git a/tests/unit/transformers/pii/test_anonymizer.py b/tests/unit/transformers/pii/test_anonymizer.py index 79a8e1bd..16834c9b 100644 --- a/tests/unit/transformers/pii/test_anonymizer.py +++ b/tests/unit/transformers/pii/test_anonymizer.py @@ -332,7 +332,8 @@ def test___init__error_missing_value_generation(self): @patch('rdt.transformers.pii.anonymizer.faker') @patch('rdt.transformers.pii.anonymizer.AnonymizedFaker.check_provider_function') - def test___init__custom(self, mock_check_provider_function, mock_faker): + @patch('rdt.transformers.pii.anonymizer.warnings') + def test___init__custom(self, mock_warnings, mock_check_provider_function, mock_faker): """Test the instantiation of the transformer with custom parameters. Test that the transformer can be instantiated with a custom provider and function, and @@ -362,7 +363,8 @@ def test___init__custom(self, mock_check_provider_function, mock_faker): 'type': 'visa' }, locales=['en_US', 'fr_FR'], - cardinality_rule='match' + cardinality_rule='match', + enforce_uniqueness=True ) # Assert @@ -373,6 +375,13 @@ def test___init__custom(self, mock_check_provider_function, mock_faker): assert instance.locales == ['en_US', 'fr_FR'] mock_faker.Faker.assert_called_once_with(['en_US', 'fr_FR']) assert instance.cardinality_rule == 'match' + mock_warnings.warn.assert_has_calls([ + call( + "The 'enforce_uniqueness' parameter is no longer supported. " + "Please use the 'cardinality_rule' parameter instead.", + FutureWarning + ) + ]) def test___init__no_function_name(self): """Test the instantiation of the transformer with custom parameters. diff --git a/tests/unit/transformers/test_utils.py b/tests/unit/transformers/test_utils.py index 6bc27bd8..8458a6df 100644 --- a/tests/unit/transformers/test_utils.py +++ b/tests/unit/transformers/test_utils.py @@ -1,10 +1,10 @@ -import sre_parse -from sre_constants import MAXREPEAT from unittest.mock import patch import numpy as np import pandas as pd import pytest +import sre_parse +from sre_constants import MAXREPEAT from rdt.transformers.utils import ( _any, _max_repeat, check_nan_in_transform, flatten_column_list, learn_rounding_digits,