Skip to content

Commit ef8e15f

Browse files
authored
[Test] remove supports_optimize in favor of standard exclude (#1437)
1 parent e51754f commit ef8e15f

File tree

5 files changed

+11
-25
lines changed

5 files changed

+11
-25
lines changed

docs/src/submodules/Test/overview.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@ function test_unit_optimize!_twice(
172172
model::MOI.ModelLike,
173173
config::Config{T},
174174
) where {T}
175-
if !config.supports_optimize
176-
# Use `config` to modify the behavior of the tests. Since this test is
177-
# concerned with `optimize!`, we should skip the test if
178-
# `config.solve == false`.
179-
return
180-
end
181175
# Use the `@requires` macro to check conditions that the test function
182176
# requires in order to run. Models failing this `@requires` check will
183177
# silently skip the test.
@@ -186,6 +180,7 @@ function test_unit_optimize!_twice(
186180
MOI.SingleVariable,
187181
MOI.GreaterThan{Float64},
188182
)
183+
@requires _supports(config, MOI.optimize!)
189184
# If needed, you can test that the model is empty at the start of the test.
190185
# You can assume that this will be the case for tests run via `runtests`.
191186
# User's calling tests individually need to call `MOI.empty!` themselves.

src/Test/Test.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ using Test
1111
mutable struct Config{T<:Real}
1212
atol::T
1313
rtol::T
14-
supports_optimize::Bool
1514
optimal_status::MOI.TerminationStatusCode
1615
exclude::Vector{Any}
1716
end
@@ -21,7 +20,6 @@ end
2120
::Type{T} = Float64;
2221
atol::Real = Base.rtoldefault(T),
2322
rtol::Real = Base.rtoldefault(T),
24-
supports_optimize::Bool = true,
2523
optimal_status::MOI.TerminationStatusCode = MOI.OPTIMAL,
2624
exclude::Vector{Any} = Any[],
2725
) where {T}
@@ -34,13 +32,12 @@ Return an object that is used to configure various tests.
3432
when comparing solutions.
3533
* `rtol::Real = Base.rtoldefault(T)`: Control the relative tolerance used
3634
when comparing solutions.
37-
* `supports_optimize::Bool = true`: Set to `false` to skip tests requiring a
38-
call to [`MOI.optimize!`](@ref)
3935
* `optimal_status = MOI.OPTIMAL`: Set to `MOI.LOCALLY_SOLVED` if the solver
4036
cannot prove global optimality.
4137
* `exclude = Vector{Any}`: Pass attributes or functions to `exclude` to skip
4238
parts of tests that require certain functionality. Common arguments include:
4339
- `MOI.delete` to skip deletion-related tests
40+
- `MOI.optimize!` to skip optimize-related tests
4441
- `MOI.ConstraintDual` to skip dual-related tests
4542
- `MOI.VariableName` to skip setting variable names
4643
- `MOI.ConstraintName` to skip setting constraint names
@@ -66,18 +63,16 @@ function Config(
6663
::Type{T} = Float64;
6764
atol::Real = Base.rtoldefault(T),
6865
rtol::Real = Base.rtoldefault(T),
69-
supports_optimize::Bool = true,
7066
optimal_status::MOI.TerminationStatusCode = MOI.OPTIMAL,
7167
exclude::Vector{Any} = Any[],
7268
) where {T<:Real}
73-
return Config{T}(atol, rtol, supports_optimize, optimal_status, exclude)
69+
return Config{T}(atol, rtol, optimal_status, exclude)
7470
end
7571

7672
function Base.copy(config::Config{T}) where {T}
7773
return Config{T}(
7874
config.atol,
7975
config.rtol,
80-
config.supports_optimize,
8176
config.optimal_status,
8277
copy(config.exclude),
8378
)
@@ -344,7 +339,7 @@ function _test_model_solution(
344339
constraint_primal = nothing,
345340
constraint_dual = nothing,
346341
) where {T}
347-
if !config.supports_optimize
342+
if !_supports(config, MOI.optimize!)
348343
return
349344
end
350345
MOI.optimize!(model)

src/Test/test_attribute.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ Test that the [`MOI.RawStatusString`](@ref) attribute is implemented for
3333
`model`.
3434
"""
3535
function test_attribute_RawStatusString(model::MOI.ModelLike, config::Config)
36-
if !config.supports_optimize || !_supports(config, MOI.RawStatusString)
37-
return
38-
end
36+
@requires _supports(config, MOI.optimize!)
37+
@requires _supports(config, MOI.RawStatusString)
3938
MOI.add_variable(model)
4039
MOI.optimize!(model)
4140
@test MOI.get(model, MOI.RawStatusString()) isa AbstractString
@@ -106,9 +105,8 @@ end
106105
Test that the [`MOI.SolveTimeSec`](@ref) attribute is implemented for `model`.
107106
"""
108107
function test_attribute_SolveTimeSec(model::MOI.ModelLike, config::Config)
109-
if !config.supports_optimize || !_supports(config, MOI.SolveTimeSec)
110-
return
111-
end
108+
@requires _supports(config, MOI.optimize!)
109+
@requires _supports(config, MOI.SolveTimeSec)
112110
MOI.add_variable(model)
113111
MOI.optimize!(model)
114112
@test MOI.get(model, MOI.SolveTimeSec()) >= 0.0

src/Test/test_modification.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,15 +795,15 @@ function test_modification_delete_variables_in_a_batch(
795795
@test MOI.is_valid(model, x)
796796
@test MOI.is_valid(model, y)
797797
@test MOI.is_valid(model, z)
798-
if config.supports_optimize
798+
if _supports(config, MOI.optimize!)
799799
MOI.optimize!(model)
800800
@test isapprox(MOI.get(model, MOI.ObjectiveValue()), 6.0, config)
801801
end
802802
MOI.delete(model, [x, z])
803803
@test !MOI.is_valid(model, x)
804804
@test MOI.is_valid(model, y)
805805
@test !MOI.is_valid(model, z)
806-
if config.supports_optimize
806+
if _supports(config, MOI.optimize!)
807807
MOI.optimize!(model)
808808
@test isapprox(MOI.get(model, MOI.ObjectiveValue()), 2.0, config)
809809
end

src/Test/test_objective.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ function test_objective_ObjectiveFunction_blank(
136136
model::MOI.ModelLike,
137137
config::Config,
138138
)
139-
if !_supports(config, MOI.optimize!)
140-
return
141-
end
139+
@requires _supports(config, MOI.optimize!)
142140
obj_attr = MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()
143141
@requires MOI.supports(model, obj_attr)
144142
x = MOI.add_variable(model)

0 commit comments

Comments
 (0)