- Deleted .env.example file as it is no longer needed. - Added .gitignore to manage ignored files and directories. - Introduced CLAUDE.md for AI provider integration documentation. - Created dev.sh for development setup and scripts. - Updated Dockerfile and Dockerfile.production for improved build processes. - Added multiple test files and directories for comprehensive testing. - Introduced new utility and service files for enhanced functionality. - Organized codebase with new directories and files for better maintainability.
157 lines
4.6 KiB
Bash
Executable File
157 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Test runner script for Discord Quote Bot
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${2}${1}${NC}"
|
|
}
|
|
|
|
# Function to run tests with specific markers
|
|
run_test_suite() {
|
|
local suite_name=$1
|
|
local pytest_args=$2
|
|
|
|
print_status "Running $suite_name tests..." "$BLUE"
|
|
|
|
if pytest $pytest_args; then
|
|
print_status "✓ $suite_name tests passed" "$GREEN"
|
|
return 0
|
|
else
|
|
print_status "✗ $suite_name tests failed" "$RED"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Parse command line arguments
|
|
TEST_TYPE=${1:-all}
|
|
VERBOSE=${2:-}
|
|
|
|
# Set verbosity
|
|
PYTEST_VERBOSE=""
|
|
if [ "$VERBOSE" = "-v" ] || [ "$VERBOSE" = "--verbose" ]; then
|
|
PYTEST_VERBOSE="-v"
|
|
fi
|
|
|
|
# Main test execution
|
|
print_status "Discord Quote Bot Test Suite" "$YELLOW"
|
|
print_status "=============================" "$YELLOW"
|
|
|
|
case $TEST_TYPE in
|
|
unit)
|
|
print_status "Running unit tests only..." "$BLUE"
|
|
run_test_suite "Unit" "-m unit $PYTEST_VERBOSE"
|
|
;;
|
|
|
|
integration)
|
|
print_status "Running integration tests only..." "$BLUE"
|
|
run_test_suite "Integration" "-m integration $PYTEST_VERBOSE"
|
|
;;
|
|
|
|
performance)
|
|
print_status "Running performance tests only..." "$BLUE"
|
|
run_test_suite "Performance" "-m performance $PYTEST_VERBOSE"
|
|
;;
|
|
|
|
load)
|
|
print_status "Running load tests only..." "$BLUE"
|
|
run_test_suite "Load" "-m load $PYTEST_VERBOSE"
|
|
;;
|
|
|
|
fast)
|
|
print_status "Running fast tests (unit only)..." "$BLUE"
|
|
run_test_suite "Fast" "-m 'unit and not slow' $PYTEST_VERBOSE"
|
|
;;
|
|
|
|
coverage)
|
|
print_status "Running tests with coverage report..." "$BLUE"
|
|
pytest --cov=. --cov-report=html --cov-report=term $PYTEST_VERBOSE
|
|
print_status "Coverage report generated in htmlcov/index.html" "$GREEN"
|
|
;;
|
|
|
|
parallel)
|
|
print_status "Running tests in parallel..." "$BLUE"
|
|
pytest -n auto $PYTEST_VERBOSE
|
|
;;
|
|
|
|
watch)
|
|
print_status "Running tests in watch mode..." "$BLUE"
|
|
# Requires pytest-watch to be installed
|
|
if command -v ptw &> /dev/null; then
|
|
ptw -- $PYTEST_VERBOSE
|
|
else
|
|
print_status "pytest-watch not installed. Install with: pip install pytest-watch" "$YELLOW"
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
all)
|
|
print_status "Running all test suites..." "$BLUE"
|
|
|
|
# Track overall success
|
|
ALL_PASSED=true
|
|
|
|
# Run each test suite
|
|
if ! run_test_suite "Unit" "-m unit $PYTEST_VERBOSE"; then
|
|
ALL_PASSED=false
|
|
fi
|
|
|
|
if ! run_test_suite "Integration" "-m integration $PYTEST_VERBOSE"; then
|
|
ALL_PASSED=false
|
|
fi
|
|
|
|
if ! run_test_suite "Edge Cases" "tests/unit/test_edge_cases.py $PYTEST_VERBOSE"; then
|
|
ALL_PASSED=false
|
|
fi
|
|
|
|
# Generate coverage report
|
|
print_status "Generating coverage report..." "$BLUE"
|
|
pytest --cov=. --cov-report=html --cov-report=term-missing --quiet
|
|
|
|
# Summary
|
|
echo ""
|
|
print_status "=============================" "$YELLOW"
|
|
if [ "$ALL_PASSED" = true ]; then
|
|
print_status "✓ All test suites passed!" "$GREEN"
|
|
|
|
# Show coverage summary
|
|
coverage report --skip-covered --skip-empty | tail -n 5
|
|
else
|
|
print_status "✗ Some test suites failed" "$RED"
|
|
exit 1
|
|
fi
|
|
;;
|
|
|
|
*)
|
|
print_status "Usage: $0 [test_type] [options]" "$YELLOW"
|
|
echo ""
|
|
echo "Test types:"
|
|
echo " all - Run all test suites (default)"
|
|
echo " unit - Run unit tests only"
|
|
echo " integration - Run integration tests only"
|
|
echo " performance - Run performance tests only"
|
|
echo " load - Run load tests only"
|
|
echo " fast - Run fast tests (no slow tests)"
|
|
echo " coverage - Run with coverage report"
|
|
echo " parallel - Run tests in parallel"
|
|
echo " watch - Run tests in watch mode"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -v, --verbose - Verbose output"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 # Run all tests"
|
|
echo " $0 unit # Run unit tests only"
|
|
echo " $0 unit -v # Run unit tests with verbose output"
|
|
echo " $0 coverage # Run with coverage report"
|
|
exit 1
|
|
;;
|
|
esac |