From d947e709ce77dfceba1270746740a9de20b06247 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 10 Feb 2021 20:24:57 +0200 Subject: [PATCH] Separate tests for BMConfigParser from TestProcessProto based config tests --- src/tests/test_config.py | 31 ---------------------------- src/tests/test_configparser.py | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 src/tests/test_configparser.py diff --git a/src/tests/test_config.py b/src/tests/test_config.py index fcf8c498..1b977530 100644 --- a/src/tests/test_config.py +++ b/src/tests/test_config.py @@ -3,43 +3,12 @@ Various tests for config """ import os -import unittest import tempfile from pybitmessage.bmconfigparser import BMConfigParser from test_process import TestProcessProto -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 - # pylint: disable=too-many-function-args - 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) - - class TestProcessConfig(TestProcessProto): """A test case for keys.dat""" home = tempfile.mkdtemp() diff --git a/src/tests/test_configparser.py b/src/tests/test_configparser.py new file mode 100644 index 00000000..8ebb568d --- /dev/null +++ b/src/tests/test_configparser.py @@ -0,0 +1,37 @@ +""" +Tests for BMConfigParser +""" + +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 + # pylint: disable=too-many-function-args + 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)