summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--glucometerutils/common.py10
-rw-r--r--glucometerutils/drivers/accuchek_reports.py6
-rw-r--r--test/test_common.py12
3 files changed, 11 insertions, 17 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py
index 31584b4..318fc86 100644
--- a/glucometerutils/common.py
+++ b/glucometerutils/common.py
@@ -28,7 +28,7 @@ class MeasurementMethod(enum.Enum):
CGM = 'CGM' # Continuous Glucose Monitoring
-def convert_glucose_unit(value, from_unit, to_unit=None):
+def convert_glucose_unit(value, from_unit, to_unit):
"""Convert the given value of glucose level between units.
Args:
@@ -38,14 +38,14 @@ def convert_glucose_unit(value, from_unit, to_unit=None):
Returns:
The converted representation of the blood glucose level.
-
- Raises:
- exceptions.InvalidGlucoseUnit: If the parameters are incorrect.
"""
+ from_unit = Unit(from_unit)
+ to_unit = Unit(to_unit)
+
if from_unit == to_unit:
return value
- if from_unit is Unit.MG_DL:
+ if from_unit == Unit.MG_DL:
return round(value / 18.0, 2)
else:
return round(value * 18.0, 0)
diff --git a/glucometerutils/drivers/accuchek_reports.py b/glucometerutils/drivers/accuchek_reports.py
index d55ac0f..404ed9b 100644
--- a/glucometerutils/drivers/accuchek_reports.py
+++ b/glucometerutils/drivers/accuchek_reports.py
@@ -130,6 +130,8 @@ class Device(object):
yield common.GlucoseReading(
self._extract_datetime(record),
- common.convert_glucose_unit(float(record[_RESULT_CSV_KEY]),
- _UNIT_MAP[record[_UNIT_CSV_KEY]]),
+ common.convert_glucose_unit(
+ float(record[_RESULT_CSV_KEY]),
+ _UNIT_MAP[record[_UNIT_CSV_KEY]],
+ common.Unit.MG_DL),
meal=self._extract_meal(record))
diff --git a/test/test_common.py b/test/test_common.py
index febf578..8ca50e1 100644
--- a/test/test_common.py
+++ b/test/test_common.py
@@ -22,18 +22,10 @@ class TestCommon(unittest.TestCase):
100, common.Unit.MG_DL, common.Unit.MMOL_L))
self.assertEqual(
- 5.56, common.convert_glucose_unit(
- 100, common.Unit.MG_DL))
-
- self.assertEqual(
180, common.convert_glucose_unit(
10, common.Unit.MMOL_L, common.Unit.MG_DL))
self.assertEqual(
- 180, common.convert_glucose_unit(
- 10, common.Unit.MMOL_L))
-
- self.assertEqual(
100, common.convert_glucose_unit(
100, common.Unit.MG_DL, common.Unit.MG_DL))
@@ -42,8 +34,8 @@ class TestCommon(unittest.TestCase):
10, common.Unit.MMOL_L, common.Unit.MMOL_L))
self.assertRaises(
- exceptions.InvalidGlucoseUnit,
- common.convert_glucose_unit, common.Unit.MMOL_L, 'foo')
+ ValueError,
+ common.convert_glucose_unit, 10, common.Unit.MMOL_L, 'foo')
if __name__ == '__main__':
unittest.main()