added testcase for _reset()
skip python 3 ported to python 3, fixed deprecation warnings Fixes: #1754 fixed absolute imports corrected test for _reset() few changes fixed some issues in test_reset() & bmconfigparser fixed code quality modified test case for _reset() fixed test case of _reset() for py3 fixed compatibilty with python2 fixed code quality changed _reset test added test_config file & fixed test case for reset() fixed for python3 removed pdb few changes added config dict fixed code quality fixed code quality fixed code quality fixes for focal & bionic build error added print thread name commented test_reset() added some print to debug, will remove later fixed code quality added setUp & tearDown method added docstring modified code fixed code quality modified setUp() & tearDown() method few changes in tearDown() cleaned code Added PEP8 imports blank line & moved test_config.ini to test_pattern folder
This commit is contained in:
parent
d15a58f78b
commit
aa955acf04
|
@ -172,6 +172,13 @@ 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):
|
||||
SafeConfigParser.read(self, filenames)
|
||||
for section in self.sections():
|
||||
|
|
|
@ -1,13 +1,60 @@
|
|||
# pylint: disable=no-member
|
||||
"""
|
||||
Various tests for config
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import tempfile
|
||||
import sys
|
||||
import os
|
||||
|
||||
# from six.moves import configparser
|
||||
from pybitmessage.bmconfigparser import BMConfigParser
|
||||
|
||||
test_config = {
|
||||
"bitmessagesettings": {
|
||||
"maxaddrperstreamsend": 100,
|
||||
"maxbootstrapconnections": 20,
|
||||
"maxdownloadrate": 0,
|
||||
"maxoutboundconnections": 8,
|
||||
"maxtotalconnections": 200,
|
||||
"maxuploadrate": 0,
|
||||
"apiinterface": "127.0.0.1",
|
||||
"apiport": 8442,
|
||||
"udp": "True"
|
||||
},
|
||||
"threads": {
|
||||
"receive": 3,
|
||||
},
|
||||
"network": {
|
||||
"bind": "",
|
||||
"dandelion": 90,
|
||||
},
|
||||
"inventory": {
|
||||
"storage": "sqlite",
|
||||
"acceptmismatch": "False",
|
||||
},
|
||||
"knownnodes": {
|
||||
"maxnodes": 20000,
|
||||
},
|
||||
"zlib": {
|
||||
"maxsize": 1048576
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TestConfig(unittest.TestCase):
|
||||
"""A test case for bmconfigparser"""
|
||||
config_backup = tempfile.NamedTemporaryFile(suffix='.cfg').name
|
||||
|
||||
def setUp(self):
|
||||
"""creates a backup of BMConfigparser current state"""
|
||||
with open(self.config_backup, 'wb') as configfile:
|
||||
BMConfigParser().write(configfile)
|
||||
|
||||
def tearDown(self):
|
||||
"""restore to the backup of BMConfigparser"""
|
||||
BMConfigParser().read(self.config_backup)
|
||||
os.remove(self.config_backup)
|
||||
|
||||
def test_safeGet(self):
|
||||
"""safeGet retuns provided default for nonexistent option or None"""
|
||||
|
@ -41,3 +88,16 @@ class TestConfig(unittest.TestCase):
|
|||
BMConfigParser().safeGetFloat('nonexistent', 'nonexistent'), 0.0)
|
||||
self.assertEqual(
|
||||
BMConfigParser().safeGetFloat('nonexistent', 'nonexistent', 42.0), 42.0)
|
||||
|
||||
def test_reset(self):
|
||||
"""safeGetInt retuns provided default for bitmessagesettings option or 0"""
|
||||
if sys.version_info[0] >= 3:
|
||||
BMConfigParser().read_dict(test_config)
|
||||
else:
|
||||
BMConfigParser().read('src/tests/test_config.ini')
|
||||
self.assertEqual(
|
||||
BMConfigParser().safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 100)
|
||||
# pylint: disable=protected-access
|
||||
BMConfigParser()._reset()
|
||||
self.assertEqual(
|
||||
BMConfigParser().safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 500)
|
||||
|
|
27
src/tests/test_pattern/test_config.ini
Normal file
27
src/tests/test_pattern/test_config.ini
Normal file
|
@ -0,0 +1,27 @@
|
|||
[bitmessagesettings]
|
||||
maxaddrperstreamsend=100
|
||||
maxbootstrapconnections=10
|
||||
maxdownloadrate=0
|
||||
maxoutboundconnections=8
|
||||
maxtotalconnections=100
|
||||
maxuploadrate=0
|
||||
apiinterface=127.0.0.1
|
||||
apiport=8442
|
||||
udp=True
|
||||
|
||||
[threads]
|
||||
receive=3
|
||||
|
||||
[network]
|
||||
bind=None
|
||||
dandelion= 90
|
||||
|
||||
[inventory]
|
||||
storage= sqlite
|
||||
acceptmismatch= False
|
||||
|
||||
[knownnodes]
|
||||
maxnodes= 15000
|
||||
|
||||
[zlib]
|
||||
maxsize= 1048576
|
Reference in New Issue
Block a user