diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.com> | 2020-03-16 19:51:27 +0100 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2020-03-16 20:06:33 +0100 |
commit | f5143327b243fc616f37252d76bd31f2690b088d (patch) | |
tree | 0c165ca6b5a6a0783d594b2beeb50295e52f6a5f /test/test_construct_extras.py | |
parent | Mergify: configuration update (diff) | |
download | glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.gz glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.bz2 glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.lz glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.xz glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.tar.zst glucometerutils-f5143327b243fc616f37252d76bd31f2690b088d.zip |
Diffstat (limited to 'test/test_construct_extras.py')
-rw-r--r-- | test/test_construct_extras.py | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/test/test_construct_extras.py b/test/test_construct_extras.py deleted file mode 100644 index 6bba873..0000000 --- a/test/test_construct_extras.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -# -# SPDX-License-Identifier: MIT -"""Tests for the common routines.""" - -# pylint: disable=protected-access,missing-docstring - -import datetime - -import construct - -from absl.testing import absltest -from glucometerutils.support import construct_extras - -_TEST_DATE1 = datetime.datetime(1970, 1, 2, 0, 0) -_TEST_DATE2 = datetime.datetime(1971, 1, 1, 0, 0) -_TEST_DATE3 = datetime.datetime(1970, 1, 1, 0, 0) - -_NEW_EPOCH = 31536000 # datetime.datetime(1971, 1, 1, 0, 0) - - -class TestTimestamp(absltest.TestCase): - def test_build_unix_epoch(self): - self.assertEqual( - construct_extras.Timestamp(construct.Int32ul).build(_TEST_DATE1), - b"\x80\x51\x01\x00", - ) - - def test_parse_unix_epoch(self): - self.assertEqual( - construct_extras.Timestamp(construct.Int32ul).parse(b"\x803\xe1\x01"), - _TEST_DATE2, - ) - - def test_build_custom_epoch(self): - self.assertEqual( - construct_extras.Timestamp(construct.Int32ul, epoch=_NEW_EPOCH).build( - _TEST_DATE2 - ), - b"\x00\x00\x00\x00", - ) - - def test_parse_custom_epoch(self): - self.assertEqual( - construct_extras.Timestamp(construct.Int32ul, epoch=_NEW_EPOCH).parse( - b"\x00\x00\x00\x00" - ), - _TEST_DATE2, - ) - - def test_build_custom_epoch_negative_failure(self): - with self.assertRaises(construct.core.FormatFieldError): - construct_extras.Timestamp(construct.Int32ul, epoch=_NEW_EPOCH).build( - _TEST_DATE1 - ) - - def test_build_custom_epoch_negative_success(self): - self.assertEqual( - construct_extras.Timestamp(construct.Int32sl, epoch=_NEW_EPOCH).build( - _TEST_DATE1 - ), - b"\x00\x1e\x20\xfe", - ) - - def test_build_varint(self): - self.assertEqual( - construct_extras.Timestamp(construct.VarInt).build(_TEST_DATE3), b"\x00" - ) - - def test_invalid_value(self): - with self.assertRaises(AssertionError): - construct_extras.Timestamp(construct.Int32ul).build("foo") |