This repository has been archived on 2024-12-19. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-19/src/tests/test_config.py
Dmitri Bogomolov 7b9824afc9
Separate method for stopping the bitmessage process and new test case
for settings in the generated config, which particularly checks that
extralowdifficulty settings are not applied to daemon.
2019-04-22 12:19:09 +03:00

66 lines
2.2 KiB
Python

"""
Various tests for config
"""
import os
import unittest
from pybitmessage.bmconfigparser import BMConfigParser
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
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):
"""A test case for keys.dat"""
def test_config_defaults(self):
"""Test settings in the generated config"""
self._stop_process()
config = BMConfigParser()
config.read(os.path.join(self.home, 'keys.dat'))
self.assertEquals(config.safeGetInt(
'bitmessagesettings', 'settingsversion'), 10)
self.assertEquals(config.safeGetInt(
'bitmessagesettings', 'port'), 8444)
# don't connect
self.assertTrue(config.safeGetBoolean(
'bitmessagesettings', 'dontconnect'))
# API disabled
self.assertFalse(config.safeGetBoolean(
'bitmessagesettings', 'apienabled'))
# extralowdifficulty is false
self.assertEquals(config.safeGetInt(
'bitmessagesettings', 'defaultnoncetrialsperbyte'), 1000)
self.assertEquals(config.safeGetInt(
'bitmessagesettings', 'defaultpayloadlengthextrabytes'), 1000)