annotate NewTests/main.py @ 474:6917a26881ed

NewTests working with Docker
author Alain Mazy <am@osimis.io>
date Mon, 02 May 2022 17:05:42 +0200
parents 4ee85b016a40
children fe37cf5e9c02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 import argparse
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 import unittest
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 import os
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 import sys
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
5 import argparse
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
6 from helpers import Helpers
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 import pathlib
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
8 # python3 main.py --orthanc_under_tests_exe=/home/alain/o/build/orthanc/Orthanc --pattern=Housekeeper.test_housekeeper.TestHousekeeper.* --plugin=/home/alain/o/build/orthanc/libHousekeeper.so
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
9
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 here = pathlib.Path(__file__).parent.resolve()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
11
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
12
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 def load_tests(loader=None, tests=None, pattern='test_*.py'):
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 this_dir = os.path.dirname(__file__)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
15 package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 return package_tests
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
17
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 if __name__ == '__main__':
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
19
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 parser = argparse.ArgumentParser(description='Executes Orthanc integration tests.')
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
21 parser.add_argument('-k', '--pattern', dest='test_name_patterns', action='append', type=str, help='a test pattern (ex: Housekeeper.toto')
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
22 parser.add_argument('--orthanc_under_tests_hostname', type=str, default="localhost", help="orthanc under tests hostname")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
23 parser.add_argument('--orthanc_under_tests_http_port', type=int, default=8042, help="orthanc under tests HTTP port")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 parser.add_argument('--orthanc_under_tests_exe', type=str, default=None, help="path to the orthanc executable (if it must be launched by this script)")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
25 parser.add_argument('--orthanc_previous_version_exe', type=str, default=None, help="path to the orthanc executable used to prepare previous version of storage/db (if it must be launched by this script and if different from orthanc_under_tests_exe)")
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
26 parser.add_argument('--orthanc_under_tests_docker_image', type=str, default=None, help="Docker image of the orthanc under tests (if it must be launched by this script)")
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
27 parser.add_argument('--orthanc_previous_version_docker_image', type=str, default=None, help="Docker image of the orthanc version used to prepare previous version of storage/db (if it must be launched by this script)")
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 parser.add_argument('--skip_preparation', action='store_true', help="if this is a multi stage tests with preparations, skip the preparation")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 parser.add_argument('--break_after_preparation', action='store_true', help="if this is a multi stage tests with preparations, pause after the preparation (such that you can start your own orthanc-under-tests in your debugger)")
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 parser.add_argument('-p', '--plugin', dest='plugins', action='append', type=str, help='path to a plugin to add to configuration')
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
31
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
32
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 args = parser.parse_args()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
34
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
35 loader = unittest.TestLoader()
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
36 loader.testNamePatterns = args.test_name_patterns
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
37
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 Helpers.orthanc_under_tests_hostname = args.orthanc_under_tests_hostname
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 Helpers.orthanc_under_tests_http_port = args.orthanc_under_tests_http_port
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
40 Helpers.plugins = args.plugins
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
41
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
42 Helpers.orthanc_under_tests_exe = args.orthanc_under_tests_exe
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
43 Helpers.orthanc_under_tests_docker_image = args.orthanc_under_tests_docker_image
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
44
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
45 if args.orthanc_previous_version_exe:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
46 Helpers.orthanc_previous_version_exe = args.orthanc_previous_version_exe
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
47 else:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
48 Helpers.orthanc_previous_version_exe = args.orthanc_under_tests_exe
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
49
474
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
50 if args.orthanc_previous_version_docker_image:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
51 Helpers.orthanc_previous_version_docker_image = args.orthanc_previous_version_docker_image
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
52 else:
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
53 Helpers.orthanc_previous_version_docker_image = args.orthanc_under_tests_docker_image
6917a26881ed NewTests working with Docker
Alain Mazy <am@osimis.io>
parents: 473
diff changeset
54
473
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
55 if args.skip_preparation:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
56 Helpers.skip_preparation = True
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
57 if args.break_after_preparation:
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
58 Helpers.break_after_preparation = True
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
59
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
60 result = unittest.TextTestRunner(verbosity=2).run(load_tests(loader=loader))
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
61 if not result.wasSuccessful():
4ee85b016a40 added NewTests framework - only the Housekeeper tests right now
Alain Mazy <am@osimis.io>
parents:
diff changeset
62 sys.exit(1)