diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-11-15 21:26:15 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-11-15 21:26:15 +0300 |
commit | eff760bd2b79f6db1de00a9d871e45ada673c8fc (patch) | |
tree | 13a051936dc60d006d19ac0c289d49f06eeac0c7 /test | |
parent | c1fd6cb589d08a5feae5399d176e6e02599c823d (diff) | |
download | unit-eff760bd2b79f6db1de00a9d871e45ada673c8fc.tar.gz unit-eff760bd2b79f6db1de00a9d871e45ada673c8fc.tar.bz2 |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/test_access_log.py | 2 | ||||
-rw-r--r-- | test/test_configuration.py | 2 | ||||
-rw-r--r-- | test/test_go_application.py | 2 | ||||
-rw-r--r-- | test/test_http_header.py | 2 | ||||
-rw-r--r-- | test/test_perl_application.py | 2 | ||||
-rw-r--r-- | test/test_php_application.py | 2 | ||||
-rw-r--r-- | test/test_php_basic.py | 2 | ||||
-rw-r--r-- | test/test_python_application.py | 2 | ||||
-rw-r--r-- | test/test_python_basic.py | 2 | ||||
-rw-r--r-- | test/test_python_environment.py | 2 | ||||
-rw-r--r-- | test/test_python_procman.py | 2 | ||||
-rw-r--r-- | test/test_ruby_application.py | 2 | ||||
-rw-r--r-- | test/test_settings.py | 2 | ||||
-rw-r--r-- | test/test_tls.py | 2 | ||||
-rw-r--r-- | test/unit.py | 44 |
15 files changed, 55 insertions, 17 deletions
diff --git a/test/test_access_log.py b/test/test_access_log.py index 05f5f54a..c8464796 100644 --- a/test/test_access_log.py +++ b/test/test_access_log.py @@ -305,4 +305,4 @@ Connection: close 'reopen 2') if __name__ == '__main__': - unittest.main() + TestUnitAccessLog.main() diff --git a/test/test_configuration.py b/test/test_configuration.py index 6db65bb3..02705afe 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -218,4 +218,4 @@ class TestUnitConfiguration(unit.TestUnitControl): }), 'no port') if __name__ == '__main__': - unittest.main() + TestUnitConfiguration.main() diff --git a/test/test_go_application.py b/test/test_go_application.py index 650d1c27..fd80bf5b 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -151,4 +151,4 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): 'arguments empty') if __name__ == '__main__': - unittest.main() + TestUnitGoApplication.main() diff --git a/test/test_http_header.py b/test/test_http_header.py index 1ca0920d..b850831d 100644 --- a/test/test_http_header.py +++ b/test/test_http_header.py @@ -163,4 +163,4 @@ a self.assertEqual(resp['status'], 200, 'transfer encoding chunked') if __name__ == '__main__': - unittest.main() + TestUnitHTTPHeader.main() diff --git a/test/test_perl_application.py b/test/test_perl_application.py index 09e3d576..c9cb3f0c 100644 --- a/test/test_perl_application.py +++ b/test/test_perl_application.py @@ -167,4 +167,4 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl): self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') if __name__ == '__main__': - unittest.main() + TestUnitPerlApplication.main() diff --git a/test/test_php_application.py b/test/test_php_application.py index 0dbc743d..1b6dd497 100644 --- a/test/test_php_application.py +++ b/test/test_php_application.py @@ -205,4 +205,4 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP): 'ini value repeat') if __name__ == '__main__': - unittest.main() + TestUnitPHPApplication.main() diff --git a/test/test_php_basic.py b/test/test_php_basic.py index 9e0ce822..1ea46c91 100644 --- a/test/test_php_basic.py +++ b/test/test_php_basic.py @@ -139,4 +139,4 @@ class TestUnitPHPBasic(unit.TestUnitControl): 'delete app again') if __name__ == '__main__': - unittest.main() + TestUnitPHPBasic.main() diff --git a/test/test_python_application.py b/test/test_python_application.py index e71b6432..667047bc 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -349,4 +349,4 @@ Connection: close self.assertEqual(self.get()['body'], '0123456789', 'write') if __name__ == '__main__': - unittest.main() + TestUnitPythonApplication.main() diff --git a/test/test_python_basic.py b/test/test_python_basic.py index 4cb194f6..b5179dea 100644 --- a/test/test_python_basic.py +++ b/test/test_python_basic.py @@ -149,4 +149,4 @@ class TestUnitPythonBasic(unit.TestUnitControl): 'delete app again') if __name__ == '__main__': - unittest.main() + TestUnitPythonBasic.main() diff --git a/test/test_python_environment.py b/test/test_python_environment.py index 907ad57c..71e4d5b7 100644 --- a/test/test_python_environment.py +++ b/test/test_python_environment.py @@ -125,4 +125,4 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython): })['body'], pwd_default, 'restore default') if __name__ == '__main__': - unittest.main() + TestUnitPythonEnvironment.main() diff --git a/test/test_python_procman.py b/test/test_python_procman.py index 297484eb..65268d49 100644 --- a/test/test_python_procman.py +++ b/test/test_python_procman.py @@ -245,4 +245,4 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython): self.assertEqual(len(self.pids_for_process()), 0, 'stop all') if __name__ == '__main__': - unittest.main() + TestUnitPythonProcman.main() diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index 77040127..57ab88cd 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -284,4 +284,4 @@ class TestUnitRubyApplication(unit.TestUnitApplicationRuby): self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') if __name__ == '__main__': - unittest.main() + TestUnitRubyApplication.main() diff --git a/test/test_settings.py b/test/test_settings.py index 816dcb5e..b4ac33dc 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -170,4 +170,4 @@ Content-Length: %d 'settings'), 'settings negative value') if __name__ == '__main__': - unittest.main() + TestUnitSettings.main() diff --git a/test/test_tls.py b/test/test_tls.py index aaf939ec..fa5c9754 100644 --- a/test/test_tls.py +++ b/test/test_tls.py @@ -417,4 +417,4 @@ Connection: close self.assertEqual(resp['body'], '0123456789', 'application respawn body') if __name__ == '__main__': - unittest.main() + TestUnitTLS.main() 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: |