Skip to content

Commit b0d0c98

Browse files
committed
Fix remaining errors
Signed-off-by: Gaurav Gupta <gaugup@microsoft.com>
1 parent d3c18e2 commit b0d0c98

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

tests/test_data_interface/test_public_data_interface.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,19 @@ def test_invalid_continuous_features(self, data_type):
6767
iris = load_iris(as_frame=True)
6868
dataset = iris.frame
6969

70+
import re
7071
if data_type == DataTypeCombinations.Incorrect:
71-
with pytest.raises(ValueError) as ve:
72+
with pytest.raises(
73+
ValueError,
74+
match=re.escape("should provide the name(s) of continuous features in the data as a list")):
7275
dice_ml.Data(dataframe=dataset, continuous_features=np.array(iris.feature_names),
7376
outcome_name='target')
74-
assert "should provide the name(s) of continuous features in the data as a list" in str(ve)
7577
elif data_type == DataTypeCombinations.AsNone:
76-
with pytest.raises(ValueError) as ve:
78+
with pytest.raises(
79+
ValueError,
80+
match=re.escape("should provide the name(s) of continuous features in the data as a list")):
7781
dice_ml.Data(dataframe=dataset, continuous_features=None,
7882
outcome_name='target')
79-
assert "should provide the name(s) of continuous features in the data as a list" in str(ve)
8083
else:
8184
with pytest.raises(
8285
ValueError,

tests/test_dice_interface/test_dice_KD.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def test_invalid_query_instance(self, desired_range, desired_class, sample_custo
5454
self.exp.dataset_with_predictions, self.exp.KD_tree, self.exp.predictions = \
5555
self.exp.build_KD_tree(self.data_df_copy, desired_range, desired_class, self.exp.predicted_outcome_name)
5656

57-
with pytest.raises(ValueError):
57+
with pytest.raises(
58+
ValueError, match="is outside the permitted range and isn't allowed to vary"):
5859
self.exp._generate_counterfactuals(query_instance=sample_custom_query_1, total_CFs=total_CFs,
5960
features_to_vary=features_to_vary, permitted_range=permitted_range)
6061

tests/test_dice_interface/test_dice_genetic.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def test_no_cfs(self, desired_class, sample_custom_query_1, total_CFs):
5454
@pytest.mark.parametrize(("features_to_vary", "permitted_range", "feature_weights"),
5555
[(['Numerical'], {'Categorical': ['b', 'c']}, "inverse_mad")])
5656
def test_invalid_query_instance(self, sample_custom_query_1, features_to_vary, permitted_range, feature_weights):
57-
with pytest.raises(ValueError):
57+
with pytest.raises(
58+
ValueError,
59+
match="is outside the permitted range and isn't allowed to vary"):
5860
self.exp.setup(features_to_vary, permitted_range, sample_custom_query_1, feature_weights)
5961

6062
# Testing that the features_to_vary argument actually varies only the features that you wish to vary
@@ -112,11 +114,10 @@ def test_permitted_range_categorical(self, desired_class, total_CFs, features_to
112114

113115
# Testing if an error is thrown when the query instance has outcome variable
114116
def test_query_instance_with_target_column(self, sample_custom_query_6):
115-
with pytest.raises(ValueError) as ve:
117+
with pytest.raises(
118+
ValueError, match="present in query instance"):
116119
self.exp.setup("all", None, sample_custom_query_6, "inverse_mad")
117120

118-
assert "present in query instance" in str(ve)
119-
120121
# Testing if only valid cfs are found after maxiterations
121122
@pytest.mark.parametrize(("desired_class", "total_CFs", "initialization", "maxiterations"),
122123
[(0, 7, "kdtree", 0), (0, 7, "random", 0)])

tests/test_dice_interface/test_dice_random.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def test_no_cfs(self, desired_class, desired_range, sample_custom_query_1, total
7070
@pytest.mark.parametrize(("features_to_vary", "permitted_range", "feature_weights"),
7171
[(['Numerical'], {'Categorical': ['b', 'c']}, "inverse_mad")])
7272
def test_invalid_query_instance(self, sample_custom_query_1, features_to_vary, permitted_range, feature_weights):
73-
with pytest.raises(ValueError):
73+
with pytest.raises(
74+
ValueError, match="is outside the permitted range and isn't allowed to vary"):
7475
self.exp.setup(features_to_vary, permitted_range, sample_custom_query_1, feature_weights)
7576

7677
# Testing that the features_to_vary argument actually varies only the features that you wish to vary

tests/test_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ def test_model_user_validation_model_type(self, create_iris_data):
5353
dice_ml.Model(model=trained_model, backend='sklearn', model_type='random')
5454

5555
def test_model_user_validation_no_valid_model(self):
56-
with pytest.raises(ValueError):
56+
with pytest.raises(
57+
ValueError,
58+
match="should provide either a trained model or the path to a model"):
5759
dice_ml.Model(backend='sklearn')

0 commit comments

Comments
 (0)