summaryrefslogtreecommitdiffstats
path: root/test/test_contourusb.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_contourusb.py')
-rw-r--r--test/test_contourusb.py65
1 files changed, 31 insertions, 34 deletions
diff --git a/test/test_contourusb.py b/test/test_contourusb.py
index e2fb6cb..3b8b547 100644
--- a/test/test_contourusb.py
+++ b/test/test_contourusb.py
@@ -5,62 +5,57 @@
# pylint: disable=protected-access,missing-docstring
-from absl.testing import absltest
-
-from glucometerutils.support import contourusb
-
from unittest.mock import Mock
+from absl.testing import absltest
+from glucometerutils.support import contourusb
class TestContourUSB(absltest.TestCase):
- header_record = b'\x04\x021H|\\^&||7w3LBL|Bayer7390^01.24\\01.04\\09.02.20^7390-2336773^7403-|A=1^C=63^G=1^I=0200^R=0^S=1^U=0^V=10600^X=070070070070180130150250^Y=360126090050099050300089^Z=1|1714||||||1|201909221304\r\x17D7\r\n\x05'
-
+ header_record = b"\x04\x021H|\\^&||7w3LBL|Bayer7390^01.24\\01.04\\09.02.20^7390-2336773^7403-|A=1^C=63^G=1^I=0200^R=0^S=1^U=0^V=10600^X=070070070070180130150250^Y=360126090050099050300089^Z=1|1714||||||1|201909221304\r\x17D7\r\n\x05"
+
mock_dev = Mock()
def test_get_datetime(self):
import datetime
- self.datetime = "201908071315" # returned by
+ self.datetime = "201908071315" # returned by
self.assertEqual(
- datetime.datetime(2019,8,7,13,15),
- contourusb.ContourHidDevice.get_datetime(self)
+ datetime.datetime(2019, 8, 7, 13, 15),
+ contourusb.ContourHidDevice.get_datetime(self),
)
-
def test_RECORD_FORMAT_match(self):
- #first decode the header record frame
+ # first decode the header record frame
header_record_decoded = self.header_record.decode()
- stx = header_record_decoded.find('\x02')
+ stx = header_record_decoded.find("\x02")
_RECORD_FORMAT = contourusb._RECORD_FORMAT
- result = _RECORD_FORMAT.match(header_record_decoded[stx:]).group('text')
+ result = _RECORD_FORMAT.match(header_record_decoded[stx:]).group("text")
self.assertEqual(
- "H|\\^&||7w3LBL|Bayer7390^01.24\\01.04\\09.02.20^7390-2336773^7403-|A=1^C=63^G=1^I=0200^R=0^S=1^U=0^V=10600^X=070070070070180130150250^Y=360126090050099050300089^Z=1|1714||||||1|201909221304",
- result
+ "H|\\^&||7w3LBL|Bayer7390^01.24\\01.04\\09.02.20^7390-2336773^7403-|A=1^C=63^G=1^I=0200^R=0^S=1^U=0^V=10600^X=070070070070180130150250^Y=360126090050099050300089^Z=1|1714||||||1|201909221304",
+ result,
)
def test_parse_header_record(self):
-
+
_HEADER_RECORD_RE = contourusb._HEADER_RECORD_RE
_RECORD_FORMAT = contourusb._RECORD_FORMAT
-
header_record_decoded = self.header_record.decode()
- stx = header_record_decoded.find('\x02')
+ stx = header_record_decoded.find("\x02")
-
- result = _RECORD_FORMAT.match(header_record_decoded[stx:]).group('text')
- contourusb.ContourHidDevice.parse_header_record(self.mock_dev,result)
+ result = _RECORD_FORMAT.match(header_record_decoded[stx:]).group("text")
+ contourusb.ContourHidDevice.parse_header_record(self.mock_dev, result)
self.assertEqual(self.mock_dev.field_del, "\\")
self.assertEqual(self.mock_dev.repeat_del, "^")
self.assertEqual(self.mock_dev.component_del, "&")
self.assertEqual(self.mock_dev.escape_del, "|")
- self.assertEqual(self.mock_dev.product_code, "Bayer7390")
+ self.assertEqual(self.mock_dev.product_code, "Bayer7390")
self.assertEqual(self.mock_dev.dig_ver, "01.24")
self.assertEqual(self.mock_dev.anlg_ver, "01.04")
@@ -100,18 +95,20 @@ class TestContourUSB(absltest.TestCase):
self.assertEqual(self.mock_dev.datetime, "201909221304")
- #TO-DO checksum and checkframe unit tests
+ # TO-DO checksum and checkframe unit tests
def test_parse_result_record(self):
- #first decode the header record frame
+ # first decode the header record frame
result_record = "R|8|^^^Glucose|133|mg/dL^P||B/X||201202052034"
- result_dict = contourusb.ContourHidDevice.parse_result_record(self.mock_dev, result_record)
-
- self.assertEqual(result_dict['record_type'], 'R')
- self.assertEqual(result_dict['seq_num'], '8')
- self.assertEqual(result_dict['test_id'], 'Glucose')
- self.assertEqual(result_dict['value'], '133')
- self.assertEqual(result_dict['unit'], 'mg/dL')
- self.assertEqual(result_dict['ref_method'], 'P')
- self.assertEqual(result_dict['markers'], 'B/X')
- self.assertEqual(result_dict['datetime'], '201202052034') \ No newline at end of file
+ result_dict = contourusb.ContourHidDevice.parse_result_record(
+ self.mock_dev, result_record
+ )
+
+ self.assertEqual(result_dict["record_type"], "R")
+ self.assertEqual(result_dict["seq_num"], "8")
+ self.assertEqual(result_dict["test_id"], "Glucose")
+ self.assertEqual(result_dict["value"], "133")
+ self.assertEqual(result_dict["unit"], "mg/dL")
+ self.assertEqual(result_dict["ref_method"], "P")
+ self.assertEqual(result_dict["markers"], "B/X")
+ self.assertEqual(result_dict["datetime"], "201202052034")