Style fixes and docstrings for tests
This commit is contained in:
parent
a3300ba8f1
commit
d8b4682ee9
|
@ -1,7 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
"""
|
||||
Utility configured as apinotifypath in bitmessagesettings
|
||||
when pybitmessage started in test mode.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from test_process import put_signal_file
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
"""
|
||||
Tests for core.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
|
@ -8,5 +12,6 @@ class TestCore(unittest.TestCase):
|
|||
|
||||
|
||||
def run():
|
||||
"""Starts all tests defined in this module"""
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestCore)
|
||||
return unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
import xmlrpclib
|
||||
"""
|
||||
Tests using API.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import json
|
||||
import xmlrpclib
|
||||
from time import sleep
|
||||
|
||||
from test_process import TestProcessProto
|
||||
|
||||
|
||||
class TestAPI(TestProcessProto):
|
||||
"""A test case for API"""
|
||||
_process_cmd = ['pybitmessage', '-t']
|
||||
_seed = base64.encodestring(
|
||||
'TIGER, tiger, burning bright. In the forests of the night'
|
||||
|
@ -14,11 +19,12 @@ class TestAPI(TestProcessProto):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Setup XMLRPC proxy for pybitmessage API"""
|
||||
super(TestAPI, cls).setUpClass()
|
||||
cls.addresses = []
|
||||
cls.api = xmlrpclib.ServerProxy(
|
||||
"http://username:password@127.0.0.1:8442/")
|
||||
for tick in range(0, 5):
|
||||
for _ in range(0, 5):
|
||||
if cls._get_readline('.api_started'):
|
||||
print('API start detected!')
|
||||
return
|
||||
|
|
|
@ -1,19 +1,27 @@
|
|||
import unittest
|
||||
import subprocess
|
||||
"""
|
||||
Common reusable code for tests and tests for pybitmessage process.
|
||||
"""
|
||||
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import psutil
|
||||
|
||||
|
||||
def put_signal_file(path, filename):
|
||||
"""Creates file, presence of which is a signal about some event."""
|
||||
with open(os.path.join(path, filename), 'wb') as outfile:
|
||||
outfile.write(str(time.time()))
|
||||
|
||||
|
||||
class TestProcessProto(unittest.TestCase):
|
||||
"""Test case implementing common logic for external testing:
|
||||
it starts pybitmessage in setUpClass() and stops it in tearDownClass()
|
||||
"""
|
||||
_process_cmd = ['pybitmessage', '-d']
|
||||
_threads_count = 14
|
||||
_files = (
|
||||
|
@ -23,6 +31,7 @@ class TestProcessProto(unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Setup environment and start pybitmessage"""
|
||||
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
|
||||
put_signal_file(cls.home, 'unittest.lock')
|
||||
subprocess.call(cls._process_cmd)
|
||||
|
@ -48,6 +57,7 @@ class TestProcessProto(unittest.TestCase):
|
|||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
"""Ensures that pybitmessage stopped and removes files"""
|
||||
cls.process.send_signal(signal.SIGTERM)
|
||||
try:
|
||||
cls.process.wait(5)
|
||||
|
@ -80,6 +90,7 @@ class TestProcessProto(unittest.TestCase):
|
|||
|
||||
|
||||
class TestProcess(TestProcessProto):
|
||||
"""A test case for pybitmessage process"""
|
||||
def test_process_name(self):
|
||||
"""Check PyBitmessage process name"""
|
||||
self.assertEqual(self.process.name(), 'PyBitmessage')
|
||||
|
|
Reference in New Issue
Block a user