diff --git a/docs/src/submodules/Test/overview.md b/docs/src/submodules/Test/overview.md index 581a4c3504..c313eefc70 100644 --- a/docs/src/submodules/Test/overview.md +++ b/docs/src/submodules/Test/overview.md @@ -172,12 +172,6 @@ function test_unit_optimize!_twice( model::MOI.ModelLike, config::Config{T}, ) where {T} - if !config.supports_optimize - # Use `config` to modify the behavior of the tests. Since this test is - # concerned with `optimize!`, we should skip the test if - # `config.solve == false`. - return - end # Use the `@requires` macro to check conditions that the test function # requires in order to run. Models failing this `@requires` check will # silently skip the test. @@ -186,6 +180,7 @@ function test_unit_optimize!_twice( MOI.SingleVariable, MOI.GreaterThan{Float64}, ) + @requires _supports(config, MOI.optimize!) # If needed, you can test that the model is empty at the start of the test. # You can assume that this will be the case for tests run via `runtests`. # User's calling tests individually need to call `MOI.empty!` themselves. diff --git a/src/Test/Test.jl b/src/Test/Test.jl index 81da55dc66..f2e3a9e046 100644 --- a/src/Test/Test.jl +++ b/src/Test/Test.jl @@ -11,7 +11,6 @@ using Test mutable struct Config{T<:Real} atol::T rtol::T - supports_optimize::Bool optimal_status::MOI.TerminationStatusCode exclude::Vector{Any} end @@ -21,7 +20,6 @@ end ::Type{T} = Float64; atol::Real = Base.rtoldefault(T), rtol::Real = Base.rtoldefault(T), - supports_optimize::Bool = true, optimal_status::MOI.TerminationStatusCode = MOI.OPTIMAL, exclude::Vector{Any} = Any[], ) where {T} @@ -34,13 +32,12 @@ Return an object that is used to configure various tests. when comparing solutions. * `rtol::Real = Base.rtoldefault(T)`: Control the relative tolerance used when comparing solutions. - * `supports_optimize::Bool = true`: Set to `false` to skip tests requiring a - call to [`MOI.optimize!`](@ref) * `optimal_status = MOI.OPTIMAL`: Set to `MOI.LOCALLY_SOLVED` if the solver cannot prove global optimality. * `exclude = Vector{Any}`: Pass attributes or functions to `exclude` to skip parts of tests that require certain functionality. Common arguments include: - `MOI.delete` to skip deletion-related tests + - `MOI.optimize!` to skip optimize-related tests - `MOI.ConstraintDual` to skip dual-related tests - `MOI.VariableName` to skip setting variable names - `MOI.ConstraintName` to skip setting constraint names @@ -66,18 +63,16 @@ function Config( ::Type{T} = Float64; atol::Real = Base.rtoldefault(T), rtol::Real = Base.rtoldefault(T), - supports_optimize::Bool = true, optimal_status::MOI.TerminationStatusCode = MOI.OPTIMAL, exclude::Vector{Any} = Any[], ) where {T<:Real} - return Config{T}(atol, rtol, supports_optimize, optimal_status, exclude) + return Config{T}(atol, rtol, optimal_status, exclude) end function Base.copy(config::Config{T}) where {T} return Config{T}( config.atol, config.rtol, - config.supports_optimize, config.optimal_status, copy(config.exclude), ) @@ -344,7 +339,7 @@ function _test_model_solution( constraint_primal = nothing, constraint_dual = nothing, ) where {T} - if !config.supports_optimize + if !_supports(config, MOI.optimize!) return end MOI.optimize!(model) diff --git a/src/Test/test_attribute.jl b/src/Test/test_attribute.jl index 7c3241b4f4..16948f37e8 100644 --- a/src/Test/test_attribute.jl +++ b/src/Test/test_attribute.jl @@ -33,9 +33,8 @@ Test that the [`MOI.RawStatusString`](@ref) attribute is implemented for `model`. """ function test_attribute_RawStatusString(model::MOI.ModelLike, config::Config) - if !config.supports_optimize || !_supports(config, MOI.RawStatusString) - return - end + @requires _supports(config, MOI.optimize!) + @requires _supports(config, MOI.RawStatusString) MOI.add_variable(model) MOI.optimize!(model) @test MOI.get(model, MOI.RawStatusString()) isa AbstractString @@ -106,9 +105,8 @@ end Test that the [`MOI.SolveTimeSec`](@ref) attribute is implemented for `model`. """ function test_attribute_SolveTimeSec(model::MOI.ModelLike, config::Config) - if !config.supports_optimize || !_supports(config, MOI.SolveTimeSec) - return - end + @requires _supports(config, MOI.optimize!) + @requires _supports(config, MOI.SolveTimeSec) MOI.add_variable(model) MOI.optimize!(model) @test MOI.get(model, MOI.SolveTimeSec()) >= 0.0 diff --git a/src/Test/test_modification.jl b/src/Test/test_modification.jl index bcc59c90ea..670e815d89 100644 --- a/src/Test/test_modification.jl +++ b/src/Test/test_modification.jl @@ -795,7 +795,7 @@ function test_modification_delete_variables_in_a_batch( @test MOI.is_valid(model, x) @test MOI.is_valid(model, y) @test MOI.is_valid(model, z) - if config.supports_optimize + if _supports(config, MOI.optimize!) MOI.optimize!(model) @test isapprox(MOI.get(model, MOI.ObjectiveValue()), 6.0, config) end @@ -803,7 +803,7 @@ function test_modification_delete_variables_in_a_batch( @test !MOI.is_valid(model, x) @test MOI.is_valid(model, y) @test !MOI.is_valid(model, z) - if config.supports_optimize + if _supports(config, MOI.optimize!) MOI.optimize!(model) @test isapprox(MOI.get(model, MOI.ObjectiveValue()), 2.0, config) end diff --git a/src/Test/test_objective.jl b/src/Test/test_objective.jl index df23f4488b..6027ed0655 100644 --- a/src/Test/test_objective.jl +++ b/src/Test/test_objective.jl @@ -136,9 +136,7 @@ function test_objective_ObjectiveFunction_blank( model::MOI.ModelLike, config::Config, ) - if !_supports(config, MOI.optimize!) - return - end + @requires _supports(config, MOI.optimize!) obj_attr = MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}() @requires MOI.supports(model, obj_attr) x = MOI.add_variable(model)