add simpler exception message, assert that it is being used

This commit is contained in:
Chris Wolfe 2016-06-02 14:21:29 -07:00
parent 5be436b81d
commit bc7dea8bab
2 changed files with 5 additions and 5 deletions

View File

@ -826,9 +826,12 @@ class Wormholes(ServerBase, unittest.TestCase):
code = yield w1.get_code()
code_no_dashes = code.replace('-', ' ')
with self.assertRaises(KeyFormatError):
with self.assertRaises(KeyFormatError) as ex:
w2.set_code(code_no_dashes)
expected_msg = "code (%s) contains spaces." % (code_no_dashes,)
self.assertEqual(expected_msg, str(ex.exception))
yield w1.close()
yield w2.close()
self.flushLoggedErrors(ValueError)

View File

@ -479,10 +479,7 @@ class _Wormhole:
# bail out early if the password contains spaces...
# this should raise a useful error
if ' ' in code:
raise KeyFormatError(
"code (%s) contains spaces. Words must be separated by dashes"
% code
)
raise KeyFormatError("code (%s) contains spaces." % code)
self._code = code
mo = re.search(r'^(\d+)-', code)
if not mo: