From eff760bd2b79f6db1de00a9d871e45ada673c8fc Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Thu, 15 Nov 2018 21:26:15 +0300 Subject: Tests: added command line arguments parsing in tests. Added the following command line arguments: -d, --detailed: Show detailed output for tests Usage examples: ./test/run.py --detailed python3 test/test_access_log.py --detailed python3 test/test_access_log.py -d TestUnitAccessLog.test_access_log_ipv6 -l, --log: Save unit.log after the test execution Usage examples: ./test/run.py -l python3 test/test_access_log.py -l python3 test/test_access_log.py --log TestUnitAccessLog.test_access_log_ipv6 --- test/unit.py | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'test/unit.py') diff --git a/test/unit.py b/test/unit.py index a5f96968..0415d83a 100644 --- a/test/unit.py +++ b/test/unit.py @@ -7,6 +7,7 @@ import time import shutil import socket import select +import argparse import platform import tempfile import unittest @@ -19,6 +20,27 @@ class TestUnit(unittest.TestCase): architecture = platform.architecture()[0] maxDiff = None + detailed = False + save_log = False + + def __init__(self, methodName='runTest'): + super().__init__(methodName) + + if re.match(r'.*\/run\.py$', sys.argv[0]): + args, rest = TestUnit._parse_args() + + TestUnit._set_args(args) + + @staticmethod + def main(): + args, rest = TestUnit._parse_args() + + sys.argv = sys.argv[:1] + rest + + TestUnit._set_args(args) + + unittest.main() + def setUp(self): self._run() @@ -49,7 +71,7 @@ class TestUnit(unittest.TestCase): # remove unit.log - if '--leave' not in sys.argv and success: + if not TestUnit.save_log and success: shutil.rmtree(self.testdir) else: @@ -227,6 +249,22 @@ class TestUnit(unittest.TestCase): return ret + @staticmethod + def _parse_args(): + parser = argparse.ArgumentParser(add_help=False) + + parser.add_argument('-d', '--detailed', dest='detailed', + action='store_true', help='Detailed output for tests') + parser.add_argument('-l', '--log', dest='save_log', + action='store_true', help='Save unit.log after the test execution') + + return parser.parse_known_args() + + @staticmethod + def _set_args(args): + TestUnit.detailed = args.detailed + TestUnit.save_log = args.save_log + def _print_path_to_log(self): print('Path to unit.log:\n' + self.testdir + '/unit.log') @@ -296,7 +334,7 @@ class TestUnitHTTP(TestUnit): sock.sendall(req) - if '--verbose' in sys.argv: + if TestUnit.detailed: print('>>>', req, sep='\n') resp = '' @@ -305,7 +343,7 @@ class TestUnitHTTP(TestUnit): enc = 'utf-8' if 'encoding' not in kwargs else kwargs['encoding'] resp = self.recvall(sock).decode(enc) - if '--verbose' in sys.argv: + if TestUnit.detailed: print('<<<', resp.encode('utf-8'), sep='\n') if 'raw_resp' not in kwargs: -- cgit From 41d3d63758fc3846d5a09afd3b33aac19231942a Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Thu, 15 Nov 2018 21:26:15 +0300 Subject: Tests: class prefix made optional. --- test/unit.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/unit.py') diff --git a/test/unit.py b/test/unit.py index 0415d83a..c3efef26 100644 --- a/test/unit.py +++ b/test/unit.py @@ -31,10 +31,14 @@ class TestUnit(unittest.TestCase): TestUnit._set_args(args) - @staticmethod - def main(): + @classmethod + def main(cls): args, rest = TestUnit._parse_args() + for i, arg in enumerate(rest): + if arg[:5] == 'test_': + rest[i] = cls.__name__ + '.' + arg + sys.argv = sys.argv[:1] + rest TestUnit._set_args(args) -- cgit From 0fdc7c3a55daceb54c034a51b30f06a932236965 Mon Sep 17 00:00:00 2001 From: Sergey Kandaurov Date: Thu, 25 Oct 2018 15:43:48 +0300 Subject: Tests: Node.js application tests. --- test/unit.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/unit.py') diff --git a/test/unit.py b/test/unit.py index c3efef26..e88ed684 100644 --- a/test/unit.py +++ b/test/unit.py @@ -117,6 +117,12 @@ class TestUnit(unittest.TestCase): except: m = None + elif module == 'node': + if os.path.isdir(self.pardir + '/node/node_modules'): + m = module + else: + m = None + elif module == 'openssl': try: subprocess.check_output(['which', 'openssl']) @@ -558,6 +564,35 @@ class TestUnitApplicationGo(TestUnitApplicationProto): } }) +class TestUnitApplicationNode(TestUnitApplicationProto): + def load(self, script, name='app.js'): + + # copy application + + shutil.copytree(self.current_dir + '/node/' + script, + self.testdir + '/node') + + # link modules + + os.symlink(self.pardir + '/node/node_modules', + self.testdir + '/node/node_modules') + + self.conf({ + "listeners": { + "*:7080": { + "application": script + } + }, + "applications": { + script: { + "type": "external", + "processes": { "spare": 0 }, + "working_directory": self.testdir + '/node', + "executable": name + } + } + }) + class TestUnitApplicationPerl(TestUnitApplicationProto): def load(self, script, name='psgi.pl'): self.conf({ -- cgit