Skip to content

Commit

Permalink
use custom exception classes in tests to make sure callables work
Browse files Browse the repository at this point in the history
  • Loading branch information
andymccurdy committed Apr 15, 2014
1 parent fcb22ad commit 68ac439
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ def test_protocol_error_with_custom_class(self):
self.assertRaises(RuntimeError, self.reply)

def test_protocol_error_with_custom_callable(self):
self.reader = hiredis.Reader(protocolError=lambda err: RuntimeError(err))
class CustomException(Exception):
pass

self.reader = hiredis.Reader(protocolError=lambda e: CustomException(e))
self.reader.feed(b"x")
self.assertRaises(RuntimeError, self.reply)
self.assertRaises(CustomException, self.reply)

def test_fail_with_wrong_protocol_error_class(self):
self.assertRaises(TypeError, hiredis.Reader, protocolError="wrong")
Expand All @@ -48,11 +51,14 @@ def test_error_string_with_custom_class(self):
self.assertEquals(("error",), error.args)

def test_error_string_with_custom_callable(self):
self.reader = hiredis.Reader(replyError=lambda err: RuntimeError(err))
class CustomException(Exception):
pass

self.reader = hiredis.Reader(replyError=lambda e: CustomException(e))
self.reader.feed(b"-error\r\n")
error = self.reply()

self.assertEquals(RuntimeError, type(error))
self.assertEquals(CustomException, type(error))
self.assertEquals(("error",), error.args)

def test_fail_with_wrong_reply_error_class(self):
Expand Down

0 comments on commit 68ac439

Please sign in to comment.