-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·135 lines (115 loc) · 4.1 KB
/
run-tests.sh
File metadata and controls
executable file
·135 lines (115 loc) · 4.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
#
# Autoken Python Client Test Runner
#
# ╔═══════════════════════════════════════════════════════════════════════════╗
# ║ This script runs tests for the Autoken Python client package. ║
# ║ Tests are run inside a Docker container to ensure isolation. ║
# ╚═══════════════════════════════════════════════════════════════════════════╝
#
# Usage:
# ./run-tests.sh # Run all tests
# ./run-tests.sh test_cli # Run only CLI tests
# ./run-tests.sh test_client # Run only client tests
# ./run-tests.sh --coverage # Run tests with coverage
# ./run-tests.sh --help # Show help
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
show_help() {
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Autoken Python Client Test Runner${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "${CYAN}Usage:${NC}"
echo " ./run-tests.sh Run all tests"
echo " ./run-tests.sh test_cli Run only CLI tests"
echo " ./run-tests.sh test_client Run only client tests"
echo " ./run-tests.sh --coverage|-c Run tests with coverage"
echo " ./run-tests.sh --install Test package installation"
echo " ./run-tests.sh --help|-h Show this help"
echo ""
exit 0
}
# Parse arguments
COVERAGE_MODE=false
INSTALL_MODE=false
TEST_PATTERN=""
while [[ $# -gt 0 ]]; do
case $1 in
--coverage|-c)
COVERAGE_MODE=true
shift
;;
--install)
INSTALL_MODE=true
shift
;;
--help|-h)
show_help
;;
*)
TEST_PATTERN="$1"
shift
;;
esac
done
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Autoken Python Client Test Runner${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
cd "$SCRIPT_DIR"
# Build test command
if [ "$INSTALL_MODE" = true ]; then
echo -e "${YELLOW}Testing package installation...${NC}"
# Create a temporary virtual environment and test installation
docker run --rm -v "$SCRIPT_DIR:/app" -w /app python:3.11-slim bash -c "
set -e
pip install --quiet --upgrade pip
pip install --quiet build
echo 'Building package...'
python -m build --wheel --outdir /tmp/dist
echo 'Installing package...'
pip install /tmp/dist/*.whl
echo ''
echo 'Testing CLI availability...'
autoken --help
echo ''
echo 'Testing module import...'
python -c 'from autoken import Autoken; print(\"✓ Import successful\")'
echo ''
echo -e '\033[0;32m✓ Package installation test passed\033[0m'
"
exit 0
fi
# Run pytest
TEST_CMD="pytest"
if [ "$COVERAGE_MODE" = true ]; then
TEST_CMD="pytest --cov=autoken --cov-report=term-missing"
fi
if [ -n "$TEST_PATTERN" ]; then
TEST_CMD="$TEST_CMD tests/${TEST_PATTERN}.py"
else
TEST_CMD="$TEST_CMD tests/"
fi
echo -e "${YELLOW}Running tests...${NC}"
echo -e "${CYAN}Command: docker run python:3.11-slim $TEST_CMD${NC}"
echo ""
# Run tests in Docker container
docker run --rm -v "$SCRIPT_DIR:/app" -w /app python:3.11-slim bash -c "
set -e
pip install --quiet --upgrade pip
pip install --quiet -e '.[dev]'
$TEST_CMD -v
"
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Tests Complete${NC}"
echo -e "${GREEN}========================================${NC}"