Separate tests for BMConfigParser from TestProcessProto based config tests

This commit is contained in:
Dmitri Bogomolov 2021-02-10 20:24:57 +02:00
parent c51108e867
commit d947e709ce
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 37 additions and 31 deletions

View File

@ -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()

View 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)