Skip to content

Commit 671b53f

Browse files
authored
[Test] fix test_model_copy_to_ tests (#1686)
1 parent 2e7b323 commit 671b53f

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

src/Test/test_model.jl

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,16 @@ function test_model_empty(model::MOI.ModelLike, ::Config)
559559
end
560560

561561
"""
562-
test_model_copy_to_UnsupportedConstraint(
563-
model::MOI.ModelLike,
564-
::Config,
565-
)
562+
test_model_copy_to_UnsupportedConstraint(model::MOI.ModelLike, ::Config)
563+
564+
Test an error is thrown when a constraint is unsupported.
566565
567-
Test `MOI.copy_to` when a constraint is unsupported.
566+
!!! note
567+
This function uses the two-argument `MOI.optimize!`. This ensures that we
568+
test three cases:
569+
* models implementing the two-argument method
570+
* models using the generic fallback and erroring on `copy_to`
571+
* models using the generic fallback and erroring on `optimize!`.
568572
"""
569573
function test_model_copy_to_UnsupportedConstraint(
570574
model::MOI.ModelLike,
@@ -577,18 +581,22 @@ function test_model_copy_to_UnsupportedConstraint(
577581
)
578582
@test_throws(
579583
MOI.UnsupportedConstraint,
580-
MOI.copy_to(model, BadConstraintModel()),
584+
MOI.optimize!(model, BadConstraintModel()),
581585
)
582586
return
583587
end
584588

585589
"""
586-
test_model_copy_to_UnsupportedAttribute(
587-
model::MOI.ModelLike,
588-
::Config,
589-
)
590+
test_model_copy_to_UnsupportedAttribute(model::MOI.ModelLike, ::Config)
591+
592+
Test an error is thrown when an attribute is unsupported.
590593
591-
Test `MOI.copy_to` when an attribute is unsupported.
594+
!!! note
595+
This function uses the two-argument `MOI.optimize!`. This ensures that we
596+
test three cases:
597+
* models implementing the two-argument method
598+
* models using the generic fallback and erroring on `copy_to`
599+
* models using the generic fallback and erroring on `optimize!`.
592600
"""
593601
function test_model_copy_to_UnsupportedAttribute(
594602
model::MOI.ModelLike,
@@ -598,13 +606,13 @@ function test_model_copy_to_UnsupportedAttribute(
598606
@test !MOI.supports(model, UnknownModelAttribute())
599607
@test_throws(
600608
MOI.UnsupportedAttribute,
601-
MOI.copy_to(model, BadModelAttributeModel(T)),
609+
MOI.optimize!(model, BadModelAttributeModel(T)),
602610
)
603611
# VariableAttribute
604612
@test !MOI.supports(model, UnknownVariableAttribute(), MOI.VariableIndex)
605613
@test_throws(
606614
MOI.UnsupportedAttribute,
607-
MOI.copy_to(model, BadVariableAttributeModel(T)),
615+
MOI.optimize!(model, BadVariableAttributeModel(T)),
608616
)
609617
# ConstraintAttribute
610618
@test !MOI.supports(
@@ -614,7 +622,7 @@ function test_model_copy_to_UnsupportedAttribute(
614622
)
615623
@test_throws(
616624
MOI.UnsupportedAttribute,
617-
MOI.copy_to(model, BadConstraintAttributeModel(T)),
625+
MOI.optimize!(model, BadConstraintAttributeModel(T)),
618626
)
619627
return
620628
end

0 commit comments

Comments
 (0)