summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 14:25:28 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 14:29:04 +0100
commitf3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6 (patch)
treec01b66d8dc8803c654035a8094d6787a54d22906
parentFix up link to the site. (diff)
downloadglucometerutils-f3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6.tar
glucometerutils-f3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6.tar.gz
glucometerutils-f3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6.tar.bz2
glucometerutils-f3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6.tar.lz
glucometerutils-f3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6.tar.xz
glucometerutils-f3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6.tar.zst
glucometerutils-f3a3cf0660ba4d9477434805e5c5d3c2bfa52eb6.zip
Diffstat (limited to '')
-rw-r--r--test/test_otultra2.py69
-rw-r--r--test/test_otultraeasy.py10
2 files changed, 26 insertions, 53 deletions
diff --git a/test/test_otultra2.py b/test/test_otultra2.py
index 3099604..5713987 100644
--- a/test/test_otultra2.py
+++ b/test/test_otultra2.py
@@ -3,14 +3,15 @@
__author__ = 'Diego Elio Pettenò'
__email__ = 'flameeyes@flameeyes.eu'
-__copyright__ = 'Copyright © 2013, Diego Elio Pettenò'
+__copyright__ = 'Copyright © 2013-2017, Diego Elio Pettenò'
__license__ = 'MIT'
import os
import sys
import unittest
+from unittest import mock
-import mock
+from absl.testing import parameterized
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -18,61 +19,33 @@ from glucometerutils.drivers import otultra2
from glucometerutils.support import lifescan
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 _set_return_string(self, string):
- self.mock_readline.return_value = bytes(string, 'ascii')
+class TestOTUltra2(parameterized.TestCase):
def test_checksum(self):
checksum = otultra2._calculate_checksum(bytes('T', 'ascii'))
self.assertEqual(0x0054, checksum)
+ def test_checksum_full(self):
checksum = otultra2._calculate_checksum(
bytes('T "SAT","08/03/13","22:12:00 "', 'ascii'))
self.assertEqual(0x0608, checksum)
- def test_missing_checksum(self):
- self._set_return_string('INVALID')
-
- self.assertRaises(lifescan.MissingChecksum,
- self.device.get_serial_number)
-
- def test_short_response(self):
- self._set_return_string('.\r')
-
- self.assertRaises(exceptions.InvalidResponse,
- self.device.get_serial_number)
-
- def test_invalid_response(self):
- self._set_return_string('% 2500\r')
-
- self.assertRaises(exceptions.InvalidResponse,
- self.device.get_serial_number)
-
- def test_invalid_serial_number(self):
- self._set_return_string('@ "12345678O" 0297\r')
-
- self.assertRaises(lifescan.InvalidSerialNumber,
- self.device.get_serial_number)
-
- def test_invalid_checksum(self):
- self._set_return_string('% 1337\r')
-
- self.assertRaises(exceptions.InvalidChecksum,
- self.device.get_serial_number)
-
- def test_broken_checksum(self):
- self._set_return_string('% 13AZ\r')
-
- self.assertRaises(lifescan.MissingChecksum,
- self.device.get_serial_number)
+ @parameterized.named_parameters(
+ ('_missing_checksum', b'INVALID', lifescan.MissingChecksum),
+ ('_short', b'.\r', exceptions.InvalidResponse),
+ ('_generic', b'% 2500\r', exceptions.InvalidResponse),
+ ('_invalid_serial_number', b'@ "12345678O" 0297\r',
+ lifescan.InvalidSerialNumber),
+ ('_invalid_checksum', b'% 1337\r', exceptions.InvalidChecksum),
+ ('_broken_checksum', b'% 13AZ\r', lifescan.MissingChecksum),
+ )
+ def test_invalid_response(self, returned_string, expected_exception):
+ with mock.patch('serial.Serial') as mock_serial:
+ mock_serial.return_value.readline.return_value = returned_string
+
+ device = otultra2.Device('mockdevice')
+ with self.assertRaises(expected_exception):
+ device.get_serial_number()
if __name__ == '__main__':
unittest.main()
diff --git a/test/test_otultraeasy.py b/test/test_otultraeasy.py
index 7b91d56..a1d4c02 100644
--- a/test/test_otultraeasy.py
+++ b/test/test_otultraeasy.py
@@ -3,15 +3,14 @@
__author__ = 'Diego Elio Pettenò'
__email__ = 'flameeyes@flameeyes.eu'
-__copyright__ = 'Copyright © 2013, Diego Elio Pettenò'
+__copyright__ = 'Copyright © 2013-2017, Diego Elio Pettenò'
__license__ = 'MIT'
import array
import os
import sys
import unittest
-
-import mock
+from unittest import mock
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -28,17 +27,18 @@ class TestOTUltraMini(unittest.TestCase):
self.device = otultraeasy.Device('mockdevice')
- def testCrc(self):
+ def test_crc(self):
self.assertEqual(
0x41cd,
lifescan.crc_ccitt(b'\x02\x06\x06\x03'))
+ def test_crc_array(self):
cmd_array = array.array('B', b'\x02\x06\x08\x03')
self.assertEqual(
0x62C2,
lifescan.crc_ccitt(cmd_array))
- def testPacketUpdateChecksum(self):
+ def test_packet_update_checksum(self):
packet = otultraeasy._Packet()
packet.build_command('')