Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo committed Oct 26, 2023
1 parent 74d6375 commit 01f569c
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions tests/unit/reports/single_table/_properties/test_column_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,69 +119,69 @@ def test__generate_details_error(self):
assert column_names_nan == ['col1']
assert error_message == [expected_message]

@patch('sdmetrics.reports.single_table._properties.column_shapes.px')
def test_get_visualization(self, mock_px):
"""Test the ``get_visualization`` method."""
# Setup
column_shape_property = ColumnShapes()

mock_df = pd.DataFrame({
'Column': ['Column1', 'Column2'],
'Score': [0.7, 0.3],
'Metric': ['KSComplement', 'TVComplement']
})
column_shape_property.details = mock_df

mock__compute_average = Mock(return_value=0.5)
column_shape_property._compute_average = mock__compute_average

mock_bar = Mock()
mock_px.bar.return_value = mock_bar

# Run
column_shape_property.get_visualization()

# Assert
mock__compute_average.assert_called_once()

# Expected call
expected_kwargs = {
'data_frame': mock_df,
'x': 'Column',
'y': 'Score',
'title': (
'Data Quality: Column Shapes (Average'
f'Score={mock__compute_average.return_value})'
),
'category_orders': {'group': mock_df['Column'].tolist()},
'color': 'Metric',
'color_discrete_map': {
'KSComplement': '#000036',
'TVComplement': '#03AFF1',
},
'pattern_shape': 'Metric',
'pattern_shape_sequence': ['', '/'],
'hover_name': 'Column',
'hover_data': {
'Column': False,
'Metric': True,
'Score': True,
},
}
@patch('sdmetrics.reports.single_table._properties.column_shapes.px')
def test_get_visualization(self, mock_px):
"""Test the ``get_visualization`` method."""
# Setup
column_shape_property = ColumnShapes()

# Check call_args of mock_px.bar
_, kwargs = mock_px.bar.call_args
mock_df = pd.DataFrame({
'Column': ['Column1', 'Column2'],
'Score': [0.7, 0.3],
'Metric': ['KSComplement', 'TVComplement']
})
column_shape_property.details = mock_df

# Check DataFrame separately
assert kwargs.pop('data_frame').equals(expected_kwargs.pop('data_frame'))
mock__compute_average = Mock(return_value=0.5)
column_shape_property._compute_average = mock__compute_average

# Check other arguments
assert kwargs == expected_kwargs
mock_bar = Mock()
mock_px.bar.return_value = mock_bar

mock_bar.update_yaxes.assert_called_once_with(range=[0, 1])
mock_bar.update_layout.assert_called_once_with(
xaxis_categoryorder='total ascending',
plot_bgcolor='#F5F5F8',
margin={'t': 150},
font={'size': 18}
)
# Run
column_shape_property.get_visualization()

# Assert
mock__compute_average.assert_called_once()

# Expected call
expected_kwargs = {
'data_frame': mock_df,
'x': 'Column',
'y': 'Score',
'title': (
'Data Quality: Column Shapes (Average '
f'Score={mock__compute_average.return_value})'
),
'category_orders': {'group': mock_df['Column'].tolist()},
'color': 'Metric',
'color_discrete_map': {
'KSComplement': '#000036',
'TVComplement': '#03AFF1',
},
'pattern_shape': 'Metric',
'pattern_shape_sequence': ['', '/'],
'hover_name': 'Column',
'hover_data': {
'Column': False,
'Metric': True,
'Score': True,
},
}

# Check call_args of mock_px.bar
_, kwargs = mock_px.bar.call_args

# Check DataFrame separately
assert kwargs.pop('data_frame').equals(expected_kwargs.pop('data_frame'))

# Check other arguments
assert kwargs == expected_kwargs

mock_bar.update_yaxes.assert_called_once_with(range=[0, 1])
mock_bar.update_layout.assert_called_once_with(
xaxis_categoryorder='total ascending',
plot_bgcolor='#F5F5F8',
margin={'t': 150},
font={'size': 18}
)

0 comments on commit 01f569c

Please sign in to comment.