Skip to content

Commit 50e7e8c

Browse files
committed
tests
1 parent d020123 commit 50e7e8c

51 files changed

Lines changed: 3474 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/badges/coverage.svg

Lines changed: 21 additions & 0 deletions
Loading

.github/workflows/test.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Test Coverage
2+
3+
on:
4+
push:
5+
branches: [main, hybrid-pipeline]
6+
pull_request:
7+
branches: [main, hybrid-pipeline]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 30
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
fetch-depth: 0
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: '3.10'
25+
cache: 'pip'
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install pytest pytest-cov pytest-mock pyyaml coverage-badge
31+
pip install numpy torch transformers sentence-transformers pymilvus
32+
33+
- name: Run tests with coverage
34+
run: |
35+
pytest tests/ \
36+
--cov=src \
37+
--cov-report=term-missing \
38+
--cov-report=xml \
39+
--cov-report=html \
40+
--tb=short \
41+
-v
42+
43+
- name: Generate coverage badge
44+
if: github.event_name == 'push' && github.ref == 'refs/heads/hybrid-pipeline'
45+
run: |
46+
coverage-badge -o .github/badges/coverage.svg -f
47+
48+
- name: Upload coverage reports to Codecov
49+
if: github.event_name == 'push'
50+
uses: codecov/codecov-action@v4
51+
with:
52+
file: ./coverage.xml
53+
flags: unittests
54+
name: codecov-arxplorer
55+
fail_ci_if_error: false
56+
env:
57+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
58+
59+
- name: Upload HTML coverage report
60+
if: always()
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: coverage-report
64+
path: htmlcov/
65+
retention-days: 7
66+
67+
- name: Check coverage threshold
68+
run: |
69+
coverage report --fail-under=70
70+
71+
- name: Commit coverage badge
72+
if: github.event_name == 'push' && github.ref == 'refs/heads/hybrid-pipeline'
73+
run: |
74+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
75+
git config --local user.name "github-actions[bot]"
76+
git add .github/badges/coverage.svg
77+
git diff --staged --quiet || git commit -m "Update coverage badge [skip ci]"
78+
git push

scripts/run_tests.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/usr/bin/env python3
2+
"""
3+
pytest script for ArXplorer test suite.
4+
Usage:
5+
python scripts/run_tests.py # Run all tests
6+
python scripts/run_tests.py --fast # Run only fast unit tests
7+
python scripts/run_tests.py --coverage # Generate coverage report
8+
python scripts/run_tests.py --verbose # Verbose output
9+
"""
10+
11+
import sys
12+
import subprocess
13+
from pathlib import Path
14+
15+
16+
def run_tests(
17+
fast_only: bool = False,
18+
coverage: bool = True,
19+
verbose: bool = False,
20+
html_report: bool = True,
21+
fail_under: int = 70
22+
):
23+
"""
24+
Run pytest with specified options.
25+
26+
Args:
27+
fast_only: Skip slow integration tests
28+
coverage: Generate coverage report
29+
verbose: Verbose test output
30+
html_report: Generate HTML coverage report
31+
fail_under: Minimum coverage percentage required
32+
"""
33+
# Ensure we're in the project root
34+
project_root = Path(__file__).parent.parent
35+
tests_dir = project_root / "tests"
36+
37+
if not tests_dir.exists():
38+
print(f"Tests directory not found: {tests_dir}")
39+
return 1
40+
41+
# Base pytest command
42+
cmd = ["pytest", str(tests_dir)]
43+
44+
# Add markers for fast-only mode
45+
if fast_only:
46+
cmd.extend(["-m", "not slow"])
47+
48+
# Coverage options
49+
if coverage:
50+
cmd.extend([
51+
"--cov=src",
52+
"--cov-report=term-missing",
53+
"--cov-report=xml",
54+
])
55+
if html_report:
56+
cmd.append("--cov-report=html")
57+
58+
# Verbosity
59+
if verbose:
60+
cmd.append("-vv")
61+
else:
62+
cmd.append("-v")
63+
64+
# Show short traceback on failures
65+
cmd.append("--tb=short")
66+
67+
# Color output
68+
cmd.append("--color=yes")
69+
70+
print("=" * 60)
71+
print("Running ArXplorer Test Suite")
72+
print("=" * 60)
73+
print(f"Project root: {project_root}")
74+
print(f"Command: {' '.join(cmd)}")
75+
print()
76+
77+
# Run pytest from project root
78+
result = subprocess.run(cmd, cwd=project_root)
79+
80+
# Check coverage threshold if enabled
81+
if coverage and result.returncode == 0:
82+
print()
83+
print("=" * 60)
84+
print(f"Checking coverage threshold (>= {fail_under}%)")
85+
print("=" * 60)
86+
threshold_cmd = ["coverage", "report", f"--fail-under={fail_under}"]
87+
threshold_result = subprocess.run(threshold_cmd, cwd=project_root)
88+
89+
if threshold_result.returncode != 0:
90+
print()
91+
print(f"overage below {fail_under}% threshold")
92+
return threshold_result.returncode
93+
else:
94+
print()
95+
print(f"Coverage meets {fail_under}% threshold")
96+
97+
return result.returncode
98+
99+
100+
def main():
101+
"""Parse arguments and run tests."""
102+
args = sys.argv[1:]
103+
104+
fast_only = "--fast" in args
105+
no_coverage = "--no-coverage" in args
106+
verbose = "--verbose" in args or "-v" in args
107+
no_html = "--no-html" in args
108+
109+
# Check for help
110+
if "--help" in args or "-h" in args:
111+
print(__doc__)
112+
return 0
113+
114+
exit_code = run_tests(
115+
fast_only=fast_only,
116+
coverage=not no_coverage,
117+
verbose=verbose,
118+
html_report=not no_html,
119+
fail_under=70
120+
)
121+
122+
if exit_code == 0:
123+
print()
124+
print("=" * 60)
125+
print("All tests passed!")
126+
print("=" * 60)
127+
if not no_coverage:
128+
print()
129+
print("Coverage reports generated:")
130+
print(" - Terminal: (displayed above)")
131+
print(" - XML: coverage.xml")
132+
if not no_html:
133+
print(" - HTML: htmlcov/index.html")
134+
else:
135+
print()
136+
print("=" * 60)
137+
print("Tests failed")
138+
print("=" * 60)
139+
140+
return exit_code
141+
142+
143+
if __name__ == "__main__":
144+
sys.exit(main())
9.33 KB
Binary file not shown.
11.5 KB
Binary file not shown.
1.68 KB
Binary file not shown.
3.14 KB
Binary file not shown.
27.1 KB
Binary file not shown.
46.4 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)