44from pyoptinterface import knitro
55import pyoptinterface as poi
66
7-
87pytestmark = pytest .mark .skipif (
98 not knitro .is_library_loaded (), reason = "KNITRO library is not loaded"
109)
@@ -166,6 +165,7 @@ def test_model_init_with_empty_env_after_start():
166165 env .start ()
167166 assert knitro .Model (env = env ) is not None
168167
168+
169169def test_model_dirty ():
170170 """Test the dirty method."""
171171 model = knitro .Model ()
@@ -256,20 +256,63 @@ def test_number_of_constraints():
256256def test_supports_attribute_methods ():
257257 """Test supports_*_attribute() static methods."""
258258 assert knitro .Model .supports_variable_attribute (poi .VariableAttribute .Value ) is True
259- assert knitro .Model .supports_variable_attribute (poi .VariableAttribute .LowerBound ) is True
260- assert knitro .Model .supports_variable_attribute (poi .VariableAttribute .LowerBound , setable = True ) is True
261- assert knitro .Model .supports_variable_attribute (poi .VariableAttribute .Value , setable = True ) is False
262-
263- assert knitro .Model .supports_constraint_attribute (poi .ConstraintAttribute .Primal ) is True
264- assert knitro .Model .supports_constraint_attribute (poi .ConstraintAttribute .Name ) is True
265- assert knitro .Model .supports_constraint_attribute (poi .ConstraintAttribute .Name , setable = True ) is True
266-
267- assert knitro .Model .supports_model_attribute (poi .ModelAttribute .ObjectiveValue ) is True
259+ assert (
260+ knitro .Model .supports_variable_attribute (poi .VariableAttribute .LowerBound )
261+ is True
262+ )
263+ assert (
264+ knitro .Model .supports_variable_attribute (
265+ poi .VariableAttribute .LowerBound , setable = True
266+ )
267+ is True
268+ )
269+ assert (
270+ knitro .Model .supports_variable_attribute (
271+ poi .VariableAttribute .Value , setable = True
272+ )
273+ is False
274+ )
275+
276+ assert (
277+ knitro .Model .supports_constraint_attribute (poi .ConstraintAttribute .Primal )
278+ is True
279+ )
280+ assert (
281+ knitro .Model .supports_constraint_attribute (poi .ConstraintAttribute .Name ) is True
282+ )
283+ assert (
284+ knitro .Model .supports_constraint_attribute (
285+ poi .ConstraintAttribute .Name , setable = True
286+ )
287+ is True
288+ )
289+
290+ assert (
291+ knitro .Model .supports_model_attribute (poi .ModelAttribute .ObjectiveValue ) is True
292+ )
268293 assert knitro .Model .supports_model_attribute (poi .ModelAttribute .SolverName ) is True
269- assert knitro .Model .supports_model_attribute (poi .ModelAttribute .Silent , setable = True ) is True
270- assert knitro .Model .supports_model_attribute (poi .ModelAttribute .ObjectiveValue , setable = True ) is False
271- assert knitro .Model .supports_model_attribute (poi .ModelAttribute .NumberOfThreads , setable = True ) is True
272- assert knitro .Model .supports_model_attribute (poi .ModelAttribute .TimeLimitSec , setable = True ) is True
294+ assert (
295+ knitro .Model .supports_model_attribute (poi .ModelAttribute .Silent , setable = True )
296+ is True
297+ )
298+ assert (
299+ knitro .Model .supports_model_attribute (
300+ poi .ModelAttribute .ObjectiveValue , setable = True
301+ )
302+ is False
303+ )
304+ assert (
305+ knitro .Model .supports_model_attribute (
306+ poi .ModelAttribute .NumberOfThreads , setable = True
307+ )
308+ is True
309+ )
310+ assert (
311+ knitro .Model .supports_model_attribute (
312+ poi .ModelAttribute .TimeLimitSec , setable = True
313+ )
314+ is True
315+ )
273316
274317
275318def test_model_attribute_solver_info ():
@@ -334,11 +377,21 @@ def test_set_model_attribute_objective_sense():
334377 model = knitro .Model ()
335378 model .add_variable (lb = 0.0 , ub = 10.0 )
336379
337- model .set_model_attribute (poi .ModelAttribute .ObjectiveSense , poi .ObjectiveSense .Maximize )
338- assert model .get_model_attribute (poi .ModelAttribute .ObjectiveSense ) == poi .ObjectiveSense .Maximize
380+ model .set_model_attribute (
381+ poi .ModelAttribute .ObjectiveSense , poi .ObjectiveSense .Maximize
382+ )
383+ assert (
384+ model .get_model_attribute (poi .ModelAttribute .ObjectiveSense )
385+ == poi .ObjectiveSense .Maximize
386+ )
339387
340- model .set_model_attribute (poi .ModelAttribute .ObjectiveSense , poi .ObjectiveSense .Minimize )
341- assert model .get_model_attribute (poi .ModelAttribute .ObjectiveSense ) == poi .ObjectiveSense .Minimize
388+ model .set_model_attribute (
389+ poi .ModelAttribute .ObjectiveSense , poi .ObjectiveSense .Minimize
390+ )
391+ assert (
392+ model .get_model_attribute (poi .ModelAttribute .ObjectiveSense )
393+ == poi .ObjectiveSense .Minimize
394+ )
342395
343396
344397def test_set_model_attribute_silent ():
@@ -434,7 +487,9 @@ def test_variable_attribute_domain():
434487 model = knitro .Model ()
435488 x = model .add_variable (lb = 0.0 , ub = 10.0 )
436489
437- model .set_variable_attribute (x , poi .VariableAttribute .Domain , poi .VariableDomain .Integer )
490+ model .set_variable_attribute (
491+ x , poi .VariableAttribute .Domain , poi .VariableDomain .Integer
492+ )
438493
439494 model .set_objective (x , poi .ObjectiveSense .Minimize )
440495 model .add_linear_constraint (x , poi .ConstraintSense .GreaterEqual , 2.5 )
@@ -448,7 +503,9 @@ def test_constraint_attribute_name():
448503 model = knitro .Model ()
449504 x = model .add_variable (lb = 0.0 , ub = 10.0 )
450505
451- con = model .add_linear_constraint (x , poi .ConstraintSense .LessEqual , 5.0 , name = "my_con" )
506+ con = model .add_linear_constraint (
507+ x , poi .ConstraintSense .LessEqual , 5.0 , name = "my_con"
508+ )
452509
453510 name = model .get_constraint_attribute (con , poi .ConstraintAttribute .Name )
454511 assert name == "my_con"
0 commit comments