148 lines
4.4 KiB
Python
148 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify dose editing functionality in the edit window.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import shutil
|
|
import sys
|
|
|
|
# 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"))
|
|
|
|
from data_manager import DataManager
|
|
|
|
|
|
def test_dose_editing_functionality():
|
|
"""Test the dose editing functionality with the edit window."""
|
|
print("Testing dose editing functionality in edit window...")
|
|
|
|
# Create a backup of the current CSV
|
|
try:
|
|
shutil.copy("thechart_data.csv", "thechart_data_backup.csv")
|
|
print("✓ Created backup of current CSV")
|
|
except Exception as e:
|
|
print(f"✗ Failed to create backup: {e}")
|
|
return False
|
|
|
|
try:
|
|
# Create a logger for the DataManager
|
|
logger = logging.getLogger("test_logger")
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
# Initialize data manager
|
|
data_manager = DataManager("thechart_data.csv", logger)
|
|
|
|
# Load current data
|
|
df = data_manager.load_data()
|
|
print(f"✓ Loaded {len(df)} entries from CSV")
|
|
|
|
if df.empty:
|
|
print("✗ No data to test dose editing functionality")
|
|
return False
|
|
|
|
# Test 1: Check that we can retrieve full row data including doses
|
|
print("\n=== Testing Full Row Data Retrieval ===")
|
|
first_entry_date = df.iloc[0]["date"]
|
|
first_entry = df[df["date"] == first_entry_date].iloc[0]
|
|
|
|
print(f"Testing with date: {first_entry_date}")
|
|
|
|
# Check that all expected columns are present
|
|
expected_columns = [
|
|
"date",
|
|
"depression",
|
|
"anxiety",
|
|
"sleep",
|
|
"appetite",
|
|
"bupropion",
|
|
"bupropion_doses",
|
|
"hydroxyzine",
|
|
"hydroxyzine_doses",
|
|
"gabapentin",
|
|
"gabapentin_doses",
|
|
"propranolol",
|
|
"propranolol_doses",
|
|
"note",
|
|
]
|
|
|
|
missing_columns = [col for col in expected_columns if col not in df.columns]
|
|
if missing_columns:
|
|
print(f"✗ Missing columns: {missing_columns}")
|
|
return False
|
|
else:
|
|
print("✓ All expected columns present in CSV")
|
|
|
|
# Test 2: Check dose data access
|
|
print("\n=== Testing Dose Data Access ===")
|
|
dose_columns = [
|
|
"bupropion_doses",
|
|
"hydroxyzine_doses",
|
|
"gabapentin_doses",
|
|
"propranolol_doses",
|
|
]
|
|
|
|
for col in dose_columns:
|
|
dose_data = first_entry[col]
|
|
print(f"{col}: '{dose_data}'")
|
|
|
|
print("✓ Dose data accessible from CSV")
|
|
|
|
# Test 3: Test parsing dose text (simulate edit window input)
|
|
print("\n=== Testing Dose Text Parsing ===")
|
|
|
|
# Simulate some dose text that a user might enter
|
|
test_dose_text = "09:00: 150mg\n18:30: 150mg"
|
|
test_date = "07/28/2025"
|
|
|
|
# Test the parsing logic (we'll need to import this)
|
|
try:
|
|
import tkinter as tk
|
|
|
|
from ui_manager import UIManager
|
|
|
|
# Create a temporary UI manager to test the parsing
|
|
root = tk.Tk()
|
|
root.withdraw() # Hide the window
|
|
ui_manager = UIManager(root, logger)
|
|
|
|
parsed_doses = ui_manager._parse_dose_text(test_dose_text, test_date)
|
|
print(f"Original text: '{test_dose_text}'")
|
|
print(f"Parsed doses: '{parsed_doses}'")
|
|
|
|
if "|" in parsed_doses and "2025-07-28" in parsed_doses:
|
|
print("✓ Dose text parsing working correctly")
|
|
else:
|
|
print("✗ Dose text parsing failed")
|
|
root.destroy()
|
|
return False
|
|
|
|
root.destroy()
|
|
|
|
except Exception as e:
|
|
print(f"✗ Error testing dose parsing: {e}")
|
|
return False
|
|
|
|
print("\n✓ All dose editing functionality tests passed!")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"✗ Error during test: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
finally:
|
|
# Restore the backup
|
|
try:
|
|
shutil.move("thechart_data_backup.csv", "thechart_data.csv")
|
|
print("✓ Restored original CSV from backup")
|
|
except Exception as e:
|
|
print(f"✗ Failed to restore backup: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_dose_editing_functionality()
|