Skip to content

Commit 68fa4f5

Browse files
committed
Update
1 parent 50c1c19 commit 68fa4f5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Test/test_attribute.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function test_attribute_TimeLimitSec(model::MOI.AbstractOptimizer, ::Config)
172172
try
173173
return MOI.get(model, MOI.TimeLimitSec())
174174
catch err
175-
@assert err isa MOI.GetAttributeNotAllowed(MOI.TimeLimitSec())
175+
@assert err isa MOI.GetAttributeNotAllowed{MOI.TimeLimitSec}
176176
end
177177
return
178178
end

test/Test/Test.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,30 @@ function test_error_handler()
246246
return
247247
end
248248

249+
"Test a model that errors getting time limit unless it was previously set"
250+
mutable struct ModelTimeLimitSecErrorIfNotSet <: MOI.AbstractOptimizer
251+
time_limit::Union{Missing,Nothing,Float64}
252+
end
253+
254+
MOI.supports(::ModelTimeLimitSecErrorIfNotSet, ::MOI.TimeLimitSec) = true
255+
256+
function MOI.get(model::ModelTimeLimitSecErrorIfNotSet, attr::MOI.TimeLimitSec)
257+
if model.time_limit === missing
258+
throw(MOI.GetAttributeNotAllowed(attr))
259+
end
260+
return model.time_limit::Union{Nothing,Float64}
261+
end
262+
263+
function MOI.set(model::ModelTimeLimitSecErrorIfNotSet, ::MOI.TimeLimitSec, v)
264+
model.time_limit = v
265+
return
266+
end
267+
268+
function test_attribute_TimeLimitSec()
269+
model = ModelTimeLimitSecErrorIfNotSet(missing)
270+
MOI.Test.test_attribute_TimeLimitSec(model, MOI.Test.Config())
271+
end
272+
249273
end # module
250274

251275
TestTest.runtests()

0 commit comments

Comments
 (0)