summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-29 21:51:56 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-29 21:51:56 +0100
commit18321782bba3986d4ce55e9559026aca1bdbf0ad (patch)
tree040837c76fe94759a8290e4135201971aeeded05
parentFix error in meter info output, after conversion of Unit to enum. (diff)
downloadglucometerutils-18321782bba3986d4ce55e9559026aca1bdbf0ad.tar
glucometerutils-18321782bba3986d4ce55e9559026aca1bdbf0ad.tar.gz
glucometerutils-18321782bba3986d4ce55e9559026aca1bdbf0ad.tar.bz2
glucometerutils-18321782bba3986d4ce55e9559026aca1bdbf0ad.tar.lz
glucometerutils-18321782bba3986d4ce55e9559026aca1bdbf0ad.tar.xz
glucometerutils-18321782bba3986d4ce55e9559026aca1bdbf0ad.tar.zst
glucometerutils-18321782bba3986d4ce55e9559026aca1bdbf0ad.zip
Diffstat (limited to '')
-rw-r--r--test/test_common.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/test_common.py b/test/test_common.py
index 92805a5..8cff341 100644
--- a/test/test_common.py
+++ b/test/test_common.py
@@ -6,6 +6,7 @@ __email__ = 'flameeyes@flameeyes.eu'
__copyright__ = 'Copyright © 2013, Diego Elio Pettenò'
__license__ = 'MIT'
+import datetime
import os
import sys
import unittest
@@ -52,5 +53,78 @@ class TestGlucoseConversion(parameterized.TestCase):
common.convert_glucose_unit(100, from_unit, to_unit)
+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)
+ self.assertEqual(reading.as_csv(common.Unit.MG_DL),
+ '"2018-01-01 00:30:45","100.00","","blood sample",""')
+
+ @parameterized.named_parameters(
+ ('_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)
+ self.assertAlmostEqual(
+ reading.get_value_as(unit), expected_value, places=2)
+
+ @parameterized.named_parameters(
+ ('_meal_none',
+ {'meal': common.Meal.NONE},
+ '"2018-01-01 00:30:45","100.00","","blood sample",""'),
+ ('_meal_before',
+ {'meal': common.Meal.BEFORE},
+ '"2018-01-01 00:30:45","100.00","Before Meal","blood sample",""'),
+ ('_meal_after',
+ {'meal': common.Meal.AFTER},
+ '"2018-01-01 00:30:45","100.00","After Meal","blood sample",""'),
+ ('_measurement_blood',
+ {'measure_method': common.MeasurementMethod.BLOOD_SAMPLE},
+ '"2018-01-01 00:30:45","100.00","","blood sample",""'),
+ ('_measurement_cgm',
+ {'measure_method': common.MeasurementMethod.CGM},
+ '"2018-01-01 00:30:45","100.00","","CGM",""'),
+ ('_comment',
+ {'comment': 'too much'},
+ '"2018-01-01 00:30:45","100.00","","blood sample","too much"'),
+ ('_comment_quoted',
+ {'comment': '"too" much'},
+ '"2018-01-01 00:30:45","100.00","","blood sample","\"too\" much"'),
+ )
+ def test_csv(self, kwargs_dict, expected_csv):
+ reading = common.GlucoseReading(
+ self.TEST_DATETIME, 100, **kwargs_dict)
+ self.assertEqual(reading.as_csv(common.Unit.MG_DL), expected_csv)
+
+
+class TestMeterInfo(parameterized.TestCase):
+
+ @parameterized.named_parameters(
+ ('_no_serial_number',
+ {},
+ 'Serial Number: N/A\n'),
+ ('_serial_number',
+ {'serial_number': 1234},
+ 'Serial Number: 1234\n'),
+ ('_no_version_information',
+ {},
+ 'Version Information:\n N/A\n'),
+ ('_version_information_1',
+ {'version_info': ['test']},
+ 'Version Information:\n test\n'),
+ ('_version_information_2',
+ {'version_info': ['test', 'test2']},
+ 'Version Information:\n test\n test2\n'),
+ ('_default_native_unit',
+ {},
+ 'Native Unit: mg/dL\n'),
+ )
+ def test_meter_info(self, kwargs_dict, expected_fragment):
+ info = common.MeterInfo(self.id(), **kwargs_dict)
+ self.assertIn(expected_fragment, str(info))
+
+
if __name__ == '__main__':
unittest.main()