From c733287fb1c86c868d46a1546658c95dad8e6282 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 10 Aug 2021 14:29:43 +1200 Subject: [PATCH 1/3] [Test] add a test for attributes after empty --- src/Test/test_attribute.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Test/test_attribute.jl b/src/Test/test_attribute.jl index bf9cf3afd1..d02ed2d775 100644 --- a/src/Test/test_attribute.jl +++ b/src/Test/test_attribute.jl @@ -167,3 +167,18 @@ function setup_test( MOI.set(model, MOI.TimeLimitSec(), nothing) return end + +""" + test_attribute_after_empty(model::MOI.AbstractOptimizer, config::Config) + +Test that optimizer attributes such as `Silent` are not cleared by `MOI.empty!`. +""" +function test_attribute_after_empty(model::MOI.AbstractOptimizer, ::Config) + @requires MOI.supports(model, MOI.Silent()) + @test MOI.get(model, MOI.Silent()) == false + MOI.set(model, MOI.Silent(), true) + @test MOI.get(model, MOI.Silent()) == true + MOI.empty!(model) + @test MOI.get(model, MOI.Silent()) == true + return +end From 9254f5bca15ed2c219363f681fc48e23a236a2b9 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 10 Aug 2021 14:34:14 +1200 Subject: [PATCH 2/3] Fix before leaving function --- src/Test/test_attribute.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Test/test_attribute.jl b/src/Test/test_attribute.jl index d02ed2d775..9d20bb5264 100644 --- a/src/Test/test_attribute.jl +++ b/src/Test/test_attribute.jl @@ -175,10 +175,14 @@ Test that optimizer attributes such as `Silent` are not cleared by `MOI.empty!`. """ function test_attribute_after_empty(model::MOI.AbstractOptimizer, ::Config) @requires MOI.supports(model, MOI.Silent()) - @test MOI.get(model, MOI.Silent()) == false - MOI.set(model, MOI.Silent(), true) - @test MOI.get(model, MOI.Silent()) == true - MOI.empty!(model) - @test MOI.get(model, MOI.Silent()) == true + current = MOI.get(model, MOI.Silent()) + for value in (true, false) + MOI.set(model, MOI.Silent(), value) + @test MOI.get(model, MOI.Silent()) == value + MOI.empty!(model) + @test MOI.get(model, MOI.Silent()) == value + end + # Make sure to reset the value before leaving this function! + MOI.set(model, MOI.Silent(), current) return end From 47629aba909cfa9cf0867f74a8587beb5a5d5cf5 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 10 Aug 2021 15:36:58 +1200 Subject: [PATCH 3/3] Update test_attribute.jl --- src/Test/test_attribute.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Test/test_attribute.jl b/src/Test/test_attribute.jl index 9d20bb5264..2107f3e45a 100644 --- a/src/Test/test_attribute.jl +++ b/src/Test/test_attribute.jl @@ -186,3 +186,5 @@ function test_attribute_after_empty(model::MOI.AbstractOptimizer, ::Config) MOI.set(model, MOI.Silent(), current) return end + +test_attribute_after_empty(::MOI.ModelLike, ::Config) = nothing