Allow TestProcess subclasses set home dir, use mkdtemp for test_config

This commit is contained in:
Dmitri Bogomolov 2020-11-02 12:27:02 +02:00
parent affdb2fdc0
commit cf4e812334
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 7 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Various tests for config
import os import os
import unittest import unittest
import tempfile
from pybitmessage.bmconfigparser import BMConfigParser from pybitmessage.bmconfigparser import BMConfigParser
from test_process import TestProcessProto from test_process import TestProcessProto
@ -41,6 +42,7 @@ class TestConfig(unittest.TestCase):
class TestProcessConfig(TestProcessProto): class TestProcessConfig(TestProcessProto):
"""A test case for keys.dat""" """A test case for keys.dat"""
home = tempfile.mkdtemp()
def test_config_defaults(self): def test_config_defaults(self):
"""Test settings in the generated config""" """Test settings in the generated config"""

View File

@ -28,12 +28,16 @@ class TestProcessProto(unittest.TestCase):
'keys.dat', 'debug.log', 'messages.dat', 'knownnodes.dat', 'keys.dat', 'debug.log', 'messages.dat', 'knownnodes.dat',
'.api_started', 'unittest.lock' '.api_started', 'unittest.lock'
) )
home = None
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
"""Setup environment and start pybitmessage""" """Setup environment and start pybitmessage"""
cls.flag = False cls.flag = False
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir() if not cls.home:
cls.home = tempfile.gettempdir()
cls._cleanup_files()
os.environ['BITMESSAGE_HOME'] = cls.home
put_signal_file(cls.home, 'unittest.lock') put_signal_file(cls.home, 'unittest.lock')
subprocess.Popen( subprocess.Popen(
cls._process_cmd, cls._process_cmd,