SIENTIAPDE-1241: Add unit tests for Activities class and enhance validation script with fix and test options

This commit introduces a new test suite for the Activities class, achieving 100% coverage. Additionally, the validation script (validate.sh) is enhanced with new options:

- --fix: Automatically fixes code formatting and linting issues using Ruff.
- --only-tests: Runs only the unit tests, skipping other validation steps.

The validation script now also supports skipping tests and provides more informative output.
This commit is contained in:
Bruno Domingues
2025-10-22 23:38:01 -03:00
parent f07bc8ff30
commit fc2fe33b59
2 changed files with 384 additions and 29 deletions

View File

@@ -6,22 +6,38 @@
# ./validate.sh # Run all checks including tests (default)
# ./validate.sh --no-tests # Skip unit tests
# ./validate.sh --skip-tests # Skip unit tests (alias)
# ./validate.sh --only-tests # Run only unit tests
# ./validate.sh --fix # Auto-fix formatting and linting, then run validations (no tests)
set -e # Exit on any error
# Parse command line arguments
RUN_TESTS=true
ONLY_TESTS=false
FIX_MODE=false
for arg in "$@"; do
case $arg in
--no-tests|--skip-tests)
RUN_TESTS=false
shift
;;
--only-tests)
ONLY_TESTS=true
shift
;;
--fix)
FIX_MODE=true
RUN_TESTS=false
shift
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --no-tests, --skip-tests Skip unit tests (default: run tests)"
echo " --only-tests Run only unit tests"
echo " --fix Auto-fix formatting and linting, then run validations (no tests)"
echo " --help, -h Show this help message"
echo ""
exit 0
@@ -46,7 +62,36 @@ echo -e "${BLUE}║ Model Manager - Code Validation Suite ║${N
echo -e "${BLUE}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
if [ "$RUN_TESTS" = false ]; then
# Handle --fix mode
if [ "$FIX_MODE" = true ]; then
echo -e "${BLUE}🔧 Running auto-fix mode...${NC}"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}▶ Auto-fixing code formatting (Ruff)${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
ruff format model_manager/ tests/
echo -e "${GREEN}✅ Code formatting applied${NC}"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}▶ Auto-fixing linting issues (Ruff)${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
ruff check --fix model_manager/ tests/
echo -e "${GREEN}✅ Linting fixes applied${NC}"
echo ""
echo -e "${YELLOW} Now running validations (without tests)...${NC}"
echo ""
fi
# Handle --only-tests mode
if [ "$ONLY_TESTS" = true ]; then
echo -e "${BLUE}🧪 Running only unit tests...${NC}"
echo ""
fi
if [ "$RUN_TESTS" = false ] && [ "$ONLY_TESTS" = false ]; then
echo -e "${YELLOW} Unit tests will be skipped${NC}"
echo ""
fi
@@ -81,37 +126,45 @@ run_step() {
# Track failures
FAILED_STEPS=()
# Step 1: Code Formatting Check (Ruff)
if ! run_step "1. Code Formatting (Ruff)" "ruff format --check model_manager/ tests/"; then
FAILED_STEPS+=("Code Formatting")
fi
# Step 2: Linting (Ruff)
if ! run_step "2. Code Linting (Ruff)" "ruff check model_manager/ tests/"; then
FAILED_STEPS+=("Linting")
fi
# Step 3: Type Checking (mypy)
if ! run_step "3. Type Checking (mypy)" "mypy model_manager/"; then
FAILED_STEPS+=("Type Checking")
fi
# Step 4: Security Analysis (Bandit)
if ! run_step "4. Security Analysis (Bandit)" "bandit -r model_manager/ -ll -q"; then
FAILED_STEPS+=("Security Analysis")
fi
# Step 5: Unit Tests (pytest)
if [ "$RUN_TESTS" = true ]; then
if ! run_step "5. Unit Tests (pytest)" "pytest tests/ --cov=model_manager --cov-report=term-missing --cov-report=xml --cov-report=html --cov-fail-under=80 -q"; then
# Handle --only-tests mode
if [ "$ONLY_TESTS" = true ]; then
# Step 5: Unit Tests (pytest)
if ! run_step "Unit Tests (pytest)" "pytest tests/ --cov=model_manager --cov-report=term-missing --cov-report=xml --cov-report=html --cov-fail-under=80 -q"; then
FAILED_STEPS+=("Unit Tests")
fi
else
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}▶ 5. Unit Tests (pytest)${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}⏭️ Unit Tests - SKIPPED${NC}"
echo ""
# Step 1: Code Formatting Check (Ruff)
if ! run_step "1. Code Formatting (Ruff)" "ruff format --check model_manager/ tests/"; then
FAILED_STEPS+=("Code Formatting")
fi
# Step 2: Linting (Ruff)
if ! run_step "2. Code Linting (Ruff)" "ruff check model_manager/ tests/"; then
FAILED_STEPS+=("Linting")
fi
# Step 3: Type Checking (mypy)
if ! run_step "3. Type Checking (mypy)" "mypy model_manager/"; then
FAILED_STEPS+=("Type Checking")
fi
# Step 4: Security Analysis (Bandit)
if ! run_step "4. Security Analysis (Bandit)" "bandit -r model_manager/ -ll -q"; then
FAILED_STEPS+=("Security Analysis")
fi
# Step 5: Unit Tests (pytest)
if [ "$RUN_TESTS" = true ]; then
if ! run_step "5. Unit Tests (pytest)" "pytest tests/ --cov=model_manager --cov-report=term-missing --cov-report=xml --cov-report=html --cov-fail-under=80 -q"; then
FAILED_STEPS+=("Unit Tests")
fi
else
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}▶ 5. Unit Tests (pytest)${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}⏭️ Unit Tests - SKIPPED${NC}"
echo ""
fi
fi
# Summary