Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo committed Dec 5, 2023
1 parent ac571ae commit 44e9aaa
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/integration/test_hyper_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,3 +1815,34 @@ def test_update_sdtype(self):

assert repr(new_config) == repr(expected_config)
assert ht._multi_column_fields == expected_multi_columns

def test_with_tuple_returned_by_faker(self):
"""Test that the Hypertransformer handles situations when Faker returns a tuple."""
# Setup
ht = HyperTransformer()
ht.set_config({
'sdtypes': {
'A': 'pii'
},
'transformers': {
'A': AnonymizedFaker(provider_name='currency', function_name='currency')
}
})

ht.fit(pd.DataFrame({
'A': ['a', 'b', 'c']
}))

# Run
result = ht.create_anonymized_columns(num_rows=10, column_names=['A'])

# Assert
expected_results = pd.DataFrame({
'A': [
'KHR, Cambodian riel', 'TVD, Tuvaluan dollar', 'PKR, Pakistani rupee',
'SVC, Salvadoran colón', 'CVE, Cape Verdean escudo', 'BRL, Brazilian real',
'RWF, Rwandan franc', 'KZT, Kazakhstani tenge', 'HRK, Croatian kuna',
'ILS, Israeli new shekel'
]
})
pd.testing.assert_frame_equal(result, expected_results)
19 changes: 19 additions & 0 deletions tests/unit/transformers/pii/test_anonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ def test__function_enforce_uniqueness_true(self):
unique_function.assert_called_once_with(type='int')
assert result == 1

def test__function_with_iterables_return(self):
"""Test that ``_function`` returns the values of the iterable."""
# setup
instance = Mock()
instance.enforce_uniqueness = False
function = Mock()
function.return_value = ('value_1', 'value_2')

instance.faker.number = function
instance.function_name = 'number'
instance.function_kwargs = {'type': 'int'}

# Run
result = AnonymizedFaker._function(instance)

# Assert
function.assert_called_once_with(type='int')
assert result == 'value_1, value_2'

@patch('rdt.transformers.pii.anonymizer.importlib')
@patch('rdt.transformers.pii.anonymizer.warnings')
def test__check_locales(self, mock_warnings, mock_importlib):
Expand Down

0 comments on commit 44e9aaa

Please sign in to comment.