Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fealho committed Jan 17, 2024
1 parent f1cc267 commit c7b10a2
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tests/unit/transformers/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def test__reverse_transform_generator_size_of_input_data(self):
assert instance.generated == 4

@patch('rdt.transformers.text.warnings')
def test__reverse_transform_not_enough_unique_values(self, mock_warnings):
def test__reverse_transform_not_enough_unique_values_enforce_uniqueness(self, mock_warnings):
"""Test it when there are not enough unique values to generate."""
# Setup
instance = RegexGenerator('[A-E]', enforce_uniqueness=True)
Expand All @@ -448,6 +448,47 @@ def test__reverse_transform_not_enough_unique_values(self, mock_warnings):
)
np.testing.assert_array_equal(out, np.array(['A', 'B', 'C', 'D', 'E', 'A(0)']))

def test__reverse_transform_not_enough_unique_values(self):
"""Test it when there are not enough unique values to generate."""
# Setup
instance = RegexGenerator('[A-E]', enforce_uniqueness=False)
instance.data_length = 6
generator = AsciiGenerator(5)
instance.generator = generator
instance.generator_size = 5
instance.generated = 0
instance.columns = ['a']
columns_data = pd.Series()

# Run
out = instance._reverse_transform(columns_data)

# Assert
np.testing.assert_array_equal(out, np.array(['A', 'B', 'C', 'D', 'E', 'A']))

@patch('rdt.transformers.text.warnings')
def test__reverse_transform_not_enough_unique_values_numerical(self, mock_warnings):
"""Test it when there are not enough unique values to generate."""
# Setup
instance = RegexGenerator('[1-3]', enforce_uniqueness=True)
instance.data_length = 6
generator = AsciiGenerator(5)
instance.generator = generator
instance.generator_size = 3
instance.generated = 0
instance.columns = ['a']
columns_data = pd.Series()

# Run
out = instance._reverse_transform(columns_data)

# Assert
mock_warnings.warn.assert_called_once_with(
"The regex for 'a' can only generate 3 "
'unique values. Additional values may not exactly follow the provided regex.'
)
np.testing.assert_array_equal(out, np.array(['1', '2', '3', '4', '5', '6']))

@patch('rdt.transformers.text.warnings')
def test__reverse_transform_enforce_uniqueness_not_enough_remaining(self, mock_warnings):
"""Test the case when there are not enough unique values remaining."""
Expand Down

0 comments on commit c7b10a2

Please sign in to comment.