summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 13:52:20 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 14:12:46 +0100
commit9aa444dec1047590451ef6204d6b296c2f24ac3b (patch)
treeb4d52265b75aea306d705589ecfcd058855bd42b /test
parentaccucheck_reports: fix bug for mg/dL native meters. (diff)
downloadglucometerutils-9aa444dec1047590451ef6204d6b296c2f24ac3b.tar
glucometerutils-9aa444dec1047590451ef6204d6b296c2f24ac3b.tar.gz
glucometerutils-9aa444dec1047590451ef6204d6b296c2f24ac3b.tar.bz2
glucometerutils-9aa444dec1047590451ef6204d6b296c2f24ac3b.tar.lz
glucometerutils-9aa444dec1047590451ef6204d6b296c2f24ac3b.tar.xz
glucometerutils-9aa444dec1047590451ef6204d6b296c2f24ac3b.tar.zst
glucometerutils-9aa444dec1047590451ef6204d6b296c2f24ac3b.zip
Diffstat (limited to 'test')
-rw-r--r--test/test_common.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/test/test_common.py b/test/test_common.py
index 8ca50e1..92805a5 100644
--- a/test/test_common.py
+++ b/test/test_common.py
@@ -10,32 +10,47 @@ import os
import sys
import unittest
+from absl.testing import parameterized
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from glucometerutils import common
from glucometerutils import exceptions
-class TestCommon(unittest.TestCase):
- def test_glucose_conversion(self):
+
+class TestGlucoseConversion(parameterized.TestCase):
+
+ def test_convert_to_mmol(self):
self.assertEqual(
5.56, common.convert_glucose_unit(
100, common.Unit.MG_DL, common.Unit.MMOL_L))
+ def test_convert_to_mgdl(self):
self.assertEqual(
180, common.convert_glucose_unit(
10, common.Unit.MMOL_L, common.Unit.MG_DL))
+ @parameterized.parameters(list(common.Unit))
+ def test_convert_identity(self, unit):
self.assertEqual(
100, common.convert_glucose_unit(
- 100, common.Unit.MG_DL, common.Unit.MG_DL))
+ 100, unit, unit))
+ @parameterized.parameters([unit.value for unit in common.Unit])
+ def test_convert_identity_str(self, unit_str):
self.assertEqual(
- 10, common.convert_glucose_unit(
- 10, common.Unit.MMOL_L, common.Unit.MMOL_L))
+ 100, common.convert_glucose_unit(
+ 100, unit_str, unit_str))
+
+ @parameterized.parameters(
+ (common.Unit.MMOL_L, 'foo'),
+ ('foo', common.Unit.MG_DL),
+ (None, common.Unit.MG_DL),
+ (common.Meal.NONE, common.Unit.MG_DL))
+ def test_invalid_values(self, from_unit, to_unit):
+ with self.assertRaises(Exception):
+ common.convert_glucose_unit(100, from_unit, to_unit)
- self.assertRaises(
- ValueError,
- common.convert_glucose_unit, 10, common.Unit.MMOL_L, 'foo')
if __name__ == '__main__':
unittest.main()