opencobra / optlang

optlang - sympy based mathematical programming language
http://optlang.readthedocs.org/
Apache License 2.0
244 stars 51 forks source link

Multiple AssertionErrors occurrences in tests (Debian sid) #268

Closed NGC2023 closed 1 month ago

NGC2023 commented 1 month ago

Hi,

There are several AssertionError occurrences in tests during the build process in Debian sid. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1079740

self = <optlang.tests.test_glpk_exact_interface.ModelTestCase testMethod=test_objective_expression_includes_constant>

    def test_objective_expression_includes_constant(self):
        objective = self.model.objective
        self.model.objective = self.interface.Objective(objective.expression + 3)
        self.model.update()
>       self.assertEqual((self.model.objective.expression - (objective.expression + 3.)).expand(), 0.)
E       AssertionError: 0 != 0.0

optlang/tests/abstract_test_cases.py:826: AssertionError

Following patch should help fix the issue,

--- a/src/optlang/tests/abstract_test_cases.py
+++ b/src/optlang/tests/abstract_test_cases.py
@@ -22,6 +22,7 @@ import unittest
 from functools import partial

 import sympy
+from sympy import simplify

 import optlang
 from optlang import interface, symbolics
@@ -823,7 +824,7 @@ class AbstractModelTestCase(unittest.Tes
         objective = self.model.objective
         self.model.objective = self.interface.Objective(objective.expression + 3)
         self.model.update()
-        self.assertEqual((self.model.objective.expression - (objective.expression + 3.)).expand(), 0.)
+        self.assertEqual(simplify(self.model.objective.expression - (objective.expression + 3.)), 0)

     def test_is_integer(self):
         model = self.model