Skip to content

Catching _supports error in tests #1757

@blegat

Description

@blegat

This does not work if the ConstraintFunction are in the exclude list of the tests:

try
f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], T(1))
c = MOI.add_constraint(model, f, MOI.EqualTo(T(2)))
@requires _supports(config, MOI.ConstraintFunction)
@test MOI.get(model, MOI.ConstraintFunction(), c) f
catch err
@test err == _error(MOI.EqualTo{T}, T(1))
end
try
f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], T(2))
c = MOI.add_constraint(model, f, MOI.GreaterThan(T(1)))
@requires _supports(config, MOI.ConstraintFunction)
@test MOI.get(model, MOI.ConstraintFunction(), c) f
catch err
@test err == _error(MOI.GreaterThan{T}, T(2))
end

You get:

test_model_ScalarFunctionConstantNotZero: Test Failed at /home/blegat/.julia/packages/MathOptInterface/IIN1o/src/Test/test_model.jl:754
  Expression: err == _error(MOI.EqualTo{T}, T(1))
   Evaluated: RequirementUnmet: _supports(config, MOI.ConstraintFunction) == MathOptInterface.ScalarFunctionConstantNotZero{Float64, MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}(1.0)
Stacktrace:
 [1] macro expansion
   @ ~/packages/julias/julia-1.7.1/share/julia/stdlib/v1.7/Test/src/Test.jl:445 [inlined]
 [2] test_model_ScalarFunctionConstantNotZero(model::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{SDPT3.Optimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, config::MathOptInterface.Test.Config{Float64})
   @ MathOptInterface.Test ~/.julia/packages/MathOptInterface/IIN1o/src/Test/test_model.jl:754
test_model_ScalarFunctionConstantNotZero: Test Failed at /home/blegat/.julia/packages/MathOptInterface/IIN1o/src/Test/test_model.jl:762
  Expression: err == _error(MOI.GreaterThan{T}, T(2))
   Evaluated: RequirementUnmet: _supports(config, MOI.ConstraintFunction) == MathOptInterface.ScalarFunctionConstantNotZero{Float64, MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.GreaterThan{Float64}}(2.0)
Stacktrace:
 [1] macro expansion
   @ ~/packages/julias/julia-1.7.1/share/julia/stdlib/v1.7/Test/src/Test.jl:445 [inlined]
 [2] test_model_ScalarFunctionConstantNotZero(model::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{SDPT3.Optimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, config::MathOptInterface.Test.Config{Float64})
   @ MathOptInterface.Test ~/.julia/packages/MathOptInterface/IIN1o/src/Test/test_model.jl:762

Detected while going from DeprecatedTest to Test in jump-dev/SDPT3.jl#15

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions