-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·85 lines (62 loc) · 2.07 KB
/
run-tests.sh
File metadata and controls
executable file
·85 lines (62 loc) · 2.07 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
#!/usr/bin/env bash
#
# run the python tests
#
GIT_ROOT="$(git rev-parse --show-toplevel)"
# Use $TMPDIR on macOS (user-specific temp dir) or /tmp on Linux
# Remove trailing slash if present to ensure clean path construction
TMP_BASE="${TMPDIR:-/tmp}"
TMP_BASE="${TMP_BASE%/}"
TEST_VENV_DIR="${TMP_BASE}/ekglib-test-venv"
VIRTUAL_ENV="${TEST_VENV_DIR}"
flag_file="${TMP_BASE}/ekglib-last-checked-environment.flag"
function checkEnvironment() {
cd "${GIT_ROOT}" || return $?
echo "========================== check environment"
touch "${flag_file}" || return 1
echo "Using test virtual environment at: ${VIRTUAL_ENV}"
# Create venv in temp directory if it doesn't exist
if [[ ! -d "${VIRTUAL_ENV}" ]] || [[ ! -f "${VIRTUAL_ENV}/bin/python" ]] ; then
echo "Creating test virtual environment..."
uv venv "${VIRTUAL_ENV}" || return 1
fi
# Install dependencies into the test venv
# Use uv sync to install project, runtime dependencies, and dev dependencies
# UV_PROJECT_ENVIRONMENT tells uv to use our test venv instead of .venv
echo "Installing dependencies into test venv..."
(
unset VIRTUAL_ENV
UV_PROJECT_ENVIRONMENT="${TEST_VENV_DIR}" uv sync || return 1
) || return 1
source "${VIRTUAL_ENV}/bin/activate"
}
function runLint() {
echo "========================== lint"
# Format check with ruff (using executable from test venv)
"${VIRTUAL_ENV}/bin/ruff" format --check . || return $?
# Lint with ruff (includes flake8-compatible checks)
"${VIRTUAL_ENV}/bin/ruff" check . || return $?
# Type check with mypy
"${VIRTUAL_ENV}/bin/mypy" src || return $?
echo "Lint was ok"
return 0
}
function runTests() {
local -r testWildCard="$*"
local opts=""
cd "${GIT_ROOT}" || return $?
if [[ -n "${testWildCard}" ]] ; then
opts+="-k ${testWildCard}"
fi
echo "========================== tests"
# shellcheck disable=SC2086
"${VIRTUAL_ENV}/bin/pytest" tests ${opts}
local -r rc=$?
echo "pytest ended with rc=${rc}"
return ${rc}
}
checkEnvironment || exit 1
runLint || exit 1
# shellcheck disable=SC2068
runTests $@
exit $?