Common basic cleanup procedure
This commit is contained in:
parent
1bcffd2853
commit
b65f2d154a
19
src/tests/common.py
Normal file
19
src/tests/common.py
Normal 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
|
|
@ -24,6 +24,8 @@ from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection
|
||||||
from queues import excQueue
|
from queues import excQueue
|
||||||
from version import softwareVersion
|
from version import softwareVersion
|
||||||
|
|
||||||
|
from common import cleanup
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import stem.version as stem_version
|
import stem.version as stem_version
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -48,11 +50,6 @@ def pickle_knownnodes():
|
||||||
}, dst)
|
}, dst)
|
||||||
|
|
||||||
|
|
||||||
def cleanup():
|
|
||||||
"""Cleanup application files"""
|
|
||||||
os.remove(knownnodes_file)
|
|
||||||
|
|
||||||
|
|
||||||
class TestCore(unittest.TestCase):
|
class TestCore(unittest.TestCase):
|
||||||
"""Test case, which runs in main pybitmessage thread"""
|
"""Test case, which runs in main pybitmessage thread"""
|
||||||
|
|
||||||
|
@ -132,7 +129,7 @@ class TestCore(unittest.TestCase):
|
||||||
|
|
||||||
def test_knownnodes_default(self):
|
def test_knownnodes_default(self):
|
||||||
"""test adding default knownnodes if nothing loaded"""
|
"""test adding default knownnodes if nothing loaded"""
|
||||||
cleanup()
|
cleanup(files=('knownnodes.dat',))
|
||||||
self._wipe_knownnodes()
|
self._wipe_knownnodes()
|
||||||
knownnodes.readKnownNodes()
|
knownnodes.readKnownNodes()
|
||||||
self.assertGreaterEqual(
|
self.assertGreaterEqual(
|
||||||
|
|
|
@ -11,6 +11,8 @@ import unittest
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
|
from common import cleanup
|
||||||
|
|
||||||
|
|
||||||
def put_signal_file(path, filename):
|
def put_signal_file(path, filename):
|
||||||
"""Creates file, presence of which is a signal about some event."""
|
"""Creates file, presence of which is a signal about some event."""
|
||||||
|
@ -73,11 +75,7 @@ class TestProcessProto(unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _cleanup_files(cls):
|
def _cleanup_files(cls):
|
||||||
for pfile in cls._files:
|
cleanup(cls.home, cls._files)
|
||||||
try:
|
|
||||||
os.remove(os.path.join(cls.home, pfile))
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user