From ea8991c05bb6e032e0a491fee7b00d9e58015bc6 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 18 Apr 2018 22:58:46 +0300 Subject: [PATCH] Test case for config, not runs pybitmessage yet --- src/tests/test_config.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/tests/test_config.py diff --git a/src/tests/test_config.py b/src/tests/test_config.py new file mode 100644 index 00000000..6817b37a --- /dev/null +++ b/src/tests/test_config.py @@ -0,0 +1,36 @@ +""" +Various tests for config +""" + +import unittest + +from pybitmessage.bmconfigparser import BMConfigParser + + +class TestConfig(unittest.TestCase): + """A test case for bmconfigparser""" + + def test_safeGet(self): + """safeGet retuns provided default for nonexistent option or None""" + self.assertIs( + BMConfigParser().safeGet('nonexistent', 'nonexistent'), None) + self.assertEqual( + BMConfigParser().safeGet('nonexistent', 'nonexistent', 42), 42) + + def test_safeGetBoolean(self): + """safeGetBoolean returns False for nonexistent option, no default""" + self.assertIs( + BMConfigParser().safeGetBoolean('nonexistent', 'nonexistent'), + False + ) + # no arg for default + with self.assertRaises(TypeError): + BMConfigParser().safeGetBoolean( + 'nonexistent', 'nonexistent', True) + + def test_safeGetInt(self): + """safeGetInt retuns provided default for nonexistent option or 0""" + self.assertEqual( + BMConfigParser().safeGetInt('nonexistent', 'nonexistent'), 0) + self.assertEqual( + BMConfigParser().safeGetInt('nonexistent', 'nonexistent', 42), 42)