mirror of
https://gitlab.com/flectra-community/mis-builder.git
synced 2024-11-16 11:12:07 +00:00
26 lines
903 B
Python
26 lines
903 B
Python
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
|
|
|
import flectra.tests.common as common
|
|
|
|
from ..models.mis_safe_eval import DataError, NameDataError, mis_safe_eval
|
|
|
|
|
|
class TestMisSafeEval(common.TransactionCase):
|
|
def test_nominal(self):
|
|
val = mis_safe_eval("a + 1", {"a": 1})
|
|
self.assertEqual(val, 2)
|
|
|
|
def test_exceptions(self):
|
|
val = mis_safe_eval("1/0", {}) # division by zero
|
|
self.assertTrue(isinstance(val, DataError))
|
|
self.assertEqual(val.name, "#DIV/0")
|
|
val = mis_safe_eval("1a", {}) # syntax error
|
|
self.assertTrue(isinstance(val, DataError))
|
|
self.assertEqual(val.name, "#ERR")
|
|
|
|
def test_name_error(self):
|
|
val = mis_safe_eval("a + 1", {})
|
|
self.assertTrue(isinstance(val, NameDataError))
|
|
self.assertEqual(val.name, "#NAME")
|