Browse Source

[IMP] mis_builder: tests for mis_safe_eval

pull/189/head
Stéphane Bidoul 9 years ago
parent
commit
c8901da5c9
  1. 26
      mis_builder/tests/test_mis_safe_eval.py

26
mis_builder/tests/test_mis_safe_eval.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import openerp.tests.common as common
from ..models.mis_safe_eval import mis_safe_eval, DataError
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):
with self.assertRaises(NameError):
mis_safe_eval('a + 1', {})
Loading…
Cancel
Save