Common basic cleanup procedure

This commit is contained in:
Dmitri Bogomolov 2020-10-28 18:01:55 +02:00
parent 1bcffd2853
commit b65f2d154a
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
3 changed files with 25 additions and 11 deletions

19
src/tests/common.py Normal file
View File

@ -0,0 +1,19 @@
import os
_files = (
'keys.dat', 'debug.log', 'messages.dat', 'knownnodes.dat',
'.api_started', 'unittest.lock'
)
def cleanup(home=None, files=_files):
"""Cleanup application files"""
if not home:
import state
home = state.appdata
for pfile in files:
try:
os.remove(os.path.join(home, pfile))
except OSError:
pass

View File

@ -24,6 +24,8 @@ from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection
from queues import excQueue
from version import softwareVersion
from common import cleanup
try:
import stem.version as stem_version
except ImportError:
@ -48,11 +50,6 @@ def pickle_knownnodes():
}, dst)
def cleanup():
"""Cleanup application files"""
os.remove(knownnodes_file)
class TestCore(unittest.TestCase):
"""Test case, which runs in main pybitmessage thread"""
@ -132,7 +129,7 @@ class TestCore(unittest.TestCase):
def test_knownnodes_default(self):
"""test adding default knownnodes if nothing loaded"""
cleanup()
cleanup(files=('knownnodes.dat',))
self._wipe_knownnodes()
knownnodes.readKnownNodes()
self.assertGreaterEqual(

View File

@ -11,6 +11,8 @@ import unittest
import psutil
from common import cleanup
def put_signal_file(path, filename):
"""Creates file, presence of which is a signal about some event."""
@ -73,11 +75,7 @@ class TestProcessProto(unittest.TestCase):
@classmethod
def _cleanup_files(cls):
for pfile in cls._files:
try:
os.remove(os.path.join(cls.home, pfile))
except OSError:
pass
cleanup(cls.home, cls._files)
@classmethod
def tearDownClass(cls):