diff options
author | Denis Laxalde <denis.laxalde@logilab.fr> | 2019-07-26 16:13:02 +0200 |
---|---|---|
committer | Denis Laxalde <denis.laxalde@logilab.fr> | 2019-07-26 16:13:02 +0200 |
commit | 131b6bd58b7aaed997576fe363da2c80fdcb0a67 (patch) | |
tree | 84e18d013b9a822b55cf5dd83d119789f29c0caa /test | |
parent | 0dc34dc2792b7c846b6d683cc251f05f065940e6 (diff) | |
download | logilab-common-131b6bd58b7aaed997576fe363da2c80fdcb0a67.tar.gz |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_textutils.py | 3 |
1 files changed, 3 insertions, 0 deletions
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): |