Skip to content

Commit 59f8a9b

Browse files
authored
[python-package] Add specific error messages to test_plotting (#6927)
add error messages to test_plotting.py
1 parent adb7ee1 commit 59f8a9b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/python_package_test/test_plotting.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ def test_plot_split_value_histogram(params, breast_cancer_split, train_data):
154154
assert ax2.patches[2].get_facecolor() == (0, 0.5, 0, 1.0) # g
155155
assert ax2.patches[3].get_facecolor() == (0, 0, 1.0, 1.0) # b
156156

157-
with pytest.raises(ValueError):
157+
with pytest.raises(
158+
ValueError, match="Cannot plot split value histogram, because feature 0 was not used in splitting"
159+
):
158160
lgb.plot_split_value_histogram(gbm0, 0) # was not used in splitting
159161

160162

@@ -166,7 +168,7 @@ def test_plot_tree(breast_cancer_split):
166168
gbm = lgb.LGBMClassifier(n_estimators=10, num_leaves=3, verbose=-1)
167169
gbm.fit(X_train, y_train)
168170

169-
with pytest.raises(IndexError):
171+
with pytest.raises(IndexError, match="tree_index is out of range."):
170172
lgb.plot_tree(gbm, tree_index=83)
171173

172174
ax = lgb.plot_tree(gbm, tree_index=3, figsize=(15, 8), show_info=["split_gain"])
@@ -184,7 +186,7 @@ def test_create_tree_digraph(tmp_path, breast_cancer_split):
184186
gbm = lgb.LGBMClassifier(n_estimators=10, num_leaves=3, verbose=-1, monotone_constraints=constraints)
185187
gbm.fit(X_train, y_train)
186188

187-
with pytest.raises(IndexError):
189+
with pytest.raises(IndexError, match="tree_index is out of range."):
188190
lgb.create_tree_digraph(gbm, tree_index=83)
189191

190192
graph = lgb.create_tree_digraph(
@@ -229,7 +231,7 @@ def test_tree_with_categories_below_max_category_values(tmp_path):
229231
gbm = lgb.LGBMClassifier(**params)
230232
gbm.fit(X_train, y_train)
231233

232-
with pytest.raises(IndexError):
234+
with pytest.raises(IndexError, match="tree_index is out of range."):
233235
lgb.create_tree_digraph(gbm, tree_index=83)
234236

235237
graph = lgb.create_tree_digraph(
@@ -274,7 +276,7 @@ def test_tree_with_categories_above_max_category_values(tmp_path):
274276
gbm = lgb.LGBMClassifier(**params)
275277
gbm.fit(X_train, y_train)
276278

277-
with pytest.raises(IndexError):
279+
with pytest.raises(IndexError, match="tree_index is out of range."):
278280
lgb.create_tree_digraph(gbm, tree_index=83)
279281

280282
graph = lgb.create_tree_digraph(

0 commit comments

Comments
 (0)