summaryrefslogtreecommitdiffstats
path: root/glucometerutils/support
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.com>2020-03-16 19:51:27 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-03-16 20:06:33 +0100
commitf5143327b243fc616f37252d76bd31f2690b088d (patch)
tree0c165ca6b5a6a0783d594b2beeb50295e52f6a5f /glucometerutils/support
parentMergify: configuration update (diff)
downloadglucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar
glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.gz
glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.bz2
glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.lz
glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.xz
glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.zst
glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.zip
Diffstat (limited to 'glucometerutils/support')
-rw-r--r--glucometerutils/support/tests/__init__.py0
-rw-r--r--glucometerutils/support/tests/test_construct_extras.py72
-rw-r--r--glucometerutils/support/tests/test_freestyle.py22
-rwxr-xr-xglucometerutils/support/tests/test_lifescan.py20
4 files changed, 114 insertions, 0 deletions
diff --git a/glucometerutils/support/tests/__init__.py b/glucometerutils/support/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/glucometerutils/support/tests/__init__.py
diff --git a/glucometerutils/support/tests/test_construct_extras.py b/glucometerutils/support/tests/test_construct_extras.py
new file mode 100644
index 0000000..6bba873
--- /dev/null
+++ b/glucometerutils/support/tests/test_construct_extras.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+#
+# SPDX-License-Identifier: MIT
+"""Tests for the common routines."""
+
+# pylint: disable=protected-access,missing-docstring
+
+import datetime
+
+import construct
+
+from absl.testing import absltest
+from glucometerutils.support import construct_extras
+
+_TEST_DATE1 = datetime.datetime(1970, 1, 2, 0, 0)
+_TEST_DATE2 = datetime.datetime(1971, 1, 1, 0, 0)
+_TEST_DATE3 = datetime.datetime(1970, 1, 1, 0, 0)
+
+_NEW_EPOCH = 31536000 # datetime.datetime(1971, 1, 1, 0, 0)
+
+
+class TestTimestamp(absltest.TestCase):
+ def test_build_unix_epoch(self):
+ self.assertEqual(
+ construct_extras.Timestamp(construct.Int32ul).build(_TEST_DATE1),
+ b"\x80\x51\x01\x00",
+ )
+
+ def test_parse_unix_epoch(self):
+ self.assertEqual(
+ construct_extras.Timestamp(construct.Int32ul).parse(b"\x803\xe1\x01"),
+ _TEST_DATE2,
+ )
+
+ def test_build_custom_epoch(self):
+ self.assertEqual(
+ construct_extras.Timestamp(construct.Int32ul, epoch=_NEW_EPOCH).build(
+ _TEST_DATE2
+ ),
+ b"\x00\x00\x00\x00",
+ )
+
+ def test_parse_custom_epoch(self):
+ self.assertEqual(
+ construct_extras.Timestamp(construct.Int32ul, epoch=_NEW_EPOCH).parse(
+ b"\x00\x00\x00\x00"
+ ),
+ _TEST_DATE2,
+ )
+
+ def test_build_custom_epoch_negative_failure(self):
+ with self.assertRaises(construct.core.FormatFieldError):
+ construct_extras.Timestamp(construct.Int32ul, epoch=_NEW_EPOCH).build(
+ _TEST_DATE1
+ )
+
+ def test_build_custom_epoch_negative_success(self):
+ self.assertEqual(
+ construct_extras.Timestamp(construct.Int32sl, epoch=_NEW_EPOCH).build(
+ _TEST_DATE1
+ ),
+ b"\x00\x1e\x20\xfe",
+ )
+
+ def test_build_varint(self):
+ self.assertEqual(
+ construct_extras.Timestamp(construct.VarInt).build(_TEST_DATE3), b"\x00"
+ )
+
+ def test_invalid_value(self):
+ with self.assertRaises(AssertionError):
+ construct_extras.Timestamp(construct.Int32ul).build("foo")
diff --git a/glucometerutils/support/tests/test_freestyle.py b/glucometerutils/support/tests/test_freestyle.py
new file mode 100644
index 0000000..fb3f3b9
--- /dev/null
+++ b/glucometerutils/support/tests/test_freestyle.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+#
+# SPDX-License-Identifier: MIT
+"""Tests for the common FreeStyle functions.."""
+
+# pylint: disable=protected-access,missing-docstring
+
+from absl.testing import absltest
+from glucometerutils.support import freestyle
+
+
+class TestFreeStyle(absltest.TestCase):
+ def test_outgoing_command(self):
+ """Test the generation of a new outgoing message."""
+
+ self.assertEqual(
+ b"\0\x17\7command\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+ freestyle._FREESTYLE_MESSAGE.build(
+ {"message_type": 23, "command": b"command"}
+ ),
+ )
diff --git a/glucometerutils/support/tests/test_lifescan.py b/glucometerutils/support/tests/test_lifescan.py
new file mode 100755
index 0000000..b50b5d6
--- /dev/null
+++ b/glucometerutils/support/tests/test_lifescan.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+#
+# SPDX-License-Identifier: MIT
+"""Tests for the LifeScan OneTouch Ultra Mini driver."""
+
+# pylint: disable=protected-access,missing-docstring
+
+import array
+
+from absl.testing import absltest
+from glucometerutils.support import lifescan
+
+
+class TestChecksum(absltest.TestCase):
+ 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))