File tree Expand file tree Collapse file tree 2 files changed +38
-7
lines changed Expand file tree Collapse file tree 2 files changed +38
-7
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,18 @@ function _test_structural_identical(
222
222
return
223
223
end
224
224
225
+ _runtests_error_handler (err, :: Bool ) = rethrow (err)
226
+
227
+ function _runtests_error_handler (
228
+ err:: MOI.GetAttributeNotAllowed{MOI.ConstraintFunction} ,
229
+ cannot_unbridge:: Bool ,
230
+ )
231
+ if cannot_unbridge
232
+ return # This error is expected. Do nothing.
233
+ end
234
+ return rethrow (err)
235
+ end
236
+
225
237
"""
226
238
runtests(
227
239
Bridge::Type{<:AbstractBridge},
@@ -305,13 +317,8 @@ function runtests(
305
317
set = try
306
318
MOI. get (model, MOI. ConstraintSet (), ci)
307
319
catch err
308
- # Could be thrown by `unbridged_function`
309
- if cannot_unbridge &&
310
- err isa MOI. GetAttributeNotAllowed{MOI. ConstraintFunction}
311
- continue
312
- else
313
- rethrow (err)
314
- end
320
+ _runtests_error_handler (err, cannot_unbridge)
321
+ continue
315
322
end
316
323
for attr in (MOI. ConstraintPrimalStart (), MOI. ConstraintDualStart ())
317
324
if MOI. supports (model, attr, MOI. ConstraintIndex{F,S})
Original file line number Diff line number Diff line change @@ -46,6 +46,30 @@ function test_runtests()
46
46
return
47
47
end
48
48
49
+ function test_bridge_error_handler ()
50
+ for (err, flag) in (
51
+ ErrorException (" abc" ) => false ,
52
+ MOI. GetAttributeNotAllowed (MOI. ObjectiveSense ()) => false ,
53
+ MOI. GetAttributeNotAllowed (MOI. ConstraintFunction ()) => true ,
54
+ )
55
+ @test_throws err try
56
+ @assert false
57
+ catch
58
+ MOI. Bridges. _runtests_error_handler (err, false )
59
+ end
60
+ if flag
61
+ @test MOI. Bridges. _runtests_error_handler (err, true ) === nothing
62
+ else
63
+ @test_throws err try
64
+ @assert false
65
+ catch
66
+ MOI. Bridges. _runtests_error_handler (err, true )
67
+ end
68
+ end
69
+ end
70
+ return
71
+ end
72
+
49
73
function test_zeros ()
50
74
mock = MOI. Utilities. MockOptimizer (MOI. Utilities. Model {Float64} ())
51
75
bridged_mock = MOI. Bridges. Variable. Zeros {Float64} (mock)
You can’t perform that action at this time.
0 commit comments