From a589c1e61f4d634d808fdd6d77cdc06cf4cbfeb1 Mon Sep 17 00:00:00 2001 From: Jeppe Klitgaard Date: Sat, 11 Apr 2015 17:47:25 +0200 Subject: [PATCH] Added exceptions for serialization and deserialization. These will come in handy later --- minecraft/exceptions.py | 16 +++++++++++++++- tests/test_exceptions.py | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/minecraft/exceptions.py b/minecraft/exceptions.py index 80f57cd..e3d57f6 100644 --- a/minecraft/exceptions.py +++ b/minecraft/exceptions.py @@ -5,5 +5,19 @@ Contains the `Exceptions` used by this library. class YggdrasilError(Exception): """ - Base `Exception` for the Yggdrasil authentication service. + Base ``Exception`` for the Yggdrasil authentication service. + """ + + +class DeserializationError(Exception): + """ + ``Exception`` raised when something went wrong during the deserialization + process. + """ + + +class SerializationError(Exception): + """ + ``Exception`` raised when something went wrong during the serialization + process. """ diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 4f5c989..533fb35 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -1,4 +1,5 @@ from minecraft.exceptions import YggdrasilError +from minecraft.exceptions import DeserializationError, SerializationError import unittest @@ -13,3 +14,27 @@ class RaiseYggdrasilError(unittest.TestCase): raise YggdrasilError("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 RaiseSerializationError(unittest.TestCase): + def test_raise_serialization_error(self): + 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!")