summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2014-01-29 23:38:11 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2014-01-29 23:39:25 +0100
commit4181ab3a16b1cae91a1c35806067e74f7e669e9c (patch)
treecea99e835bcbcd63d84f467566ef54d7e0479638 /test
parentcommon: fix namedtuple usage to allow for optional parameters. (diff)
downloadglucometerutils-4181ab3a16b1cae91a1c35806067e74f7e669e9c.tar
glucometerutils-4181ab3a16b1cae91a1c35806067e74f7e669e9c.tar.gz
glucometerutils-4181ab3a16b1cae91a1c35806067e74f7e669e9c.tar.bz2
glucometerutils-4181ab3a16b1cae91a1c35806067e74f7e669e9c.tar.lz
glucometerutils-4181ab3a16b1cae91a1c35806067e74f7e669e9c.tar.xz
glucometerutils-4181ab3a16b1cae91a1c35806067e74f7e669e9c.tar.zst
glucometerutils-4181ab3a16b1cae91a1c35806067e74f7e669e9c.zip
Diffstat (limited to 'test')
-rw-r--r--test/test_otultraeasy.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/test_otultraeasy.py b/test/test_otultraeasy.py
new file mode 100644
index 0000000..326aeea
--- /dev/null
+++ b/test/test_otultraeasy.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+"""Tests for the LifeScan OneTouch Ultra Mini driver."""
+
+__author__ = 'Diego Elio Pettenò'
+__email__ = 'flameeyes@flameeyes.eu'
+__copyright__ = 'Copyright © 2013, Diego Elio Pettenò'
+__license__ = 'MIT'
+
+import array
+import os
+import sys
+import unittest
+
+import mock
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from glucometerutils.drivers import lifescan_common
+from glucometerutils.drivers import otultraeasy
+from glucometerutils import exceptions
+
+class TestOTUltraMini(unittest.TestCase):
+ def setUp(self):
+ self.addCleanup(mock.patch.stopall)
+
+ mock_serial = mock.patch('serial.Serial').start()
+ self.mock_readline = mock_serial.return_value.readline
+
+ self.device = otultraeasy.Device('mockdevice')
+
+ def testCrc(self):
+ self.assertEqual(
+ 0x41cd,
+ otultraeasy._Packet._crc(b'\x02\x06\x06\x03'))
+
+ cmd_array = array.array('B', b'\x02\x06\x08\x03')
+ self.assertEqual(
+ 0x62C2,
+ otultraeasy._Packet._crc(cmd_array))
+
+ def testPacketUpdateChecksum(self):
+ packet = otultraeasy._Packet()
+
+ packet.build_command('')
+ packet.disconnect = True
+
+ packet.update_checksum()
+ self.assertEqual(
+ b'\x02\x06\x08\x03\xC2\x62',
+ packet.tobytes())
+
+ packet.validate_checksum()
+ packet.disconnect = False
+
+ with self.assertRaises(lifescan_common.InvalidChecksum):
+ packet.validate_checksum()
+
+
+if __name__ == '__main__':
+ unittest.main()