diff options
-rw-r--r-- | glucometerutils/drivers/freestyle_optium.py | 9 | ||||
-rw-r--r-- | glucometerutils/drivers/lifescan_common.py | 7 | ||||
-rw-r--r-- | glucometerutils/drivers/otultra2.py | 6 | ||||
-rw-r--r-- | glucometerutils/drivers/otultraeasy.py | 2 | ||||
-rw-r--r-- | glucometerutils/drivers/otverio2015.py | 3 | ||||
-rw-r--r-- | glucometerutils/exceptions.py | 7 | ||||
-rw-r--r-- | test/test_otultra2.py | 2 | ||||
-rw-r--r-- | test/test_otultraeasy.py | 2 |
8 files changed, 15 insertions, 23 deletions
diff --git a/glucometerutils/drivers/freestyle_optium.py b/glucometerutils/drivers/freestyle_optium.py index 7f4e020..cbf171e 100644 --- a/glucometerutils/drivers/freestyle_optium.py +++ b/glucometerutils/drivers/freestyle_optium.py @@ -21,13 +21,6 @@ from glucometerutils import common from glucometerutils import exceptions -class InvalidChecksum(exceptions.InvalidResponse): - def __init__(self, expected, gotten): - self.message = ( - 'Response checksum not matching: %04x expected, %04x gotten' % - (expected, gotten)) - - _CLOCK_RE = re.compile( r'^Clock:\t(?P<month>[A-Z][a-z]{2}) (?P<day>[0-9]{2}) (?P<year>[0-9]{4})\t' r'(?P<time>[0-9]{2}:[0-9]{2}:[0-9]{2})$') @@ -255,7 +248,7 @@ class Device(object): calculated_checksum = sum(ord(c) for c in '\r\n'.join(data[:-1])) + 0xd + 0xa if expected_checksum != calculated_checksum: - raise InvalidChecksum(expected_checksum, calculated_checksum) + raise exceptions.InvalidChecksum(expected_checksum, calculated_checksum) for line in data[5:-1]: match = _READING_RE.match(line) diff --git a/glucometerutils/drivers/lifescan_common.py b/glucometerutils/drivers/lifescan_common.py index 4702652..1f8234d 100644 --- a/glucometerutils/drivers/lifescan_common.py +++ b/glucometerutils/drivers/lifescan_common.py @@ -15,13 +15,6 @@ class MissingChecksum(exceptions.InvalidResponse): self.message = 'Response is missing checksum: %s' % response -class InvalidChecksum(exceptions.InvalidResponse): - def __init__(self, expected, gotten): - self.message = ( - 'Response checksum not matching: %04x expected, %04x gotten' % - (expected, gotten)) - - class InvalidSerialNumber(exceptions.Error): """The serial number is not as expected.""" def __init__(self, serial_number): diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index b72c4eb..522d9a0 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -87,10 +87,10 @@ def _validate_and_strip_checksum(line): bytes(response, 'ascii')) if checksum_given != checksum_calculated: - raise lifescan_common.InvalidChecksum(checksum_given, - checksum_calculated) + raise exceptions.InvalidChecksum(checksum_given, + checksum_calculated) except ValueError: - raise lifescan_common.InvalidChecksum(checksum_given, None) + raise exceptions.InvalidChecksum(checksum_given, None) return response diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py index 196746d..f7d0270 100644 --- a/glucometerutils/drivers/otultraeasy.py +++ b/glucometerutils/drivers/otultraeasy.py @@ -162,7 +162,7 @@ class _Packet(object): expected_checksum = self.checksum received_checksum = self._STRUCT.unpack(self.cmd[_IDX_CHECKSUM:])[0] if received_checksum != expected_checksum: - raise lifescan_common.InvalidChecksum(expected_checksum, received_checksum) + raise exceptions.InvalidChecksum(expected_checksum, received_checksum) def update_checksum(self): self._STRUCT.pack_into(self.cmd, _IDX_CHECKSUM, self.checksum) diff --git a/glucometerutils/drivers/otverio2015.py b/glucometerutils/drivers/otverio2015.py index 44f3573..080e3df 100644 --- a/glucometerutils/drivers/otverio2015.py +++ b/glucometerutils/drivers/otverio2015.py @@ -75,8 +75,7 @@ def _extract_message(register): raise lifescan_common.MalformedCommand( 'invalid ETX byte: %02x' % etx) if encoded_checksum != calculated_checksum: - raise lifescan_common.InvalidChecksum( - encoded_checksum, calculated_checksum) + raise exceptions.InvalidChecksum(encoded_checksum, calculated_checksum) response = register[_STRUCT_PREAMBLE.size:coda_offset] return response diff --git a/glucometerutils/exceptions.py b/glucometerutils/exceptions.py index 82f8013..1290d9a 100644 --- a/glucometerutils/exceptions.py +++ b/glucometerutils/exceptions.py @@ -27,6 +27,13 @@ class InvalidResponse(Error): self.message = 'Invalid response received:\n%s' % response +class InvalidChecksum(InvalidResponse): + def __init__(self, expected, gotten): + self.message = ( + 'Response checksum not matching: %08x expected, %08x gotten' % + (expected, gotten)) + + class InvalidGlucoseUnit(Error): """Unable to parse the given glucose unit""" diff --git a/test/test_otultra2.py b/test/test_otultra2.py index 4d59f6a..34078e3 100644 --- a/test/test_otultra2.py +++ b/test/test_otultra2.py @@ -65,7 +65,7 @@ class TestOTUltra2(unittest.TestCase): def test_invalid_checksum(self): self._set_return_string('% 1337\r') - self.assertRaises(lifescan_common.InvalidChecksum, + self.assertRaises(exceptions.InvalidChecksum, self.device.get_serial_number) def test_broken_checksum(self): diff --git a/test/test_otultraeasy.py b/test/test_otultraeasy.py index f263f12..07480d2 100644 --- a/test/test_otultraeasy.py +++ b/test/test_otultraeasy.py @@ -52,7 +52,7 @@ class TestOTUltraMini(unittest.TestCase): packet.validate_checksum() packet.disconnect = False - with self.assertRaises(lifescan_common.InvalidChecksum): + with self.assertRaises(exceptions.InvalidChecksum): packet.validate_checksum() |