From 8ca5c7f35f279fcafc954d616a08fac8185d8ff2 Mon Sep 17 00:00:00 2001 From: Jeppe Klitgaard Date: Sat, 11 Apr 2015 18:35:26 +0200 Subject: [PATCH] Abstraction in exceptions tests --- tests/test_exceptions.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 533fb35..14eaa0a 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -4,37 +4,27 @@ from minecraft.exceptions import DeserializationError, SerializationError import unittest -class RaiseYggdrasilError(unittest.TestCase): - def test_raise_yggdrasil_error(self): - with self.assertRaises(YggdrasilError): - raise YggdrasilError +class BaseRaiseExceptionTest(unittest.TestCase): + EXCEPTION_TO_TEST = Exception - def test_raise_yggdrasil_error_message(self): - with self.assertRaises(YggdrasilError) as e: - raise YggdrasilError("Error!") + def test_raise_error(self): + with self.assertRaises(self.EXCEPTION_TO_TEST): + raise self.EXCEPTION_TO_TEST + + def test_raise_error_message(self): + with self.assertRaises(self.EXCEPTION_TO_TEST) as e: + raise self.EXCEPTION_TO_TEST("Error!") self.assertEqual(str(e.exception), "Error!") -class RaiseDeserializationError(unittest.TestCase): - def test_raise_deserialization_error(self): - with self.assertRaises(DeserializationError): - raise DeserializationError - - def test_raise_deserialization_error_message(self): - with self.assertRaises(DeserializationError) as e: - raise DeserializationError("Error!") - - self.assertEqual(str(e.exception), "Error!") +class RaiseYggdrasilError(BaseRaiseExceptionTest): + EXCEPTION_TO_TEST = YggdrasilError -class RaiseSerializationError(unittest.TestCase): - def test_raise_serialization_error(self): - with self.assertRaises(SerializationError): - raise SerializationError +class RaiseDeserializationError(BaseRaiseExceptionTest): + EXCEPTION_TO_TEST = DeserializationError - def test_raise_serialization_error_message(self): - with self.assertRaises(SerializationError) as e: - raise SerializationError("Error!") - self.assertEqual(str(e.exception), "Error!") +class RaiseSerializationError(BaseRaiseExceptionTest): + EXCEPTION_TO_TEST = SerializationError