-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.sh
More file actions
76 lines (66 loc) · 2.1 KB
/
coverage.sh
File metadata and controls
76 lines (66 loc) · 2.1 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
echo "[1/2] Running pytest with coverage..."
python -m pytest \
--cov=robot \
--cov-report=term-missing \
--cov-report=json:.tmp_tests/coverage.json \
-q \
-p no:cacheprovider \
--basetemp .tmp_tests/pytest \
--ignore pytest-cache-files-6mndw5k6 \
--ignore pytest-cache-files-io38dnfk
echo
echo "[2/2] Counting code lines..."
python - <<'PY'
import json
from pathlib import Path
root = Path(".").resolve()
coverage_file = root / ".tmp_tests" / "coverage.json"
def is_ignored(path: Path) -> bool:
parts = set(path.parts)
return (
".tmp_tests" in parts
or "__pycache__" in parts
or ".git" in parts
or ".venv" in parts
)
def count_lines(path: Path) -> int:
try:
return len(path.read_text(encoding="utf-8", errors="ignore").splitlines())
except Exception:
return 0
robot_file = root / "robot.py"
tests = sorted(p for p in (root / "tests").rglob("*.py") if not is_ignored(p))
repo_py = sorted(
p for p in root.rglob("*.py")
if not is_ignored(p) and "tests" not in p.parts
)
robot_lines = count_lines(robot_file) if robot_file.exists() else 0
tests_lines = sum(count_lines(p) for p in tests)
repo_code_lines = sum(count_lines(p) for p in repo_py)
total_lines = repo_code_lines + tests_lines
coverage_pct = None
if coverage_file.exists():
try:
payload = json.loads(coverage_file.read_text(encoding="utf-8"))
coverage_pct = float(payload.get("totals", {}).get("percent_covered", 0.0))
except Exception:
coverage_pct = None
print(f"robot.py lines: {robot_lines}")
print(f"system python lines (excluding tests): {repo_code_lines}")
print(f"test python lines: {tests_lines}")
print(f"total python lines: {total_lines}")
print()
print("Summary:")
print("--------")
if coverage_pct is None:
print("test coverage: unavailable")
else:
print(f"test coverage: {coverage_pct:.2f}%")
print(f"system code lines: {repo_code_lines}")
print(f"test code lines: {tests_lines}")
print(f"total code lines: {total_lines}")
PY