From d7265e672035c29b486929caf49d5a9246421d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Thu, 15 Nov 2018 23:52:39 +0000 Subject: tests: simplify and cleanup. * Remove the __main__ blocks as the tests should not be executable by themselves. * Use absltest everywhere instead of a mixture of unittest/absltest (via parameterized). * Only modify import path once. * Cleanup pylint warnings, by disabling those that are not useful, and fixing those that are. --- test/__init__.py | 12 ++++++++++++ test/test_common.py | 11 ++--------- test/test_construct_extras.py | 14 ++++---------- test/test_lifescan.py | 14 +++++--------- test/test_otultra2.py | 13 +++---------- test/test_otultraeasy.py | 3 --- 6 files changed, 26 insertions(+), 41 deletions(-) create mode 100644 test/__init__.py mode change 100644 => 100755 test/test_lifescan.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..8865d55 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +"""Add the top-level module to the PYTHONPATH.""" + +__author__ = 'Diego Elio Pettenò' +__email__ = 'flameeyes@flameeyes.eu' +__copyright__ = 'Copyright © 2018, Diego Elio Pettenò' +__license__ = 'MIT' + +import os +import sys + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) diff --git a/test/test_common.py b/test/test_common.py index 4b062ac..b31d55c 100644 --- a/test/test_common.py +++ b/test/test_common.py @@ -6,15 +6,12 @@ __email__ = 'flameeyes@flameeyes.eu' __copyright__ = 'Copyright © 2013-2018, Diego Elio Pettenò' __license__ = 'MIT' +# pylint: disable=protected-access,missing-docstring + import datetime -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 @@ -123,7 +120,3 @@ class TestMeterInfo(parameterized.TestCase): 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() diff --git a/test/test_construct_extras.py b/test/test_construct_extras.py index b0cd1c3..65bc047 100644 --- a/test/test_construct_extras.py +++ b/test/test_construct_extras.py @@ -6,15 +6,13 @@ __email__ = 'flameeyes@flameeyes.eu' __copyright__ = 'Copyright © 2018, Diego Elio Pettenò' __license__ = 'MIT' +# pylint: disable=protected-access,missing-docstring + import datetime -import os -import sys -import unittest +from absl.testing import absltest import construct -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - from glucometerutils.support import construct_extras @@ -24,7 +22,7 @@ _TEST_DATE3 = datetime.datetime(1970, 1, 1, 0, 0) _NEW_EPOCH = 31536000 # datetime.datetime(1971, 1, 1, 0, 0) -class TestTimestamp(unittest.TestCase): +class TestTimestamp(absltest.TestCase): def test_build_unix_epoch(self): self.assertEqual( @@ -69,7 +67,3 @@ class TestTimestamp(unittest.TestCase): def test_invalid_value(self): with self.assertRaises(AssertionError): construct_extras.Timestamp(construct.Int32ul).build('foo') - - -if __name__ == '__main__': - unittest.main() diff --git a/test/test_lifescan.py b/test/test_lifescan.py old mode 100644 new mode 100755 index 5781829..45f2c1c --- a/test/test_lifescan.py +++ b/test/test_lifescan.py @@ -6,16 +6,16 @@ __email__ = 'flameeyes@flameeyes.eu' __copyright__ = 'Copyright © 2013-2017, Diego Elio Pettenò' __license__ = 'MIT' +# pylint: disable=protected-access,missing-docstring + import array -import os -import sys -import unittest -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from absl.testing import absltest from glucometerutils.support import lifescan -class TestChecksum(unittest.TestCase): + +class TestChecksum(absltest.TestCase): def test_crc(self): self.assertEqual( 0x41cd, @@ -26,7 +26,3 @@ class TestChecksum(unittest.TestCase): self.assertEqual( 0x62C2, lifescan.crc_ccitt(cmd_array)) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/test_otultra2.py b/test/test_otultra2.py index b421c79..608e93b 100644 --- a/test/test_otultra2.py +++ b/test/test_otultra2.py @@ -6,28 +6,24 @@ __email__ = 'flameeyes@flameeyes.eu' __copyright__ = 'Copyright © 2013-2018, Diego Elio Pettenò' __license__ = 'MIT' -import os -import sys -import unittest +# pylint: disable=protected-access,missing-docstring + from unittest import mock from absl.testing import parameterized -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - from glucometerutils.drivers import otultra2 from glucometerutils.support import lifescan from glucometerutils import exceptions + class TestOTUltra2(parameterized.TestCase): def test_checksum(self): - # pylint: disable=protected-access checksum = otultra2._calculate_checksum(b'T') self.assertEqual(0x0054, checksum) def test_checksum_full(self): - # pylint: disable=protected-access checksum = otultra2._calculate_checksum( b'T "SAT","08/03/13","22:12:00 "') self.assertEqual(0x0608, checksum) @@ -48,6 +44,3 @@ class TestOTUltra2(parameterized.TestCase): device = otultra2.Device('mockdevice') with self.assertRaises(expected_exception): device.get_serial_number() - -if __name__ == '__main__': - unittest.main() diff --git a/test/test_otultraeasy.py b/test/test_otultraeasy.py index 6d802db..2e1b093 100644 --- a/test/test_otultraeasy.py +++ b/test/test_otultraeasy.py @@ -25,6 +25,3 @@ class ConstructTest(absltest.TestCase): b'\x02\x09\x03\x05\x0d\x02\x03\x08\x9f', otultraeasy._make_packet( b'\x05\x0d\x02', True, True, False, False)) - -if __name__ == '__main__': - absltest.main() -- cgit v1.2.3