Compare commits
2 Commits
v1.0-gui-s
...
lauffähig
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc0db8496b | ||
|
|
b7730d908c |
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
|
||||
|
||||
# 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():
|
||||
"""Test ob alle Module importiert werden können"""
|
||||
print("Teste Imports...")
|
||||
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 file_management
|
||||
import network_utils
|
||||
@@ -24,12 +58,20 @@ def test_imports():
|
||||
return True
|
||||
except ImportError as 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
|
||||
|
||||
def test_dicom_file_detection():
|
||||
"""Test DICOM-Datei-Erkennung"""
|
||||
print("\nTeste DICOM-Datei-Erkennung...")
|
||||
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
|
||||
|
||||
# Suche nach Test-DICOM-Dateien
|
||||
@@ -64,6 +106,13 @@ def test_file_management():
|
||||
"""Test Dateiverwaltung"""
|
||||
print("\nTeste Dateiverwaltung...")
|
||||
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
|
||||
|
||||
test_dir = os.path.expanduser("~/Downloads/test_dicom")
|
||||
@@ -106,6 +155,13 @@ def test_patient_name_formatting():
|
||||
"""Test Patientenname-Formatierung"""
|
||||
print("\nTeste Patientenname-Formatierung...")
|
||||
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
|
||||
|
||||
# Test verschiedene Formate
|
||||
@@ -132,6 +188,13 @@ def test_birthdate_formatting():
|
||||
"""Test Geburtsdatum-Formatierung"""
|
||||
print("\nTeste Geburtsdatum-Formatierung...")
|
||||
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
|
||||
|
||||
test_cases = [
|
||||
@@ -152,6 +215,81 @@ def test_birthdate_formatting():
|
||||
print(f"✗ Fehler: {e}")
|
||||
return False
|
||||
|
||||
def test_upload_functionality():
|
||||
"""Test Upload-Funktionalität"""
|
||||
print("\nTeste Upload-Funktionalität...")
|
||||
try:
|
||||
import asyncio
|
||||
import network_utils
|
||||
|
||||
# Lade Konfiguration
|
||||
config_path = os.path.expanduser("~/.dicom2pacs.conf")
|
||||
server_url = None
|
||||
server_username = None
|
||||
server_pw = None
|
||||
|
||||
if os.path.exists(config_path):
|
||||
with open(config_path, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line.startswith('server_url='):
|
||||
server_url = line.split('=', 1)[1]
|
||||
elif line.startswith('server_username='):
|
||||
server_username = line.split('=', 1)[1]
|
||||
elif line.startswith('server_pw='):
|
||||
server_pw = line.split('=', 1)[1]
|
||||
|
||||
if not server_url:
|
||||
print("⚠ Keine Server-URL in Konfiguration gefunden - Upload-Test übersprungen")
|
||||
print(" Bitte konfigurieren Sie die Server-URL in ~/.dicom2pacs.conf")
|
||||
return True # Nicht kritisch, Test überspringen
|
||||
|
||||
# Test 1: Server-Verfügbarkeit prüfen
|
||||
print(" Prüfe Server-Verfügbarkeit...")
|
||||
try:
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
availability = loop.run_until_complete(network_utils.check_server_availability(server_url))
|
||||
loop.close()
|
||||
|
||||
if availability:
|
||||
print(f" ✓ Server ist erreichbar: {server_url}")
|
||||
|
||||
# Test 2: Prüfe ob Test-DICOM-Dateien vorhanden sind
|
||||
test_dir = os.path.expanduser("~/Downloads/test_dicom")
|
||||
if os.path.exists(test_dir):
|
||||
import file_management
|
||||
result = file_management.find_dicom_files(test_dir)
|
||||
if result != 'non_found':
|
||||
files, count = result
|
||||
if count > 0:
|
||||
print(f" ✓ {count} Test-DICOM-Dateien gefunden")
|
||||
print(" ⚠ Upload-Test würde echte Dateien hochladen - wird übersprungen")
|
||||
print(" (Für echten Upload-Test: Manuell mit test_dicom2pacs.sh durchführen)")
|
||||
return True
|
||||
else:
|
||||
print(" ⚠ Keine DICOM-Dateien im Test-Ordner")
|
||||
else:
|
||||
print(" ⚠ Keine DICOM-Dateien im Test-Ordner")
|
||||
else:
|
||||
print(" ⚠ Test-Ordner nicht gefunden: ~/Downloads/test_dicom")
|
||||
|
||||
return True
|
||||
else:
|
||||
print(f" ⚠ Server ist nicht erreichbar: {server_url}")
|
||||
print(" (Upload-Test kann nicht durchgeführt werden)")
|
||||
return True # Nicht kritisch, Server könnte offline sein
|
||||
except Exception as e:
|
||||
print(f" ⚠ Fehler beim Prüfen der Server-Verfügbarkeit: {e}")
|
||||
return True # Nicht kritisch
|
||||
|
||||
except ImportError as e:
|
||||
print(f"✗ Import-Fehler: {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"✗ Fehler: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""Hauptfunktion für alle Tests"""
|
||||
print("=== dicom2pacs Automatisierte Tests ===\n")
|
||||
@@ -163,6 +301,7 @@ def main():
|
||||
("Konfiguration", test_config_loading),
|
||||
("Patientenname-Formatierung", test_patient_name_formatting),
|
||||
("Geburtsdatum-Formatierung", test_birthdate_formatting),
|
||||
("Upload-Funktionalität", test_upload_functionality),
|
||||
]
|
||||
|
||||
results = []
|
||||
|
||||
Reference in New Issue
Block a user