You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
921 B

  1. # -*- coding: utf-8 -*-
  2. # © 2016 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. import openerp.tests.common as common
  5. from ..models.mis_safe_eval import mis_safe_eval, DataError, NameDataError
  6. class TestMisSafeEval(common.TransactionCase):
  7. def test_nominal(self):
  8. val = mis_safe_eval('a + 1', {'a': 1})
  9. self.assertEqual(val, 2)
  10. def test_exceptions(self):
  11. val = mis_safe_eval('1/0', {}) # division by zero
  12. self.assertTrue(isinstance(val, DataError))
  13. self.assertEqual(val.name, '#DIV/0')
  14. val = mis_safe_eval('1a', {}) # syntax error
  15. self.assertTrue(isinstance(val, DataError))
  16. self.assertEqual(val.name, '#ERR')
  17. def test_name_error(self):
  18. val = mis_safe_eval('a + 1', {})
  19. self.assertTrue(isinstance(val, NameDataError))
  20. self.assertEqual(val.name, '#NAME')