2020-02-03 23:05:45 +01:00
|
|
|
#!/usr/bin/env python3
|
2017-07-24 22:38:48 +01:00
|
|
|
|
2022-07-14 13:36:57 +02:00
|
|
|
|
2022-06-27 19:08:46 +01:00
|
|
|
import argparse
|
2025-05-14 13:04:07 -04:00
|
|
|
import functools
|
2019-11-12 23:51:27 +00:00
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2020-06-18 02:00:30 +02:00
|
|
|
from pathlib import Path
|
2017-03-20 23:54:29 +00:00
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
if __name__ == "__main__":
|
2025-04-09 09:58:57 -04:00
|
|
|
if sys.version_info < (3, 13):
|
|
|
|
|
default_cpu_count = os.cpu_count() or 2
|
|
|
|
|
else:
|
|
|
|
|
default_cpu_count = os.process_cpu_count() or 2
|
|
|
|
|
|
2025-05-14 13:04:07 -04:00
|
|
|
make_parser = functools.partial(argparse.ArgumentParser, allow_abbrev=False)
|
|
|
|
|
if sys.version_info >= (3, 14):
|
|
|
|
|
make_parser = functools.partial(make_parser, color=True, suggest_on_error=True)
|
|
|
|
|
parser = make_parser()
|
2022-06-29 20:18:08 +01:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--run-podman", action="store_true", default=False, help="run podman tests (linux only)"
|
|
|
|
|
)
|
2024-02-29 22:27:09 +01:00
|
|
|
parser.add_argument(
|
|
|
|
|
"--num-processes",
|
|
|
|
|
action="store",
|
|
|
|
|
default=default_cpu_count,
|
|
|
|
|
help="number of processes to use for testing",
|
|
|
|
|
)
|
2022-06-27 19:08:46 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
2017-09-06 15:07:58 +02:00
|
|
|
# move cwd to the project root
|
2020-06-18 02:00:30 +02:00
|
|
|
os.chdir(Path(__file__).resolve().parents[1])
|
2017-09-01 13:32:34 +01:00
|
|
|
|
2022-06-27 19:08:46 +01:00
|
|
|
# unit tests
|
2021-05-03 11:45:43 -04:00
|
|
|
unit_test_args = [sys.executable, "-m", "pytest", "unit_test"]
|
2022-06-27 19:08:46 +01:00
|
|
|
|
2024-09-12 21:32:43 +02:00
|
|
|
if sys.platform.startswith("linux") and os.environ.get("CIBW_PLATFORM", "linux") == "linux":
|
2022-06-27 19:08:46 +01:00
|
|
|
# run the docker unit tests only on Linux
|
2021-05-03 11:45:43 -04:00
|
|
|
unit_test_args += ["--run-docker"]
|
2022-06-29 20:18:08 +01:00
|
|
|
|
|
|
|
|
if args.run_podman:
|
|
|
|
|
unit_test_args += ["--run-podman"]
|
2022-06-27 19:08:46 +01:00
|
|
|
|
2025-03-28 22:33:51 +08:00
|
|
|
print(
|
|
|
|
|
"\n\n================================== UNIT TESTS ==================================",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
2021-02-14 12:56:33 -05:00
|
|
|
subprocess.run(unit_test_args, check=True)
|
2017-09-01 13:32:34 +01:00
|
|
|
|
2025-03-28 22:33:51 +08:00
|
|
|
# Run the serial integration tests without multiple processes
|
|
|
|
|
serial_integration_test_args = [
|
|
|
|
|
sys.executable,
|
|
|
|
|
"-m",
|
|
|
|
|
"pytest",
|
|
|
|
|
"-m",
|
|
|
|
|
"serial",
|
|
|
|
|
"-x",
|
|
|
|
|
"--durations",
|
|
|
|
|
"0",
|
|
|
|
|
"--timeout=2400",
|
|
|
|
|
"test",
|
|
|
|
|
"-vv",
|
|
|
|
|
]
|
|
|
|
|
print(
|
|
|
|
|
"\n\n=========================== SERIAL INTEGRATION TESTS ===========================",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
|
|
|
|
subprocess.run(serial_integration_test_args, check=True)
|
|
|
|
|
|
|
|
|
|
# Non-serial integration tests
|
2022-06-27 19:08:46 +01:00
|
|
|
integration_test_args = [
|
|
|
|
|
sys.executable,
|
|
|
|
|
"-m",
|
|
|
|
|
"pytest",
|
2025-03-28 22:33:51 +08:00
|
|
|
"-m",
|
|
|
|
|
"not serial",
|
2024-02-29 22:27:09 +01:00
|
|
|
f"--numprocesses={args.num_processes}",
|
2022-06-27 19:08:46 +01:00
|
|
|
"-x",
|
|
|
|
|
"--durations",
|
|
|
|
|
"0",
|
|
|
|
|
"--timeout=2400",
|
|
|
|
|
"test",
|
2025-03-12 04:48:35 +08:00
|
|
|
"-vv",
|
2022-06-27 19:08:46 +01:00
|
|
|
]
|
2022-06-29 20:18:08 +01:00
|
|
|
|
|
|
|
|
if sys.platform.startswith("linux") and args.run_podman:
|
2022-06-27 19:08:46 +01:00
|
|
|
integration_test_args += ["--run-podman"]
|
|
|
|
|
|
2025-03-28 22:33:51 +08:00
|
|
|
print(
|
|
|
|
|
"\n\n========================= NON-SERIAL INTEGRATION TESTS =========================",
|
|
|
|
|
flush=True,
|
|
|
|
|
)
|
2022-06-27 19:08:46 +01:00
|
|
|
subprocess.run(integration_test_args, check=True)
|