Added readfp function for python3, updated StringIO & readfb based changes in setUp, teadDown and test_reset functions
This commit is contained in:
parent
14f1c15945
commit
4f9593a553
|
@ -200,6 +200,8 @@ class BMConfigParser(SafeConfigParser):
|
||||||
except configparser.InterpolationError:
|
except configparser.InterpolationError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
def readfp(self, file_obj):
|
||||||
|
SafeConfigParser.read_file(self, file_obj)
|
||||||
else:
|
else:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def addresses():
|
def addresses():
|
||||||
|
|
|
@ -7,54 +7,52 @@ import tempfile
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from six import StringIO
|
||||||
from pybitmessage import paths
|
from pybitmessage import paths
|
||||||
from pybitmessage.bmconfigparser import BMConfigParser
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
test_config = {
|
test_config = """[bitmessagesettings]
|
||||||
"bitmessagesettings": {
|
maxaddrperstreamsend = 100
|
||||||
"maxaddrperstreamsend": 100,
|
maxbootstrapconnections = 10
|
||||||
"maxbootstrapconnections": 20,
|
maxdownloadrate = 0
|
||||||
"maxdownloadrate": 0,
|
maxoutboundconnections = 8
|
||||||
"maxoutboundconnections": 8,
|
maxtotalconnections = 100
|
||||||
"maxtotalconnections": 200,
|
maxuploadrate = 0
|
||||||
"maxuploadrate": 0,
|
apiinterface = 127.0.0.1
|
||||||
"apiinterface": "127.0.0.1",
|
apiport = 8442
|
||||||
"apiport": 8442,
|
udp = True
|
||||||
"udp": "True"
|
|
||||||
},
|
[threads]
|
||||||
"threads": {
|
receive = 3
|
||||||
"receive": 3,
|
|
||||||
},
|
[network]
|
||||||
"network": {
|
bind = None
|
||||||
"bind": "",
|
dandelion = 90
|
||||||
"dandelion": 90,
|
|
||||||
},
|
[inventory]
|
||||||
"inventory": {
|
storage = sqlite
|
||||||
"storage": "sqlite",
|
acceptmismatch = False
|
||||||
"acceptmismatch": "False",
|
|
||||||
},
|
[knownnodes]
|
||||||
"knownnodes": {
|
maxnodes = 15000
|
||||||
"maxnodes": 20000,
|
|
||||||
},
|
[zlib]
|
||||||
"zlib": {
|
maxsize = 1048576"""
|
||||||
"maxsize": 1048576
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(unittest.TestCase):
|
class TestConfig(unittest.TestCase):
|
||||||
"""A test case for bmconfigparser"""
|
"""A test case for bmconfigparser"""
|
||||||
config_backup = tempfile.NamedTemporaryFile(suffix='.cfg').name
|
configfile = StringIO('')
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""creates a backup of BMConfigparser current state"""
|
"""creates a backup of BMConfigparser current state"""
|
||||||
with open(self.config_backup, 'wb') as configfile:
|
BMConfigParser().write(self.configfile)
|
||||||
BMConfigParser().write(configfile)
|
self.configfile.seek(0)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""restore to the backup of BMConfigparser"""
|
"""restore to the backup of BMConfigparser"""
|
||||||
BMConfigParser().read(self.config_backup)
|
BMConfigParser()._reset()
|
||||||
os.remove(self.config_backup)
|
BMConfigParser().readfp(self.configfile)
|
||||||
|
|
||||||
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"""
|
||||||
|
@ -70,7 +68,6 @@ class TestConfig(unittest.TestCase):
|
||||||
False
|
False
|
||||||
)
|
)
|
||||||
# no arg for default
|
# no arg for default
|
||||||
# pylint: disable=too-many-function-args
|
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
BMConfigParser().safeGetBoolean(
|
BMConfigParser().safeGetBoolean(
|
||||||
'nonexistent', 'nonexistent', True)
|
'nonexistent', 'nonexistent', True)
|
||||||
|
@ -91,13 +88,8 @@ class TestConfig(unittest.TestCase):
|
||||||
|
|
||||||
def test_reset(self):
|
def test_reset(self):
|
||||||
"""safeGetInt retuns provided default for bitmessagesettings option or 0"""
|
"""safeGetInt retuns provided default for bitmessagesettings option or 0"""
|
||||||
|
test_config_object = StringIO(test_config)
|
||||||
BMConfigParser().read(
|
BMConfigParser().readfp(test_config_object)
|
||||||
os.path.join(
|
|
||||||
os.path.abspath(os.path.dirname(__file__)),
|
|
||||||
'test_pattern', 'test_config.ini'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
BMConfigParser().safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 100)
|
BMConfigParser().safeGetInt('bitmessagesettings', 'maxaddrperstreamsend'), 100)
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
[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