Abstraction in exceptions tests

This commit is contained in:
Jeppe Klitgaard 2015-04-11 18:35:26 +02:00
parent a589c1e61f
commit 8ca5c7f35f

View File

@ -4,37 +4,27 @@ from minecraft.exceptions import DeserializationError, SerializationError
import unittest import unittest
class RaiseYggdrasilError(unittest.TestCase): class BaseRaiseExceptionTest(unittest.TestCase):
def test_raise_yggdrasil_error(self): EXCEPTION_TO_TEST = Exception
with self.assertRaises(YggdrasilError):
raise YggdrasilError
def test_raise_yggdrasil_error_message(self): def test_raise_error(self):
with self.assertRaises(YggdrasilError) as e: with self.assertRaises(self.EXCEPTION_TO_TEST):
raise YggdrasilError("Error!") 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!") self.assertEqual(str(e.exception), "Error!")
class RaiseDeserializationError(unittest.TestCase): class RaiseYggdrasilError(BaseRaiseExceptionTest):
def test_raise_deserialization_error(self): EXCEPTION_TO_TEST = YggdrasilError
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 RaiseSerializationError(unittest.TestCase): class RaiseDeserializationError(BaseRaiseExceptionTest):
def test_raise_serialization_error(self): EXCEPTION_TO_TEST = DeserializationError
with self.assertRaises(SerializationError):
raise SerializationError
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