- 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.
176 lines
5.3 KiB
Python
176 lines
5.3 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\n14: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("All edit window tests passed!")
|
|
print(
|
|
"The edit window is now fully dynamic and supports "
|
|
"user-managed pathologies!"
|
|
)
|
|
else:
|
|
print("💥 Edit window test failed!")
|
|
sys.exit(1)
|
|
|
|
root = tk.Tk()
|
|
root.withdraw() # Hide main window for testing
|
|
|
|
# Initialize managers for this block
|
|
medicine_manager = MedicineManager()
|
|
pathology_manager = PathologyManager()
|
|
data_manager = DataManager(
|
|
csv_file="thechart_data.csv",
|
|
medicine_manager=medicine_manager,
|
|
pathology_manager=pathology_manager,
|
|
)
|
|
|
|
# You may need to define or import 'logger' as well, or remove it if not needed.
|
|
# For now, let's assume logger is not required and remove it from the UIManager
|
|
# call.
|
|
ui_manager = UIManager(
|
|
root=root,
|
|
data_manager=data_manager,
|
|
medicine_manager=medicine_manager,
|
|
pathology_manager=pathology_manager,
|
|
)
|
|
|
|
# Sample data for testing (16 fields format)
|
|
test_values = (
|
|
"12/25/2024", # date
|
|
7, # depression
|
|
5, # anxiety
|
|
6, # sleep
|
|
4, # appetite
|
|
1, # bupropion
|
|
"09:00:00:150|18:00:00:150", # bupropion_doses
|
|
1, # hydroxyzine
|
|
"21:30:00:25", # hydroxyzine_doses
|
|
0, # gabapentin
|
|
"", # gabapentin_doses
|
|
1, # propranolol
|
|
"07:00:00:10|14:00:00:10", # propranolol_doses
|
|
0, # quetiapine
|
|
"", # quetiapine_doses
|
|
# Had a good day overall, feeling better with new medication routine
|
|
"Had a good day overall, feeling better with the new medication routine.",
|
|
)
|
|
|
|
# Mock callbacks
|
|
def save_callback(win, *args):
|
|
print("Save called with args:", args)
|
|
win.destroy()
|
|
|
|
def delete_callback(win):
|
|
print("Delete called")
|
|
win.destroy()
|
|
|
|
callbacks = {"save": save_callback, "delete": delete_callback}
|
|
|
|
# Create the improved edit window
|
|
edit_win = ui_manager.create_edit_window(test_values, callbacks)
|
|
|
|
# Center the edit window
|
|
edit_win.update_idletasks()
|
|
x = (edit_win.winfo_screenwidth() // 2) - (edit_win.winfo_width() // 2)
|
|
y = (edit_win.winfo_screenheight() // 2) - (edit_win.winfo_height() // 2)
|
|
edit_win.geometry(f"+{x}+{y}")
|
|
|
|
root.mainloop()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_edit_window()
|