From 98089681bdb6c1e2fad9f6667e476460b86d9534 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 10 Feb 2021 21:08:47 +0200 Subject: [PATCH] Add tests for defaults --- src/tests/test_configparser.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/tests/test_configparser.py b/src/tests/test_configparser.py index 8ebb568d..1177f9f5 100644 --- a/src/tests/test_configparser.py +++ b/src/tests/test_configparser.py @@ -19,10 +19,8 @@ class TestConfig(unittest.TestCase): def test_safeGetBoolean(self): """safeGetBoolean returns False for nonexistent option, no default""" - self.assertIs( - BMConfigParser().safeGetBoolean('nonexistent', 'nonexistent'), - False - ) + self.assertFalse( + BMConfigParser().safeGetBoolean('nonexistent', 'nonexistent')) # no arg for default # pylint: disable=too-many-function-args with self.assertRaises(TypeError): @@ -35,3 +33,19 @@ class TestConfig(unittest.TestCase): BMConfigParser().safeGetInt('nonexistent', 'nonexistent'), 0) self.assertEqual( BMConfigParser().safeGetInt('nonexistent', 'nonexistent', 42), 42) + + def test_defaults(self): + """check use of config defaults""" + self.assertEqual( # int + BMConfigParser().getint('threads', 'receive'), 3) + self.assertEqual( # str + BMConfigParser().get('network', 'bind'), '') + self.assertFalse( # bool + BMConfigParser().getboolean('inventory', 'acceptmismatch')) + + def test_defaults_safe(self): + """safeGet.. methods should use defaults""" + self.assertEqual( + BMConfigParser().safeGetInt('network', 'dandelion'), 90) + self.assertEqual( + BMConfigParser().safeGet('inventory', 'storage'), 'sqlite')