From 6963d0f016be13b6fa098a1041c4427e2d02e8c2 Mon Sep 17 00:00:00 2001 From: David Novakovic Date: Mon, 4 Aug 2014 21:05:17 +1000 Subject: [PATCH] Use cleaner failure testing. --- cyclone/tests/test_httpclient.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/cyclone/tests/test_httpclient.py b/cyclone/tests/test_httpclient.py index 024adb7db5..d619923d7a 100644 --- a/cyclone/tests/test_httpclient.py +++ b/cyclone/tests/test_httpclient.py @@ -162,12 +162,7 @@ def test_rpc_request_error(self): response.code = 200 response.body = escape.json_encode({"error": {"message": "failed"}}) cyclone.httpclient.fetch.return_value = succeed(response) - try: - yield self.client.foo() - except Exception, e: - self.assertEqual(e.message, "failed") - else: - raise Exception("Should raise an error.") + yield self.assertFailure(self.client.foo(), Exception) @inlineCallbacks def test_rpc_request_error_old(self): @@ -175,12 +170,7 @@ def test_rpc_request_error_old(self): response.code = 200 response.body = escape.json_encode({"error": "some error"}) cyclone.httpclient.fetch.return_value = succeed(response) - try: - yield self.client.foo() - except Exception, e: - self.assertEqual(e.message, "some error") - else: - raise Exception("Should raise an error.") + yield self.assertFailure(self.client.foo(), Exception) @inlineCallbacks def test_rpc_request_404(self): @@ -189,9 +179,4 @@ def test_rpc_request_404(self): response.phrase = "Not found." response.body = escape.json_encode({"result": True}) cyclone.httpclient.fetch.return_value = succeed(response) - try: - yield self.client.foo() - except HTTPError, e: - self.assertEqual(e.log_message, "Not found.") - else: - raise Exception("Should raise an error.") + yield self.assertFailure(self.client.foo(), HTTPError)