Permalink
Browse files

avoid issues with unicode error messages

  • Loading branch information...
amol- committed Jul 18, 2012
1 parent bc509ca commit b5a314de760e3e4809cc0056ab4af2422e71a775
Showing with 13 additions and 2 deletions.
  1. +10 −0 tests/test_validation.py
  2. +3 −2 tw2/core/validation.py
@@ -78,6 +78,16 @@ def test_catch_errors(self):
except twc.ValidationError:
pass
def test_unicode_catch_errors(self):
try:
formencode.api.set_stdtranslation(languages=['tr'])
twc.validation.catch_errors(lambda s, x: formencode.validators.Int.to_python(x))(None, 'x')
assert(False)
except twc.ValidationError:
pass
finally:
formencode.api.set_stdtranslation(languages=['en'])
def test_unflatten(self):
assert(twc.validation.unflatten_params({'a':1, 'b:c':2}) ==
{'a':1, 'b':{'c':2}})
@@ -94,9 +94,10 @@ def wrapper(self, *args, **kw):
d = fn(self, *args, **kw)
return d
except catch, e:
e_msg = unicode(e)
if self:
self.error_msg = str(e)
raise ValidationError(str(e), widget=self)
self.error_msg = e_msg
raise ValidationError(e_msg, widget=self)
return wrapper

0 comments on commit b5a314d

Please sign in to comment.