Skip to content

Commit

Permalink
ensure errors are not logged when using exception=False
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbynum committed Apr 26, 2021
1 parent b6ad0e8 commit 26b6f58
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pyomo/core/tests/unit/test_numeric_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from filecmp import cmp
import pyomo.common.unittest as unittest
from pyomo.common.log import LoggingIntercept
from io import StringIO

from pyomo.environ import ConcreteModel, AbstractModel, RangeSet, Var, Param, Set, Constraint, ConstraintList, Expression, Objective, Reals, ExternalFunction, PositiveReals, log10, exp, floor, ceil, log, cos, sin, tan, acos, asin, atan, sinh, cosh, tanh, acosh, asinh, atanh, sqrt, value, quicksum, sum_product, is_fixed, is_constant
from pyomo.kernel import variable, expression, objective
Expand Down Expand Up @@ -5244,5 +5246,17 @@ def con_rule(model):
self.assertEqual(polynomial_degree(m.c1.body), 1)


class TestEvaluation(unittest.TestCase):
def test_log_error(self):
m = ConcreteModel()
m.x = Var()
e = m.x**2
os = StringIO()
with LoggingIntercept(os, 'pyomo'):
e_val = value(e, exception=False)
self.assertIsNone(e_val)
self.assertEqual(os.getvalue(), '')


if __name__ == "__main__":
unittest.main()

0 comments on commit 26b6f58

Please sign in to comment.