Skip to content

Commit

Permalink
test callback wrapping is helpful
Browse files Browse the repository at this point in the history
  • Loading branch information
billylanchantin committed Dec 14, 2023
1 parent f1977bf commit 2c42efb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/exgboost/training/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ defmodule EXGBoost.Training.State do

def validate!(%__MODULE__{} = state) do
unless state.status in [:cont, :halt] do
raise ArgumentError, "`status` must be `:cont` or `:halt`, found: #{state.status}."
raise ArgumentError,
"`status` must be `:cont` or `:halt`, found: `#{inspect(state.status)}`."
end

state
Expand Down
9 changes: 9 additions & 0 deletions test/exgboost_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,14 @@ defmodule EXGBoostTest do
)
end
end

test "callback with bad function results in helpful error", %{x: x, y: y} do
bad_fun = fn state -> %{state | status: :bad_status} end
bad_callback = EXGBoost.Training.Callback.new(:before_training, bad_fun, :bad_callback)

assert_raise ArgumentError,
"`status` must be `:cont` or `:halt`, found: `:bad_status`.",
fn -> EXGBoost.train(x, y, callbacks: [bad_callback]) end
end
end
end

0 comments on commit 2c42efb

Please sign in to comment.