pyCraft/tests/test_exceptions.py

31 lines
857 B
Python
Raw Normal View History

2015-04-07 20:16:01 +02:00
from minecraft.exceptions import YggdrasilError
from minecraft.exceptions import DeserializationError, SerializationError
2015-04-07 20:16:01 +02:00
import unittest
2015-04-11 18:35:26 +02:00
class BaseRaiseExceptionTest(unittest.TestCase):
EXCEPTION_TO_TEST = Exception
2015-04-07 20:16:01 +02:00
2015-04-11 18:35:26 +02:00
def test_raise_error(self):
with self.assertRaises(self.EXCEPTION_TO_TEST):
raise self.EXCEPTION_TO_TEST
2015-04-07 20:16:01 +02:00
2015-04-11 18:35:26 +02:00
def test_raise_error_message(self):
with self.assertRaises(self.EXCEPTION_TO_TEST) as e:
raise self.EXCEPTION_TO_TEST("Error!")
2015-04-11 18:35:26 +02:00
self.assertEqual(str(e.exception), "Error!")
2015-04-11 18:35:26 +02:00
class RaiseYggdrasilError(BaseRaiseExceptionTest):
EXCEPTION_TO_TEST = YggdrasilError
2015-04-11 18:35:26 +02:00
class RaiseDeserializationError(BaseRaiseExceptionTest):
EXCEPTION_TO_TEST = DeserializationError
2015-04-11 18:35:26 +02:00
class RaiseSerializationError(BaseRaiseExceptionTest):
EXCEPTION_TO_TEST = SerializationError