pyCraft/tests/test_exceptions.py
2015-04-14 19:45:15 +02:00

31 lines
857 B
Python

from minecraft.exceptions import YggdrasilError
from minecraft.exceptions import DeserializationError, SerializationError
import unittest
class BaseRaiseExceptionTest(unittest.TestCase):
EXCEPTION_TO_TEST = Exception
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 RaiseYggdrasilError(BaseRaiseExceptionTest):
EXCEPTION_TO_TEST = YggdrasilError
class RaiseDeserializationError(BaseRaiseExceptionTest):
EXCEPTION_TO_TEST = DeserializationError
class RaiseSerializationError(BaseRaiseExceptionTest):
EXCEPTION_TO_TEST = SerializationError