Reformated _reset method placement, Fixed pylint issues & reverted pylint ignore comment delete changes

This commit is contained in:
kuldeep.k@cisinlabs.com 2021-09-28 20:44:32 +05:30
parent 4f9593a553
commit a3dceb8b3e
No known key found for this signature in database
GPG Key ID: AF4FB299BF7C7C2A
2 changed files with 14 additions and 22 deletions

View File

@ -165,6 +165,13 @@ class BMConfigParser(SafeConfigParser):
but override the "raw" argument to always True"""
return SafeConfigParser.items(self, section, True, variables)
def _reset(self):
"""Reset current config. There doesn't appear to be a built in
method for this"""
sections = self.sections()
for x in sections:
self.remove_section(x)
if sys.version_info[0] == 3:
@staticmethod
def addresses(hidden=False):
@ -172,13 +179,6 @@ class BMConfigParser(SafeConfigParser):
return [x for x in BMConfigParser().sections() if x.startswith('BM-') and (
hidden or not BMConfigParser().safeGetBoolean(x, 'hidden'))]
def _reset(self):
"""Reset current config. There doesn't appear to be a built in
method for this"""
sections = self.sections()
for x in sections:
self.remove_section(x)
def read(self, filenames):
self._reset()
SafeConfigParser.read(self, filenames)
@ -200,8 +200,9 @@ class BMConfigParser(SafeConfigParser):
except configparser.InterpolationError:
continue
def readfp(self, file_obj):
SafeConfigParser.read_file(self, file_obj)
def readfp(self, fp, filename=None):
# pylint: no-member=ignore
SafeConfigParser.read_file(self, fp)
else:
@staticmethod
def addresses():
@ -209,13 +210,6 @@ class BMConfigParser(SafeConfigParser):
return [
x for x in BMConfigParser().sections() if x.startswith('BM-')]
def _reset(self):
"""Reset current config. There doesn't appear to be a built in
method for this"""
sections = self.sections()
for x in sections:
self.remove_section(x)
def read(self, filenames):
"""Read config and populate defaults"""
self._reset()

View File

@ -3,12 +3,8 @@
Various tests for config
"""
import unittest
import tempfile
import sys
import os
from six import StringIO
from pybitmessage import paths
from pybitmessage.bmconfigparser import BMConfigParser
test_config = """[bitmessagesettings]
@ -51,7 +47,8 @@ class TestConfig(unittest.TestCase):
def tearDown(self):
"""restore to the backup of BMConfigparser"""
BMConfigParser()._reset()
# pylint: protected-access=ignore
BMConfigParser()._reset()
BMConfigParser().readfp(self.configfile)
def test_safeGet(self):
@ -68,6 +65,7 @@ class TestConfig(unittest.TestCase):
False
)
# no arg for default
# pylint: disable=too-many-function-args
with self.assertRaises(TypeError):
BMConfigParser().safeGetBoolean(
'nonexistent', 'nonexistent', True)
@ -93,7 +91,7 @@ class TestConfig(unittest.TestCase):
self.assertEqual(
BMConfigParser().safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 100)
# pylint: protected-access=ignore
BMConfigParser()._reset()
self.assertEqual(
BMConfigParser().safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 500)