From d8b4682ee9b3cc3a9a367b84d9adc1db0f8162ea Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 16 Apr 2018 21:19:30 +0300 Subject: [PATCH] Style fixes and docstrings for tests --- src/tests/apinotify_handler.py | 5 +++++ src/tests/core.py | 5 +++++ src/tests/test_api.py | 10 ++++++++-- src/tests/test_process.py | 15 +++++++++++++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/tests/apinotify_handler.py b/src/tests/apinotify_handler.py index f7674dad..4574d46a 100755 --- a/src/tests/apinotify_handler.py +++ b/src/tests/apinotify_handler.py @@ -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 diff --git a/src/tests/core.py b/src/tests/core.py index 63589da9..3738c32e 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -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) diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 942ad9bd..8915a735 100644 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -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 diff --git a/src/tests/test_process.py b/src/tests/test_process.py index 06fc2998..45e0317e 100644 --- a/src/tests/test_process.py +++ b/src/tests/test_process.py @@ -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')