127 lines
3.8 KiB
Python
127 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify the new punch button functionality in the edit window.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import tkinter as tk
|
|
|
|
# Add the src directory to the path so we can import our modules
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
|
|
|
import logging
|
|
|
|
from ui_manager import UIManager
|
|
|
|
|
|
def test_edit_window_punch_buttons():
|
|
"""Test the punch buttons in the edit window."""
|
|
print("Testing punch buttons in edit window...")
|
|
|
|
# Create a test Tkinter root
|
|
root = tk.Tk()
|
|
root.withdraw() # Hide the main window
|
|
|
|
# Create a logger
|
|
logger = logging.getLogger("test_logger")
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
# Create UIManager
|
|
ui_manager = UIManager(root, logger)
|
|
|
|
# Sample dose data for testing
|
|
sample_dose_data = {
|
|
"bupropion": "2025-01-15 08:00:00:300mg|2025-01-15 20:00:00:150mg",
|
|
"hydroxyzine": "2025-01-15 22:00:00:25mg",
|
|
"gabapentin": "",
|
|
"propranolol": "2025-01-15 09:30:00:10mg",
|
|
}
|
|
|
|
# Sample values for the edit window (14 fields for new CSV format)
|
|
sample_values = (
|
|
"01/15/2025", # date
|
|
5, # depression
|
|
3, # anxiety
|
|
7, # sleep
|
|
6, # appetite
|
|
1, # bupropion
|
|
sample_dose_data["bupropion"], # bupropion_doses
|
|
1, # hydroxyzine
|
|
sample_dose_data["hydroxyzine"], # hydroxyzine_doses
|
|
0, # gabapentin
|
|
sample_dose_data["gabapentin"], # gabapentin_doses
|
|
1, # propranolol
|
|
sample_dose_data["propranolol"], # propranolol_doses
|
|
"Test entry for punch button functionality", # note
|
|
)
|
|
|
|
# Define dummy callbacks
|
|
def dummy_save(*args):
|
|
print("Save callback triggered with args:", args)
|
|
|
|
def dummy_delete(*args):
|
|
print("Delete callback triggered")
|
|
|
|
callbacks = {
|
|
"save": dummy_save,
|
|
"delete": dummy_delete,
|
|
}
|
|
|
|
try:
|
|
# Create the edit window
|
|
edit_window = ui_manager.create_edit_window(sample_values, callbacks)
|
|
|
|
print("✓ Edit window created successfully")
|
|
print("✓ Edit window should now display:")
|
|
print(" - Medicine checkboxes")
|
|
print(" - Dose entry fields for each medicine")
|
|
print(" - 'Take [Medicine]' punch buttons")
|
|
print(" - Editable dose display areas")
|
|
print(" - Formatted existing doses (times in HH:MM format)")
|
|
|
|
print("\n=== Testing Dose Display Formatting ===")
|
|
print("Bupropion should show: 08:00: 300mg, 20:00: 150mg")
|
|
print("Hydroxyzine should show: 22:00: 25mg")
|
|
print("Gabapentin should show: No doses recorded")
|
|
print("Propranolol should show: 09:30: 10mg")
|
|
|
|
print("\n=== Punch Button Test Instructions ===")
|
|
print("1. Enter a dose amount in any medicine's entry field")
|
|
print("2. Click the corresponding 'Take [Medicine]' button")
|
|
print("3. The dose should be added to the dose display with current time")
|
|
print("4. The entry field should be cleared")
|
|
print("5. A success message should appear")
|
|
|
|
print("\n✓ Edit window is ready for testing")
|
|
print("Close the edit window when done testing.")
|
|
|
|
# Start the event loop for the edit window
|
|
edit_window.wait_window()
|
|
|
|
print("✓ Edit window test completed")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"✗ Error creating edit window: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
finally:
|
|
root.destroy()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("Testing Edit Window Punch Button Functionality")
|
|
print("=" * 50)
|
|
|
|
success = test_edit_window_punch_buttons()
|
|
|
|
if success:
|
|
print("\n✓ All edit window punch button tests completed successfully!")
|
|
else:
|
|
print("\n✗ Edit window punch button tests failed!")
|
|
sys.exit(1)
|