summaryrefslogtreecommitdiffstats
path: root/glucometerutils/tests/test_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'glucometerutils/tests/test_common.py')
-rw-r--r--glucometerutils/tests/test_common.py38
1 files changed, 32 insertions, 6 deletions
diff --git a/glucometerutils/tests/test_common.py b/glucometerutils/tests/test_common.py
index 3e733e3..2a3a23d 100644
--- a/glucometerutils/tests/test_common.py
+++ b/glucometerutils/tests/test_common.py
@@ -6,10 +6,13 @@
# pylint: disable=protected-access,missing-docstring
import datetime
+import unittest
from absl.testing import parameterized
from glucometerutils import common
+TEST_DATETIME = datetime.datetime(2018, 1, 1, 0, 30, 45)
+
class TestGlucoseConversion(parameterized.TestCase):
def test_convert_to_mmol(self):
@@ -43,11 +46,8 @@ class TestGlucoseConversion(parameterized.TestCase):
class TestGlucoseReading(parameterized.TestCase):
-
- TEST_DATETIME = datetime.datetime(2018, 1, 1, 0, 30, 45)
-
def test_minimal(self):
- reading = common.GlucoseReading(self.TEST_DATETIME, 100)
+ reading = common.GlucoseReading(TEST_DATETIME, 100)
self.assertEqual(
reading.as_csv(common.Unit.MG_DL),
'"2018-01-01 00:30:45","100.00","","blood sample",""',
@@ -57,7 +57,7 @@ class TestGlucoseReading(parameterized.TestCase):
("_mgdl", common.Unit.MG_DL, 100), ("_mmoll", common.Unit.MMOL_L, 5.56)
)
def test_value(self, unit, expected_value):
- reading = common.GlucoseReading(self.TEST_DATETIME, 100)
+ reading = common.GlucoseReading(TEST_DATETIME, 100)
self.assertAlmostEqual(reading.get_value_as(unit), expected_value, places=2)
@parameterized.named_parameters(
@@ -98,10 +98,36 @@ class TestGlucoseReading(parameterized.TestCase):
),
)
def test_csv(self, kwargs_dict, expected_csv):
- reading = common.GlucoseReading(self.TEST_DATETIME, 100, **kwargs_dict)
+ reading = common.GlucoseReading(TEST_DATETIME, 100, **kwargs_dict)
self.assertEqual(reading.as_csv(common.Unit.MG_DL), expected_csv)
+class TestKetoneReading(unittest.TestCase):
+ def test_measure_method(self):
+ """Raise an exception if an invalid measurement method is provided.
+
+ We allow measure_method as a parameter for compatibility with the other
+ Readings, but we don't want anything _but_ the BLOOD_SAMPLE method.
+ """
+ with self.subTest("No measure_method parameter."):
+ self.assertIsNotNone(common.KetoneReading(TEST_DATETIME, 100))
+
+ with self.subTest("measure_method=MeasurementMethod.BLOOD_SAMPLE is valid"):
+ self.assertIsNotNone(
+ common.KetoneReading(
+ TEST_DATETIME,
+ 100,
+ measure_method=common.MeasurementMethod.BLOOD_SAMPLE,
+ )
+ )
+
+ with self.subTest("measure_method=MeasurementMethod.TIME raises ValueError"):
+ with self.assertRaises(ValueError):
+ common.KetoneReading(
+ TEST_DATETIME, 100, measure_method=common.MeasurementMethod.TIME
+ )
+
+
class TestMeterInfo(parameterized.TestCase):
@parameterized.named_parameters(
("_no_serial_number", {}, "Serial Number: N/A\n"),