Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/Bridges/Bridges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@
return
end

_runtests_error_handler(err, ::Bool) = rethrow(err)

function _runtests_error_handler(

Check warning on line 227 in src/Bridges/Bridges.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Bridges.jl#L227

Added line #L227 was not covered by tests
err::MOI.GetAttributeNotAllowed{MOI.ConstraintFunction},
cannot_unbridge::Bool,
)
if cannot_unbridge
return # This error is expected. Do nothing.
end
return rethrow(err)
end

"""
runtests(
Bridge::Type{<:AbstractBridge},
Expand Down Expand Up @@ -305,13 +317,8 @@
set = try
MOI.get(model, MOI.ConstraintSet(), ci)
catch err
# Could be thrown by `unbridged_function`
if cannot_unbridge &&
err isa MOI.GetAttributeNotAllowed{MOI.ConstraintFunction}
continue
else
rethrow(err)
end
_runtests_error_handler(err, cannot_unbridge)
continue
end
for attr in (MOI.ConstraintPrimalStart(), MOI.ConstraintDualStart())
if MOI.supports(model, attr, MOI.ConstraintIndex{F,S})
Expand Down
24 changes: 24 additions & 0 deletions test/Bridges/Variable/zeros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ function test_runtests()
return
end

function test_bridge_error_handler()
for (err, flag) in (
ErrorException("abc") => false,
MOI.GetAttributeNotAllowed(MOI.ObjectiveSense()) => false,
MOI.GetAttributeNotAllowed(MOI.ConstraintFunction()) => true,
)
@test_throws err try
@assert false
catch
MOI.Bridges._runtests_error_handler(err, false)
end
if flag
@test MOI.Bridges._runtests_error_handler(err, true) === nothing
else
@test_throws err try
@assert false
catch
MOI.Bridges._runtests_error_handler(err, true)
end
end
end
return
end

function test_zeros()
mock = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
bridged_mock = MOI.Bridges.Variable.Zeros{Float64}(mock)
Expand Down
Loading