From 131b6bd58b7aaed997576fe363da2c80fdcb0a67 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Fri, 26 Jul 2019 16:13:02 +0200 Subject: Raise a ValueError in case of invalid unit in textutils.apply_units() The original KeyError comes from 57e242dffe89 which no justification. I believe it was meant to be a ValueError as in other errors in this function. Also, _ensure_correctly_typed() in cubicweb/web/formfields.py will catch ValueError. Adding a test for this. --- test/unittest_textutils.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/unittest_textutils.py b/test/unittest_textutils.py index 330d49c..2fa648a 100644 --- a/test/unittest_textutils.py +++ b/test/unittest_textutils.py @@ -190,6 +190,9 @@ class UnitsTC(TestCase): self.assertRaises(ValueError, tu.apply_units, 'wrong input', self.units) self.assertRaises(ValueError, tu.apply_units, 'wrong13 input', self.units) self.assertRaises(ValueError, tu.apply_units, 'wrong input42', self.units) + with self.assertRaises(ValueError) as cm: + tu.apply_units('42 cakes', self.units) + self.assertIn('invalid unit cakes.', str(cm.exception)) RGX = re.compile('abcd') class PrettyMatchTC(TestCase): -- cgit v1.2.1