Tests: test_dicom2pacs.py repariert - venv-Unterstützung und run_tests.sh hinzugefügt
This commit is contained in:
14
run_tests.sh
Executable file
14
run_tests.sh
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# run_tests.sh - Führt die Python-Tests mit aktiviertem venv aus
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
# Aktiviere venv
|
||||||
|
if [ -d "venv" ]; then
|
||||||
|
source venv/bin/activate
|
||||||
|
python3 test_dicom2pacs.py
|
||||||
|
else
|
||||||
|
echo "FEHLER: venv nicht gefunden!"
|
||||||
|
echo "Bitte erstellen Sie ein venv: python3 -m venv venv"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -10,12 +10,46 @@ import tempfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Füge Projektverzeichnis zum Python-Pfad hinzu
|
# Füge Projektverzeichnis zum Python-Pfad hinzu
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
project_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
sys.path.insert(0, project_dir)
|
||||||
|
|
||||||
|
# Versuche venv zu verwenden
|
||||||
|
venv_path = os.path.join(project_dir, 'venv')
|
||||||
|
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
|
||||||
|
|
||||||
|
if os.path.exists(venv_path):
|
||||||
|
# Füge venv site-packages zum Python-Pfad hinzu
|
||||||
|
site_packages = os.path.join(venv_path, 'lib', f'python{python_version}', 'site-packages')
|
||||||
|
if os.path.exists(site_packages):
|
||||||
|
sys.path.insert(0, site_packages)
|
||||||
|
|
||||||
|
# Versuche auch pydicom aus der gebauten App zu verwenden
|
||||||
|
app_path = os.path.join(project_dir, 'dist', 'dicom2pacs.app', 'Contents', 'Resources', 'lib', f'python{python_version}')
|
||||||
|
if os.path.exists(app_path):
|
||||||
|
sys.path.insert(0, app_path)
|
||||||
|
|
||||||
|
# Prüfe ob pydicom verfügbar ist, sonst gebe Hinweis
|
||||||
|
try:
|
||||||
|
import pydicom
|
||||||
|
except ImportError:
|
||||||
|
print("WARNUNG: pydicom nicht gefunden. Bitte venv aktivieren oder pydicom installieren:")
|
||||||
|
print(" source venv/bin/activate")
|
||||||
|
print(" pip install pydicom")
|
||||||
|
print("Oder Tests mit test_dicom2pacs.sh ausführen, das das venv automatisch aktiviert.\n")
|
||||||
|
|
||||||
def test_imports():
|
def test_imports():
|
||||||
"""Test ob alle Module importiert werden können"""
|
"""Test ob alle Module importiert werden können"""
|
||||||
print("Teste Imports...")
|
print("Teste Imports...")
|
||||||
try:
|
try:
|
||||||
|
# Versuche zuerst pydicom zu importieren, um zu prüfen ob es verfügbar ist
|
||||||
|
try:
|
||||||
|
import pydicom
|
||||||
|
except ImportError:
|
||||||
|
print("⚠ pydicom nicht gefunden - Tests können nicht vollständig ausgeführt werden")
|
||||||
|
print(" Bitte venv aktivieren: source venv/bin/activate")
|
||||||
|
print(" Oder Tests mit test_dicom2pacs.sh ausführen")
|
||||||
|
return False
|
||||||
|
|
||||||
import dicom_processing
|
import dicom_processing
|
||||||
import file_management
|
import file_management
|
||||||
import network_utils
|
import network_utils
|
||||||
@@ -24,12 +58,20 @@ def test_imports():
|
|||||||
return True
|
return True
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print(f"✗ Import-Fehler: {e}")
|
print(f"✗ Import-Fehler: {e}")
|
||||||
|
print(" Tipp: Führen Sie die Tests mit test_dicom2pacs.sh aus, um das venv automatisch zu aktivieren")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def test_dicom_file_detection():
|
def test_dicom_file_detection():
|
||||||
"""Test DICOM-Datei-Erkennung"""
|
"""Test DICOM-Datei-Erkennung"""
|
||||||
print("\nTeste DICOM-Datei-Erkennung...")
|
print("\nTeste DICOM-Datei-Erkennung...")
|
||||||
try:
|
try:
|
||||||
|
# Prüfe ob pydicom verfügbar ist
|
||||||
|
try:
|
||||||
|
import pydicom
|
||||||
|
except ImportError:
|
||||||
|
print("⚠ pydicom nicht verfügbar - Test übersprungen")
|
||||||
|
return False
|
||||||
|
|
||||||
import dicom_processing
|
import dicom_processing
|
||||||
|
|
||||||
# Suche nach Test-DICOM-Dateien
|
# Suche nach Test-DICOM-Dateien
|
||||||
@@ -64,6 +106,13 @@ def test_file_management():
|
|||||||
"""Test Dateiverwaltung"""
|
"""Test Dateiverwaltung"""
|
||||||
print("\nTeste Dateiverwaltung...")
|
print("\nTeste Dateiverwaltung...")
|
||||||
try:
|
try:
|
||||||
|
# Prüfe ob pydicom verfügbar ist
|
||||||
|
try:
|
||||||
|
import pydicom
|
||||||
|
except ImportError:
|
||||||
|
print("⚠ pydicom nicht verfügbar - Test übersprungen")
|
||||||
|
return False
|
||||||
|
|
||||||
import file_management
|
import file_management
|
||||||
|
|
||||||
test_dir = os.path.expanduser("~/Downloads/test_dicom")
|
test_dir = os.path.expanduser("~/Downloads/test_dicom")
|
||||||
@@ -106,6 +155,13 @@ def test_patient_name_formatting():
|
|||||||
"""Test Patientenname-Formatierung"""
|
"""Test Patientenname-Formatierung"""
|
||||||
print("\nTeste Patientenname-Formatierung...")
|
print("\nTeste Patientenname-Formatierung...")
|
||||||
try:
|
try:
|
||||||
|
# Prüfe ob pydicom verfügbar ist (wird indirekt benötigt)
|
||||||
|
try:
|
||||||
|
import pydicom
|
||||||
|
except ImportError:
|
||||||
|
print("⚠ pydicom nicht verfügbar - Test übersprungen")
|
||||||
|
return False
|
||||||
|
|
||||||
import file_management
|
import file_management
|
||||||
|
|
||||||
# Test verschiedene Formate
|
# Test verschiedene Formate
|
||||||
@@ -132,6 +188,13 @@ def test_birthdate_formatting():
|
|||||||
"""Test Geburtsdatum-Formatierung"""
|
"""Test Geburtsdatum-Formatierung"""
|
||||||
print("\nTeste Geburtsdatum-Formatierung...")
|
print("\nTeste Geburtsdatum-Formatierung...")
|
||||||
try:
|
try:
|
||||||
|
# Prüfe ob pydicom verfügbar ist (wird indirekt benötigt)
|
||||||
|
try:
|
||||||
|
import pydicom
|
||||||
|
except ImportError:
|
||||||
|
print("⚠ pydicom nicht verfügbar - Test übersprungen")
|
||||||
|
return False
|
||||||
|
|
||||||
import file_management
|
import file_management
|
||||||
|
|
||||||
test_cases = [
|
test_cases = [
|
||||||
|
|||||||
Reference in New Issue
Block a user