summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Louis Bonicoli <pierre-louis.bonicoli@libregerbil.fr>2021-03-07 23:04:56 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-03-08 21:35:10 +0100
commit32efabb8803d2f274420a21af2297748d256c702 (patch)
treef7a13894ded4b3dd8c9f9284cd0797311d70f9c6
parentTravis CI: update matrix of Python versions. (diff)
downloadglucometerutils-32efabb8803d2f274420a21af2297748d256c702.tar
glucometerutils-32efabb8803d2f274420a21af2297748d256c702.tar.gz
glucometerutils-32efabb8803d2f274420a21af2297748d256c702.tar.bz2
glucometerutils-32efabb8803d2f274420a21af2297748d256c702.tar.lz
glucometerutils-32efabb8803d2f274420a21af2297748d256c702.tar.xz
glucometerutils-32efabb8803d2f274420a21af2297748d256c702.tar.zst
glucometerutils-32efabb8803d2f274420a21af2297748d256c702.zip
-rw-r--r--glucometerutils/common.py4
-rw-r--r--glucometerutils/tests/test_common.py31
2 files changed, 33 insertions, 2 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py
index 3bba660..de5d293 100644
--- a/glucometerutils/common.py
+++ b/glucometerutils/common.py
@@ -102,7 +102,7 @@ class KetoneReading:
"""Returns the reading as a formatted comma-separated value string."""
del unit # Unused for Ketone readings.
- return '"%s","%.2f","%s","%s"' % (
+ return '"%s","%.2f","","%s","%s"' % (
self.timestamp,
self.value,
self.measure_method.value,
@@ -121,7 +121,7 @@ class TimeAdjustment:
def as_csv(self, unit: Unit) -> str:
del unit
- return '"%s","","%s","%s"' % (
+ return '"%s","","","%s","%s"' % (
self.timestamp,
self.measure_method.value,
self.old_timestamp,
diff --git a/glucometerutils/tests/test_common.py b/glucometerutils/tests/test_common.py
index 442d223..5a0c9d9 100644
--- a/glucometerutils/tests/test_common.py
+++ b/glucometerutils/tests/test_common.py
@@ -6,6 +6,7 @@
# pylint: disable=protected-access,missing-docstring
+import csv
import datetime
import unittest
@@ -14,6 +15,8 @@ from absl.testing import parameterized
from glucometerutils import common
TEST_DATETIME = datetime.datetime(2018, 1, 1, 0, 30, 45)
+TEST_OLD_DATETIME = datetime.datetime(2016, 2, 2, 1, 31, 46)
+CSV_FIELD_COUNT = 5
class TestGlucoseConversion(parameterized.TestCase):
@@ -54,6 +57,10 @@ class TestGlucoseReading(parameterized.TestCase):
reading.as_csv(common.Unit.MG_DL),
'"2018-01-01 00:30:45","100.00","","blood sample",""',
)
+ self.assertEqual(
+ len(list(csv.reader([reading.as_csv(common.Unit.MG_DL)]))[0]),
+ CSV_FIELD_COUNT,
+ )
@parameterized.named_parameters(
("_mgdl", common.Unit.MG_DL, 100), ("_mmoll", common.Unit.MMOL_L, 5.56)
@@ -105,6 +112,17 @@ class TestGlucoseReading(parameterized.TestCase):
class TestKetoneReading(unittest.TestCase):
+ def test_minimal(self):
+ reading = common.KetoneReading(TEST_DATETIME, 0.1)
+ self.assertEqual(
+ reading.as_csv(common.Unit.MG_DL),
+ '"2018-01-01 00:30:45","0.10","","blood sample",""',
+ )
+ self.assertEqual(
+ len(list(csv.reader([reading.as_csv(common.Unit.MG_DL)]))[0]),
+ CSV_FIELD_COUNT,
+ )
+
def test_measure_method(self):
"""Raise an exception if an invalid measurement method is provided.
@@ -130,6 +148,19 @@ class TestKetoneReading(unittest.TestCase):
)
+class TestTimeAdjustement(unittest.TestCase):
+ def test_minimal(self):
+ reading = common.TimeAdjustment(TEST_DATETIME, TEST_OLD_DATETIME)
+ self.assertEqual(
+ reading.as_csv(common.Unit.MG_DL),
+ '"2018-01-01 00:30:45","","","time","2016-02-02 01:31:46"',
+ )
+ self.assertEqual(
+ len(list(csv.reader([reading.as_csv(common.Unit.MG_DL)]))[0]),
+ CSV_FIELD_COUNT,
+ )
+
+
class TestMeterInfo(parameterized.TestCase):
@parameterized.named_parameters(
("_no_serial_number", {}, "Serial Number: N/A\n"),