@@ -27,12 +27,10 @@ function test_errors_fallback_AddVariableNotAllowed()
27
27
try
28
28
MOI. add_variable (model)
29
29
catch err
30
- @test sprint (showerror, err) ==
31
- " MathOptInterface.AddVariableNotAllowed:" *
32
- " Adding variables cannot be performed. You may want to use a" *
33
- " `CachingOptimizer` in `AUTOMATIC` mode or you may need to call" *
34
- " `reset_optimizer` before doing this operation if the" *
35
- " `CachingOptimizer` is in `MANUAL` mode."
30
+ contents = sprint (showerror, err)
31
+ @test occursin (" $(MOI. AddVariableNotAllowed) " , contents)
32
+ @test occursin (" Adding variables cannot be performed" , contents)
33
+ @test occursin (" ## Fixing this error" , contents)
36
34
end
37
35
@test_throws MOI. AddVariableNotAllowed MOI. add_variables (model, 2 )
38
36
return
@@ -104,13 +102,14 @@ function test_errors_add_constraint()
104
102
try
105
103
MOI. add_constraint (model, vi, MOI. EqualTo (0.0 ))
106
104
catch err
107
- @test sprint (showerror, err) ==
108
- " $(MOI. AddConstraintNotAllowed{MOI. VariableIndex,MOI. EqualTo{Float64}}) :" *
109
- " Adding `$MOI .VariableIndex`-in-`$MOI .EqualTo{Float64}`" *
110
- " constraints cannot be performed. You may want to use a" *
111
- " `CachingOptimizer` in `AUTOMATIC` mode or you may need to call" *
112
- " `reset_optimizer` before doing this operation if the" *
113
- " `CachingOptimizer` is in `MANUAL` mode."
105
+ contents = sprint (showerror, err)
106
+ F, S = MOI. VariableIndex, MOI. EqualTo{Float64}
107
+ @test occursin (" $(MOI. AddConstraintNotAllowed{F,S}) " , contents)
108
+ @test occursin (
109
+ " Adding `$F `-in-`$S ` constraints cannot be performed" ,
110
+ contents,
111
+ )
112
+ @test occursin (" ## Fixing this error" , contents)
114
113
end
115
114
@test_throws (
116
115
MOI. AddConstraintNotAllowed,
@@ -139,23 +138,19 @@ function test_errors_DeleteNotAllowed()
139
138
try
140
139
MOI. delete (model, vi)
141
140
catch err
142
- @test sprint (showerror, err) ==
143
- " $(MOI. DeleteNotAllowed{typeof (vi)}) : Deleting the index $vi " *
144
- " cannot be performed. You may want to use a `CachingOptimizer` " *
145
- " in `AUTOMATIC` mode or you may need to call `reset_optimizer` " *
146
- " before doing this operation if the `CachingOptimizer` is in " *
147
- " `MANUAL` mode."
141
+ contents = sprint (showerror, err)
142
+ @test occursin (" $(MOI. DeleteNotAllowed{typeof (vi)}) " , contents)
143
+ @test occursin (" Deleting the index $vi cannot be performed" , contents)
144
+ @test occursin (" ## Fixing this error" , contents)
148
145
end
149
146
@test_throws MOI. DeleteNotAllowed{typeof (ci)} MOI. delete (model, ci)
150
147
try
151
148
MOI. delete (model, ci)
152
149
catch err
153
- @test sprint (showerror, err) ==
154
- " $(MOI. DeleteNotAllowed{typeof (ci)}) : Deleting the index $ci " *
155
- " cannot be performed. You may want to use a `CachingOptimizer` " *
156
- " in `AUTOMATIC` mode or you may need to call `reset_optimizer` " *
157
- " before doing this operation if the `CachingOptimizer` is in " *
158
- " `MANUAL` mode."
150
+ contents = sprint (showerror, err)
151
+ @test occursin (" $(MOI. DeleteNotAllowed{typeof (ci)}) " , contents)
152
+ @test occursin (" Deleting the index $ci cannot be performed" , contents)
153
+ @test occursin (" ## Fixing this error" , contents)
159
154
end
160
155
return
161
156
end
@@ -244,14 +239,14 @@ function test_errors_ModifyNotAllowed_constraint()
244
239
change = MOI. ScalarConstantChange (1.0 )
245
240
err = MOI. ModifyConstraintNotAllowed (ci, change)
246
241
@test_throws err MOI. modify (model, ci, change)
247
- @test sprint (showerror, err) ==
248
- " $(MOI . ModifyConstraintNotAllowed{MOI . VariableIndex,MOI . EqualTo{Float64},MOI . ScalarConstantChange{Float64}}) : " *
249
- " Modifying the constraints $(MOI . ConstraintIndex {MOI.VariableIndex,MOI.EqualTo{Float64}} ( 1 )) " *
250
- " with MathOptInterface.ScalarConstantChange{Float64}(1.0) cannot" *
251
- " be performed. You may want to use a `CachingOptimizer` in " *
252
- " `AUTOMATIC` mode or you may need to call `reset_optimizer` " *
253
- " before doing this operation if the `CachingOptimizer` is in " *
254
- " `MANUAL` mode. "
242
+ contents = sprint (showerror, err)
243
+ @test occursin ( " $(typeof (err)) : " , contents)
244
+ @test occursin (
245
+ " Modifying the constraints $ci with $change cannot be performed " ,
246
+ contents,
247
+ )
248
+ @test occursin ( " ## Fixing this error " , contents)
249
+ return
255
250
end
256
251
257
252
function test_errors_ModifyNotAllowed_objective ()
@@ -260,13 +255,14 @@ function test_errors_ModifyNotAllowed_objective()
260
255
attr = MOI. ObjectiveFunction {MOI.VariableIndex} ()
261
256
err = MOI. ModifyObjectiveNotAllowed (change)
262
257
@test_throws err MOI. modify (model, attr, change)
263
- @test sprint (showerror, err) ==
264
- " $(MOI. ModifyObjectiveNotAllowed{MOI. ScalarConstantChange{Float64}}) :" *
265
- " Modifying the objective function with $(MOI. ScalarConstantChange {Float64} (1.0 )) " *
266
- " cannot be performed. You may want to use a `CachingOptimizer`" *
267
- " in `AUTOMATIC` mode or you may need to call `reset_optimizer`" *
268
- " before doing this operation if the `CachingOptimizer` is in" *
269
- " `MANUAL` mode."
258
+ contents = sprint (showerror, err)
259
+ @test occursin (" $(typeof (err)) :" , contents)
260
+ @test occursin (
261
+ " Modifying the objective function with $change cannot be performed" ,
262
+ contents,
263
+ )
264
+ @test occursin (" ## Fixing this error" , contents)
265
+ return
270
266
end
271
267
272
268
function test_errors_show_SetAttributeNotAllowed ()
@@ -276,26 +272,22 @@ function test_errors_show_SetAttributeNotAllowed()
276
272
@test sprint (showerror, MOI. UnsupportedAttribute (MOI. Name (), " Message" )) ==
277
273
" $MOI .UnsupportedAttribute{$MOI .Name}:" *
278
274
" Attribute $MOI .Name() is not supported by the model: Message"
279
- @test sprint (showerror, MOI. SetAttributeNotAllowed (MOI. Name ())) ==
280
- " $MOI .SetAttributeNotAllowed{$MOI .Name}:" *
281
- " Setting attribute $MOI .Name() cannot be performed. You may want to use" *
282
- " a `CachingOptimizer` in `AUTOMATIC` mode or you may need to call" *
283
- " `reset_optimizer` before doing this operation if the" *
284
- " `CachingOptimizer` is in `MANUAL` mode."
285
- @test sprint (
286
- showerror,
287
- MOI. SetAttributeNotAllowed (MOI. Name (), " Message" ),
288
- ) ==
289
- " $MOI .SetAttributeNotAllowed{$MOI .Name}:" *
290
- " Setting attribute $MOI .Name() cannot be performed: Message You may want" *
291
- " to use a `CachingOptimizer` in `AUTOMATIC` mode or you may need to call" *
292
- " `reset_optimizer` before doing this operation if the `CachingOptimizer`" *
293
- " is in `MANUAL` mode." ==
294
- " $MOI .SetAttributeNotAllowed{$MOI .Name}:" *
295
- " Setting attribute $MOI .Name() cannot be performed: Message You may want" *
296
- " to use a `CachingOptimizer` in `AUTOMATIC` mode or you may need to call" *
297
- " `reset_optimizer` before doing this operation if the `CachingOptimizer`" *
298
- " is in `MANUAL` mode."
275
+ contents = sprint (showerror, MOI. SetAttributeNotAllowed (MOI. Name ()))
276
+ @test occursin (" $MOI .SetAttributeNotAllowed{$MOI .Name}:" , contents)
277
+ @test occursin (
278
+ " Setting attribute $(MOI. Name ()) cannot be performed" ,
279
+ contents,
280
+ )
281
+ @test occursin (" ## Fixing this error" , contents)
282
+ err = MOI. SetAttributeNotAllowed (MOI. Name (), " Message" )
283
+ contents = sprint (showerror, err)
284
+ @test occursin (" $(typeof (err)) " , contents)
285
+ @test occursin (" Message" , contents)
286
+ @test occursin (
287
+ " Setting attribute $(MOI. Name ()) cannot be performed" ,
288
+ contents,
289
+ )
290
+ @test occursin (" ## Fixing this error" , contents)
299
291
return
300
292
end
301
293
@@ -352,11 +344,13 @@ function test_get_fallback_error()
352
344
MOI. get (model, MOI. SolveTimeSec ()),
353
345
)
354
346
err = MOI. GetAttributeNotAllowed (MOI. SolveTimeSec (), " " )
355
- @test sprint (showerror, err) ==
356
- " $(typeof (err)) : Getting attribute $(MOI. SolveTimeSec ()) cannot be " *
357
- " performed. You may want to use a `CachingOptimizer` in " *
358
- " `AUTOMATIC` mode or you may need to call `reset_optimizer` before " *
359
- " doing this operation if the `CachingOptimizer` is in `MANUAL` mode."
347
+ contents = sprint (showerror, err)
348
+ @test occursin (" $(typeof (err)) :" , contents)
349
+ @test occursin (
350
+ " Getting attribute $(MOI. SolveTimeSec ()) cannot be performed" ,
351
+ contents,
352
+ )
353
+ @test occursin (" ## Fixing this error" , contents)
360
354
return
361
355
end
362
356
0 commit comments