Format test_config

- for PEP8 compatibility, rewrite copypasted docstring,
  - remove unused configfile slot, move pylint hint,
  - define TestConfig.setUp(), creating BMConfigParser obj,
This commit is contained in:
Dmitri Bogomolov 2022-02-16 23:51:12 +02:00
parent 7d2b13e4ac
commit 858705357a
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -1,4 +1,3 @@
# pylint: disable=no-member, no-self-use
""" """
Various tests for config Various tests for config
""" """
@ -36,63 +35,60 @@ maxnodes = 15000
maxsize = 1048576""" maxsize = 1048576"""
# pylint: disable=protected-access
class TestConfig(unittest.TestCase): class TestConfig(unittest.TestCase):
"""A test case for bmconfigparser""" """A test case for bmconfigparser"""
configfile = StringIO('')
def setUp(self):
self.config = BMConfigParser()
self.config.add_section('bitmessagesettings')
def test_safeGet(self): def test_safeGet(self):
"""safeGet retuns provided default for nonexistent option or None""" """safeGet retuns provided default for nonexistent option or None"""
config = BMConfigParser()
self.assertIs( self.assertIs(
config.safeGet('nonexistent', 'nonexistent'), None) self.config.safeGet('nonexistent', 'nonexistent'), None)
self.assertEqual( self.assertEqual(
config.safeGet('nonexistent', 'nonexistent', 42), 42) self.config.safeGet('nonexistent', 'nonexistent', 42), 42)
def test_safeGetBoolean(self): def test_safeGetBoolean(self):
"""safeGetBoolean returns False for nonexistent option, no default""" """safeGetBoolean returns False for nonexistent option, no default"""
config = BMConfigParser()
self.assertIs( self.assertIs(
config.safeGetBoolean('nonexistent', 'nonexistent'), self.config.safeGetBoolean('nonexistent', 'nonexistent'), False)
False
)
# no arg for default # no arg for default
# pylint: disable=too-many-function-args # pylint: disable=too-many-function-args
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
config.safeGetBoolean( self.config.safeGetBoolean('nonexistent', 'nonexistent', True)
'nonexistent', 'nonexistent', True)
def test_safeGetInt(self): def test_safeGetInt(self):
"""safeGetInt retuns provided default for nonexistent option or 0""" """safeGetInt retuns provided default for nonexistent option or 0"""
config = BMConfigParser()
self.assertEqual( self.assertEqual(
config.safeGetInt('nonexistent', 'nonexistent'), 0) self.config.safeGetInt('nonexistent', 'nonexistent'), 0)
self.assertEqual( self.assertEqual(
config.safeGetInt('nonexistent', 'nonexistent', 42), 42) self.config.safeGetInt('nonexistent', 'nonexistent', 42), 42)
def test_safeGetFloat(self): def test_safeGetFloat(self):
"""safeGetFloat retuns provided default for nonexistent option or 0.0""" """
config = BMConfigParser() safeGetFloat retuns provided default for nonexistent option or 0.0
"""
self.assertEqual( self.assertEqual(
config.safeGetFloat('nonexistent', 'nonexistent'), 0.0) self.config.safeGetFloat('nonexistent', 'nonexistent'), 0.0)
self.assertEqual( self.assertEqual(
config.safeGetFloat('nonexistent', 'nonexistent', 42.0), 42.0) self.config.safeGetFloat('nonexistent', 'nonexistent', 42.0), 42.0)
def test_reset(self): def test_reset(self):
"""safeGetInt retuns provided default for bitmessagesettings option or 0""" """Some logic for testing _reset()"""
config = BMConfigParser()
test_config_object = StringIO(test_config) test_config_object = StringIO(test_config)
config.read_file(test_config_object) self.config.read_file(test_config_object)
self.assertEqual( self.assertEqual(
config.safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 100) self.config.safeGetInt(
# pylint: disable=protected-access 'bitmessagesettings', 'maxaddrperstreamsend'), 100)
config._reset() self.config._reset()
self.assertEqual(config.sections(), []) self.assertEqual(self.config.sections(), [])
def test_defaults(self): def test_defaults(self):
"""Loading defaults""" """Loading defaults"""
config = BMConfigParser() self.config.set('bitmessagesettings', 'maxaddrperstreamsend', '100')
config.add_section('bitmessagesettings') self.config.read()
config.set("bitmessagesettings", "maxaddrperstreamsend", "100")
config.read()
self.assertEqual( self.assertEqual(
config.safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 500) self.config.safeGetInt(
'bitmessagesettings', 'maxaddrperstreamsend'), 500)