- Implemented `test_dose_parsing_simple.py` to validate the dose parsing workflow. - Created `test_dose_save.py` to verify the saving functionality of dose tracking. - Added `test_dose_save_simple.py` for programmatic testing of dose saving without UI interaction. - Developed `test_final_workflow.py` to test the complete dose tracking workflow, ensuring doses are preserved during edits. - Enhanced `conftest.py` with a mock pathology manager for testing. - Updated `test_data_manager.py` to include pathology manager in DataManager tests and ensure compatibility with new features.
107 lines
3.2 KiB
Python
107 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for the dynamic edit window functionality.
|
|
Tests that the edit window properly handles dynamic pathologies and medicines.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import tkinter as tk
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "src"))
|
|
|
|
from data_manager import DataManager
|
|
from medicine_manager import MedicineManager
|
|
from pathology_manager import PathologyManager
|
|
from ui_manager import UIManager
|
|
|
|
|
|
def test_edit_window():
|
|
"""Test the edit window with dynamic pathologies and medicines."""
|
|
print("Testing edit window with dynamic pathologies and medicines...")
|
|
|
|
# Initialize managers
|
|
medicine_manager = MedicineManager()
|
|
pathology_manager = PathologyManager()
|
|
data_manager = DataManager(
|
|
csv_file="thechart_data.csv",
|
|
medicine_manager=medicine_manager,
|
|
pathology_manager=pathology_manager,
|
|
)
|
|
|
|
# Create root window
|
|
root = tk.Tk()
|
|
root.withdraw() # Hide main window for testing
|
|
|
|
# Initialize UI manager
|
|
ui_manager = UIManager(
|
|
root=root,
|
|
data_manager=data_manager,
|
|
medicine_manager=medicine_manager,
|
|
pathology_manager=pathology_manager,
|
|
)
|
|
|
|
# Test data - create a sample row
|
|
test_data = {"Date": "2025-07-31", "Note": "Test entry for edit window"}
|
|
|
|
# Add pathology values dynamically
|
|
pathologies = pathology_manager.get_all_pathologies()
|
|
for pathology_key, _pathology in pathologies.items():
|
|
test_data[pathology_key] = 3 # Mid-range value
|
|
|
|
# Add medicine values dynamically
|
|
medicines = medicine_manager.get_all_medicines()
|
|
for medicine_key in medicines:
|
|
test_data[medicine_key] = 1 # Taken
|
|
test_data[f"{medicine_key}_doses"] = "08:00: 25mg"
|
|
|
|
print(
|
|
f"Test data created with {len(pathologies)} pathologies "
|
|
f"and {len(medicines)} medicines"
|
|
)
|
|
|
|
# Create edit window
|
|
try:
|
|
edit_window = ui_manager.create_edit_window(0, test_data)
|
|
print("✅ Edit window created successfully!")
|
|
|
|
# Check that the window has the expected pathology controls
|
|
pathology_count = len(pathologies)
|
|
medicine_count = len(medicines)
|
|
|
|
print(f"✅ Edit window should contain {pathology_count} pathology scales")
|
|
print(f"✅ Edit window should contain {medicine_count} medicine checkboxes")
|
|
print(
|
|
f"✅ Edit window should contain dose tracking for "
|
|
f"{medicine_count} medicines"
|
|
)
|
|
|
|
# Show the window briefly to verify it renders
|
|
edit_window.deiconify()
|
|
# Close after 2 seconds
|
|
root.after(2000, lambda: (edit_window.destroy(), root.quit()))
|
|
root.mainloop()
|
|
|
|
print("✅ Edit window displayed and closed without errors!")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error creating edit window: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = test_edit_window()
|
|
if success:
|
|
print("\n🎉 All edit window tests passed!")
|
|
print(
|
|
"The edit window is now fully dynamic and supports "
|
|
"user-managed pathologies!"
|
|
)
|
|
else:
|
|
print("\n💥 Edit window test failed!")
|
|
sys.exit(1)
|