summaryrefslogtreecommitdiffstats
path: root/test/test_otultra2.py
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2013-08-03 10:07:41 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2013-08-03 10:07:41 +0200
commit389f424b0b541e581115d4cda355cd2c44118e1f (patch)
treeb83b3b42d4ddb2be764ba841bbd725528d83c413 /test/test_otultra2.py
downloadglucometerutils-389f424b0b541e581115d4cda355cd2c44118e1f.tar
glucometerutils-389f424b0b541e581115d4cda355cd2c44118e1f.tar.gz
glucometerutils-389f424b0b541e581115d4cda355cd2c44118e1f.tar.bz2
glucometerutils-389f424b0b541e581115d4cda355cd2c44118e1f.tar.lz
glucometerutils-389f424b0b541e581115d4cda355cd2c44118e1f.tar.xz
glucometerutils-389f424b0b541e581115d4cda355cd2c44118e1f.tar.zst
glucometerutils-389f424b0b541e581115d4cda355cd2c44118e1f.zip
Diffstat (limited to 'test/test_otultra2.py')
-rw-r--r--test/test_otultra2.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/test_otultra2.py b/test/test_otultra2.py
new file mode 100644
index 0000000..f8e0cb1
--- /dev/null
+++ b/test/test_otultra2.py
@@ -0,0 +1,48 @@
+import os
+import sys
+import unittest
+
+import mock
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from glucometerutils import common
+from glucometerutils.drivers import otultra2
+from glucometerutils import exceptions
+
+class TestOTUltra2(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 = otultra2.Device('mockdevice')
+
+ def testMissingChecksum(self):
+ self.mock_readline.return_value = bytes('INVALID', 'ascii')
+
+ self.assertRaises(otultra2.MissingChecksum,
+ self.device.GetSerialNumber)
+
+ def testShortResponse(self):
+ self.mock_readline.return_value = bytes('.\r', 'ascii')
+
+ self.assertRaises(exceptions.InvalidResponse,
+ self.device.GetSerialNumber)
+
+ def testInvalidResponse(self):
+ self.mock_readline.return_value = bytes('% 1337\r', 'ascii')
+
+ self.assertRaises(exceptions.InvalidResponse,
+ self.device.GetSerialNumber)
+
+ def testInvalidSerialNumber(self):
+ self.mock_readline.return_value = bytes(
+ '@ "12345678O" 1337\r', 'ascii')
+
+ self.assertRaises(otultra2.InvalidSerialNumber,
+ self.device.GetSerialNumber)
+
+if __name__ == '__main__':
+ unittest.main()