Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions docs/src/submodules/Test/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
11 changes: 3 additions & 8 deletions src/Test/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -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),
)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions src/Test/test_attribute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Test/test_modification.jl
Original file line number Diff line number Diff line change
Expand Up @@ -795,15 +795,15 @@ 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
MOI.delete(model, [x, z])
@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
Expand Down
4 changes: 1 addition & 3 deletions src/Test/test_objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down