Separate tests for BMConfigParser from TestProcessProto based config tests
This commit is contained in:
parent
c51108e867
commit
d947e709ce
|
@ -3,43 +3,12 @@ Various tests for config
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from pybitmessage.bmconfigparser import BMConfigParser
|
from pybitmessage.bmconfigparser import BMConfigParser
|
||||||
from test_process import TestProcessProto
|
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):
|
class TestProcessConfig(TestProcessProto):
|
||||||
"""A test case for keys.dat"""
|
"""A test case for keys.dat"""
|
||||||
home = tempfile.mkdtemp()
|
home = tempfile.mkdtemp()
|
||||||
|
|
37
src/tests/test_configparser.py
Normal file
37
src/tests/test_configparser.py
Normal file
|
@ -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)
|
Reference in New Issue
Block a user