Add comprehensive tests for dose tracking functionality
- 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.
This commit is contained in:
@@ -1,24 +1,131 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test script to demonstrate the improved edit window."""
|
||||
"""
|
||||
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
|
||||
from pathlib import Path
|
||||
|
||||
# Add src directory to path
|
||||
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "src"))
|
||||
|
||||
from src.logger import logger
|
||||
from src.ui_manager import UIManager
|
||||
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 improved edit window."""
|
||||
root = tk.Tk()
|
||||
root.title("Edit Window Test")
|
||||
root.geometry("400x300")
|
||||
"""Test the edit window with dynamic pathologies and medicines."""
|
||||
print("Testing edit window with dynamic pathologies and medicines...")
|
||||
|
||||
ui_manager = UIManager(root, logger)
|
||||
# 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 = (
|
||||
|
||||
Reference in New Issue
Block a user