Style fixes and docstrings for tests

This commit is contained in:
Dmitri Bogomolov 2018-04-16 21:19:30 +03:00
parent a3300ba8f1
commit d8b4682ee9
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
4 changed files with 31 additions and 4 deletions

View File

@ -1,7 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python
"""
Utility configured as apinotifypath in bitmessagesettings
when pybitmessage started in test mode.
"""
import sys import sys
import tempfile import tempfile
from test_process import put_signal_file from test_process import put_signal_file

View File

@ -1,3 +1,7 @@
"""
Tests for core.
"""
import unittest import unittest
@ -8,5 +12,6 @@ class TestCore(unittest.TestCase):
def run(): def run():
"""Starts all tests defined in this module"""
suite = unittest.TestLoader().loadTestsFromTestCase(TestCore) suite = unittest.TestLoader().loadTestsFromTestCase(TestCore)
return unittest.TextTestRunner(verbosity=2).run(suite) return unittest.TextTestRunner(verbosity=2).run(suite)

View File

@ -1,12 +1,17 @@
import xmlrpclib """
Tests using API.
"""
import base64 import base64
import json import json
import xmlrpclib
from time import sleep from time import sleep
from test_process import TestProcessProto from test_process import TestProcessProto
class TestAPI(TestProcessProto): class TestAPI(TestProcessProto):
"""A test case for API"""
_process_cmd = ['pybitmessage', '-t'] _process_cmd = ['pybitmessage', '-t']
_seed = base64.encodestring( _seed = base64.encodestring(
'TIGER, tiger, burning bright. In the forests of the night' 'TIGER, tiger, burning bright. In the forests of the night'
@ -14,11 +19,12 @@ class TestAPI(TestProcessProto):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
"""Setup XMLRPC proxy for pybitmessage API"""
super(TestAPI, cls).setUpClass() super(TestAPI, cls).setUpClass()
cls.addresses = [] cls.addresses = []
cls.api = xmlrpclib.ServerProxy( cls.api = xmlrpclib.ServerProxy(
"http://username:password@127.0.0.1:8442/") "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'): if cls._get_readline('.api_started'):
print('API start detected!') print('API start detected!')
return return

View File

@ -1,19 +1,27 @@
import unittest """
import subprocess Common reusable code for tests and tests for pybitmessage process.
"""
import os import os
import signal import signal
import subprocess
import tempfile import tempfile
import time import time
import unittest
import psutil import psutil
def put_signal_file(path, filename): 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: with open(os.path.join(path, filename), 'wb') as outfile:
outfile.write(str(time.time())) outfile.write(str(time.time()))
class TestProcessProto(unittest.TestCase): 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'] _process_cmd = ['pybitmessage', '-d']
_threads_count = 14 _threads_count = 14
_files = ( _files = (
@ -23,6 +31,7 @@ class TestProcessProto(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
"""Setup environment and start pybitmessage"""
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir() cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
put_signal_file(cls.home, 'unittest.lock') put_signal_file(cls.home, 'unittest.lock')
subprocess.call(cls._process_cmd) subprocess.call(cls._process_cmd)
@ -48,6 +57,7 @@ class TestProcessProto(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
"""Ensures that pybitmessage stopped and removes files"""
cls.process.send_signal(signal.SIGTERM) cls.process.send_signal(signal.SIGTERM)
try: try:
cls.process.wait(5) cls.process.wait(5)
@ -80,6 +90,7 @@ class TestProcessProto(unittest.TestCase):
class TestProcess(TestProcessProto): class TestProcess(TestProcessProto):
"""A test case for pybitmessage process"""
def test_process_name(self): def test_process_name(self):
"""Check PyBitmessage process name""" """Check PyBitmessage process name"""
self.assertEqual(self.process.name(), 'PyBitmessage') self.assertEqual(self.process.name(), 'PyBitmessage')