Mercurial > personal > weatherlog
changeset 16:770215590d80
logger: Actually pass the right type.
The logger was improperly giving the writer already-encoded values.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Thu, 17 Oct 2019 22:19:33 -0400 |
parents | b5625b531d2d |
children | 39c0686e6765 |
files | weatherlog/logger.py weatherlog/logger_test.py |
diffstat | 2 files changed, 12 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/weatherlog/logger.py Tue Oct 15 23:05:10 2019 -0400 +++ b/weatherlog/logger.py Thu Oct 17 22:19:33 2019 -0400 @@ -36,7 +36,7 @@ @attr.s(auto_attribs=True, frozen=True, slots=True) class ReadingPosition: # The encoded reading that was written. - data: bytes + data: t.Dict[str, object] # The index of the byte immediately following this one. end: int @@ -78,7 +78,7 @@ self._file.write(encoded) self._file.flush() byte = self._file.tell() - self._send_queue.append(ReadingPosition(encoded, byte)) + self._send_queue.append(ReadingPosition(reading, byte)) def _send_internal(self) -> None: to_send: t.List[ReadingPosition] = [] @@ -158,9 +158,8 @@ end_pos = infile.tell() try: for entry in reader: - data = bson_encode(entry) end_pos = infile.tell() - readings.append(ReadingPosition(data, end_pos)) + readings.append(ReadingPosition(entry, end_pos)) except bson.InvalidBSON: infile.seek(end_pos, os.SEEK_SET) infile.truncate(end_pos)
--- a/weatherlog/logger_test.py Tue Oct 15 23:05:10 2019 -0400 +++ b/weatherlog/logger_test.py Thu Oct 17 22:19:33 2019 -0400 @@ -12,7 +12,6 @@ import pytz from . import logger -from . import types class FakeWriter(logger.RemoteWriter): @@ -77,8 +76,8 @@ self.assertEqual( writer.writes, [ - (bs({'first': 'item'}), bs({'entry': 2})), - (bs({'thing': 'three'}),), + ({'first': 'item'}, {'entry': 2}), + ({'thing': 'three'},), ], ) self.assertEqual(self._read_last_sent(), '59') @@ -118,8 +117,8 @@ {'some new': 'entry'}, ]) self.assertEqual(list(itertools.chain.from_iterable(writer.writes)), [ - bs(dict(sample_time=ts(60), temp_c=10, rh_pct=99)), - bs({'some new': 'entry'}), + dict(sample_time=ts(60), temp_c=10, rh_pct=99), + {'some new': 'entry'}, ]) def test_resume_from_byte(self): @@ -150,8 +149,8 @@ {'some new': 'entry'}, ]) self.assertEqual(list(itertools.chain.from_iterable(writer.writes)), [ - bs({'unsent': 'value'}), - bs({'some new': 'entry'}), + {'unsent': 'value'}, + {'some new': 'entry'}, ]) def test_send_failure(self): @@ -169,7 +168,7 @@ self.assertEqual(self._read_last_sent(), '30') self.assertEqual( - writer.writes, [(bs({'cool write': 'succeeds'}),)]) + writer.writes, [({'cool write': 'succeeds'},)]) self.assertEqual(self._read_bsons(), [ {'cool write': 'succeeds'}, {'bad write': 'fails'}, @@ -183,8 +182,8 @@ self.assertEqual( writer.writes, [ - (bs({'cool write': 'succeeds'}),), - (bs({'bad write': 'fails'}),), + ({'cool write': 'succeeds'},), + ({'bad write': 'fails'},), ]) self.assertEqual(self._read_bsons(), [ {'cool write': 'succeeds'},