cleaned up exceptions and added tests
This commit is contained in:
parent
4d99f0c8f8
commit
698c3627cb
|
|
@ -12,9 +12,9 @@ __all__ = [
|
||||||
"ConnectionDrop",
|
"ConnectionDrop",
|
||||||
]
|
]
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logging.raiseExceptions = False
|
logging.raiseExceptions = False
|
||||||
logging.addLevelName(11, "ParseError")
|
logging.addLevelName(11, "ParseError")
|
||||||
|
logging.addLevelName(9, "UnknownFormat")
|
||||||
|
|
||||||
|
|
||||||
class GenericError(Exception):
|
class GenericError(Exception):
|
||||||
|
|
@ -22,11 +22,9 @@ class GenericError(Exception):
|
||||||
Base exception class for the library. Logs information via logging module
|
Base exception class for the library. Logs information via logging module
|
||||||
"""
|
"""
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
logger.debug("%s: %s", self.__class__.__name__, message)
|
super(GenericError, self).__init__(message)
|
||||||
self.message = message
|
|
||||||
|
|
||||||
def __str__(self):
|
self.logger = logging.getLogger(__name__)
|
||||||
return self.message
|
|
||||||
|
|
||||||
|
|
||||||
class UnknownFormat(GenericError):
|
class UnknownFormat(GenericError):
|
||||||
|
|
@ -35,9 +33,10 @@ class UnknownFormat(GenericError):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, message, packet=''):
|
def __init__(self, message, packet=''):
|
||||||
logger.log(9, "%s\nPacket: %s", message, packet)
|
super(UnknownFormat, self).__init__(message)
|
||||||
self.message = message
|
|
||||||
self.packet = packet
|
self.packet = packet
|
||||||
|
self.logger.log(9, "%s\n Packet: %s", message, packet)
|
||||||
|
|
||||||
|
|
||||||
class ParseError(GenericError):
|
class ParseError(GenericError):
|
||||||
|
|
@ -45,9 +44,10 @@ class ParseError(GenericError):
|
||||||
Raised when unexpected format of a supported packet format is encountered
|
Raised when unexpected format of a supported packet format is encountered
|
||||||
"""
|
"""
|
||||||
def __init__(self, message, packet=''):
|
def __init__(self, message, packet=''):
|
||||||
logger.log(11, "%s\nPacket: %s", message, packet)
|
super(ParseError, self).__init__(message)
|
||||||
self.message = message
|
|
||||||
self.packet = packet
|
self.packet = packet
|
||||||
|
self.logger.log(11, "%s\n Packet: %s", message, packet)
|
||||||
|
|
||||||
|
|
||||||
class LoginError(GenericError):
|
class LoginError(GenericError):
|
||||||
|
|
@ -55,8 +55,9 @@ class LoginError(GenericError):
|
||||||
Raised when IS servers didn't respond correctly to our loging attempt
|
Raised when IS servers didn't respond correctly to our loging attempt
|
||||||
"""
|
"""
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
logger.error("%s: %s", self.__class__.__name__, message)
|
super(LoginError, self).__init__(message)
|
||||||
self.message = message
|
|
||||||
|
self.logger.error("%s: %s", self.__class__.__name__, message)
|
||||||
|
|
||||||
|
|
||||||
class ConnectionError(GenericError):
|
class ConnectionError(GenericError):
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
__version__ = '0.6.12'
|
__version__ = '0.6.13'
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from aprs.exceptions import *
|
||||||
|
|
||||||
|
|
||||||
|
class TestExceptions(unittest.TestCase):
|
||||||
|
def test_exception_correctness(self):
|
||||||
|
|
||||||
|
# GenericErrror
|
||||||
|
excpInst = GenericError("test")
|
||||||
|
|
||||||
|
self.assertIsInstance(excpInst, Exception)
|
||||||
|
self.assertEqual(str(excpInst), "test")
|
||||||
|
|
||||||
|
# UnknownFormat
|
||||||
|
excpInst = UnknownFormat("test", "packet")
|
||||||
|
|
||||||
|
self.assertIsInstance(excpInst, GenericError)
|
||||||
|
self.assertEqual(str(excpInst), "test")
|
||||||
|
self.assertEqual(excpInst.packet, "packet")
|
||||||
|
|
||||||
|
# ParseError
|
||||||
|
excpInst = ParseError("test", "packet")
|
||||||
|
|
||||||
|
self.assertIsInstance(excpInst, GenericError)
|
||||||
|
self.assertEqual(str(excpInst), "test")
|
||||||
|
self.assertEqual(excpInst.packet, "packet")
|
||||||
|
|
||||||
|
# LoginError
|
||||||
|
excpInst = LoginError("test")
|
||||||
|
|
||||||
|
self.assertIsInstance(excpInst, GenericError)
|
||||||
|
self.assertEqual(str(excpInst), "test")
|
||||||
|
|
||||||
|
# ConnectionError
|
||||||
|
excpInst = ConnectionError("test")
|
||||||
|
|
||||||
|
self.assertIsInstance(excpInst, GenericError)
|
||||||
|
|
||||||
|
# ConnectionDrop
|
||||||
|
excpInst = ConnectionDrop("test")
|
||||||
|
|
||||||
|
self.assertIsInstance(excpInst, GenericError)
|
||||||
Loading…
Reference in New Issue