#!/bin/bash # Script de test pour pdf2csv set -e # Arrêter en cas d'erreur SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Couleurs pour l'output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} Test de pdf2csv${NC}" echo -e "${BLUE}========================================${NC}" echo "" # Test 1: Vérifier que Python est installé echo -e "${YELLOW}Test 1: Vérification de Python...${NC}" if command -v python3 &> /dev/null; then PYTHON_VERSION=$(python3 --version) echo -e "${GREEN}[OK] Python installé: $PYTHON_VERSION${NC}" else echo -e "${RED}[ERREUR] Python 3 n'est pas installé${NC}" exit 1 fi echo "" # Test 2: Vérifier que Java est installé echo -e "${YELLOW}Test 2: Vérification de Java...${NC}" if command -v java &> /dev/null; then JAVA_VERSION=$(java -version 2>&1 | head -n 1) echo -e "${GREEN}[OK] Java installé: $JAVA_VERSION${NC}" else echo -e "${RED}[ERREUR] Java n'est pas installé (requis pour tabula)${NC}" echo -e "${YELLOW} Installation: sudo apt-get install openjdk-17-jre-headless${NC}" exit 1 fi echo "" # Test 3: Vérifier les dépendances Python echo -e "${YELLOW}Test 3: Vérification des dépendances Python...${NC}" if [ -f "requirements.txt" ]; then echo -e "${GREEN}[OK] requirements.txt trouvé${NC}" # Vérifier si les modules sont installés if python3 -c "import tabula" 2>/dev/null; then echo -e "${GREEN}[OK] tabula-py installé${NC}" else echo -e "${YELLOW}[ATTENTION] tabula-py non installé${NC}" echo -e "${YELLOW} Installation: pip install -r requirements.txt${NC}" fi if python3 -c "import pandas" 2>/dev/null; then echo -e "${GREEN}[OK] pandas installé${NC}" else echo -e "${YELLOW}[ATTENTION] pandas non installé${NC}" echo -e "${YELLOW} Installation: pip install -r requirements.txt${NC}" fi else echo -e "${RED}[ERREUR] requirements.txt non trouvé${NC}" exit 1 fi echo "" # Test 4: Vérifier que le script existe echo -e "${YELLOW}Test 4: Vérification du script convert.py...${NC}" if [ -f "convert.py" ]; then echo -e "${GREEN}[OK] convert.py trouvé${NC}" # Vérifier que le script est exécutable if [ -x "convert.py" ]; then echo -e "${GREEN}[OK] convert.py est exécutable${NC}" else echo -e "${YELLOW}[ATTENTION] convert.py n'est pas exécutable${NC}" echo -e "${YELLOW} Correction: chmod +x convert.py${NC}" fi else echo -e "${RED}[ERREUR] convert.py non trouvé${NC}" exit 1 fi echo "" # Test 5: Tester l'aide du script echo -e "${YELLOW}Test 5: Test de l'aide du script...${NC}" if python3 convert.py --help &> /dev/null; then echo -e "${GREEN}[OK] L'aide du script fonctionne${NC}" else echo -e "${RED}[ERREUR] L'aide du script ne fonctionne pas${NC}" exit 1 fi echo "" # Test 6: Vérifier Docker echo -e "${YELLOW}Test 6: Vérification de Docker...${NC}" if command -v docker &> /dev/null; then DOCKER_VERSION=$(docker --version) echo -e "${GREEN}[OK] Docker installé: $DOCKER_VERSION${NC}" # Vérifier que Docker daemon fonctionne if docker info &> /dev/null; then echo -e "${GREEN}[OK] Docker daemon fonctionne${NC}" else echo -e "${YELLOW}[ATTENTION] Docker daemon ne répond pas${NC}" echo -e "${YELLOW} Vérifier: sudo systemctl status docker${NC}" fi else echo -e "${YELLOW}[ATTENTION] Docker n'est pas installé (optionnel)${NC}" fi echo "" # Test 7: Vérifier le Dockerfile echo -e "${YELLOW}Test 7: Vérification du Dockerfile...${NC}" if [ -f "Dockerfile" ]; then echo -e "${GREEN}[OK] Dockerfile trouvé${NC}" else echo -e "${RED}[ERREUR] Dockerfile non trouvé${NC}" fi echo "" # Test 8: Vérifier les fichiers de configuration echo -e "${YELLOW}Test 8: Vérification des fichiers de configuration...${NC}" if [ -f "config.example.env" ]; then echo -e "${GREEN}[OK] config.example.env trouvé${NC}" else echo -e "${YELLOW}[ATTENTION] config.example.env non trouvé${NC}" fi if [ -f ".env" ]; then echo -e "${GREEN}[OK] .env trouvé${NC}" else echo -e "${YELLOW}[ATTENTION] .env non trouvé (optionnel)${NC}" echo -e "${YELLOW} Création: cp config.example.env .env${NC}" fi echo "" # Test 9: Vérifier la documentation echo -e "${YELLOW}Test 9: Vérification de la documentation...${NC}" if [ -f "README.md" ]; then echo -e "${GREEN}[OK] README.md trouvé${NC}" else echo -e "${RED}[ERREUR] README.md non trouvé${NC}" fi if [ -f "CHANGELOG.md" ]; then echo -e "${GREEN}[OK] CHANGELOG.md trouvé${NC}" else echo -e "${YELLOW}[ATTENTION] CHANGELOG.md non trouvé${NC}" fi echo "" # Test 10: Structure du projet echo -e "${YELLOW}Test 10: Vérification de la structure du projet...${NC}" REQUIRED_FILES=("convert.py" "Dockerfile" "requirements.txt" "README.md") OPTIONAL_FILES=(".gitignore" ".dockerignore" "Makefile" "config.example.env") for file in "${REQUIRED_FILES[@]}"; do if [ -f "$file" ]; then echo -e "${GREEN}[OK] $file${NC}" else echo -e "${RED}[ERREUR] $file (requis)${NC}" fi done for file in "${OPTIONAL_FILES[@]}"; do if [ -f "$file" ]; then echo -e "${GREEN}[OK] $file${NC}" else echo -e "${YELLOW}[ATTENTION] $file (optionnel)${NC}" fi done echo "" # Résumé echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} Résumé des tests${NC}" echo -e "${BLUE}========================================${NC}" echo "" echo -e "${GREEN}Tous les tests principaux sont passés !${NC}" echo "" echo -e "${BLUE}Prochaines étapes :${NC}" echo -e " 1. ${YELLOW}Développement local :${NC}" echo -e " pip install -r requirements.txt" echo -e " python convert.py --help" echo "" echo -e " 2. ${YELLOW}Utilisation avec Docker :${NC}" echo -e " docker build -t pdf2csv:latest ." echo -e " docker run --rm -v \$(pwd)/data:/data pdf2csv:latest" echo "" echo -e " 3. ${YELLOW}Avec Makefile :${NC}" echo -e " make build" echo -e " make run" echo "" echo -e " 4. ${YELLOW}Documentation :${NC}" echo -e " Consultez README.md pour plus d'informations" echo ""