-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
121 lines (99 loc) · 2.97 KB
/
run_tests.py
File metadata and controls
121 lines (99 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
"""
This Source Code Form is subject to the terms of the Oxford Nanopore
Technologies, Ltd. Public License, v. 1.0. Full licence can be found
at https://github.com/ParallelSquared/JMod/blob/main/LICENSE.txt
"""
"""
Test runner for JMod
Run this script to execute all tests in the test suite
"""
import sys
import os
import subprocess
import argparse
from src.logger import logger
def run_tests(test_path=None, verbose=False, coverage=False):
"""
Run the JMod test suite using pytest
Args:
test_path: Specific test file or directory to run (default: all tests)
verbose: Enable verbose output
coverage: Generate coverage report
"""
# Base pytest command
cmd = [sys.executable, "-m", "pytest"]
# Add test directory or specific test
if test_path:
cmd.append(test_path)
else:
cmd.append("tests/")
# Add verbosity
if verbose:
cmd.append("-v")
else:
cmd.append("-q")
# Add coverage if requested
if coverage:
cmd.extend(["--cov=.", "--cov-report=html", "--cov-report=term"])
# Add color output
cmd.append("--color=yes")
# Show print statements
cmd.append("-s")
logger.info(f"Running tests with command: {' '.join(cmd)}")
logger.info("-" * 70)
# Run the tests
result = subprocess.run(cmd)
return result.returncode
def main():
parser = argparse.ArgumentParser(description="Run JMod test suite")
parser.add_argument(
"test_path",
nargs="?",
help="Specific test file or directory to run (default: all tests)"
)
parser.add_argument(
"-v", "--verbose",
action="store_true",
help="Enable verbose output"
)
parser.add_argument(
"-c", "--coverage",
action="store_true",
help="Generate coverage report"
)
parser.add_argument(
"--dummy",
action="store_true",
help="Run only dummy tests"
)
parser.add_argument(
"--misc",
action="store_true",
help="Run only misc_functions tests"
)
args = parser.parse_args()
# Handle specific test selections
test_path = args.test_path
if args.dummy:
test_path = "tests/test_dummy.py"
elif args.misc:
test_path = "tests/test_misc_functions.py"
# Check if pytest is installed
try:
import pytest
except ImportError:
logger.error("Error: pytest is not installed!")
logger.error("Please install it with: pip install pytest")
if args.coverage:
logger.warning("For coverage support, also install: pip install pytest-cov")
return 1
# Run the tests
exit_code = run_tests(test_path, args.verbose, args.coverage)
if exit_code == 0:
logger.info("\n✅ All tests passed!")
else:
logger.error("\n❌ Some tests failed!")
return exit_code
if __name__ == "__main__":
sys.exit(main())