- Added a new migration script to introduce dose tracking columns in the CSV. - Updated DataManager to handle new dose tracking columns and methods for adding doses. - Enhanced MedTrackerApp to support dose entry and display for each medicine. - Modified UIManager to create a scrollable input frame with dose tracking elements. - Implemented tests for delete functionality, dose tracking, edit functionality, and scrollable input. - Updated existing tests to ensure compatibility with the new CSV format and dose tracking features.
96 lines
2.9 KiB
Python
96 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify delete functionality after dose tracking implementation.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
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_delete_functionality():
|
|
"""Test the delete functionality with the new CSV format."""
|
|
print("Testing delete functionality...")
|
|
|
|
# Create a backup of the current CSV
|
|
import shutil
|
|
|
|
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 delete functionality")
|
|
return False
|
|
|
|
# Show first few entries
|
|
print("\nFirst few entries:")
|
|
for _idx, row in df.head(3).iterrows():
|
|
print(f" {row['date']}: {row['note']}")
|
|
|
|
# Test deleting the last entry
|
|
last_entry_date = df.iloc[-1]["date"]
|
|
print(f"\nAttempting to delete entry with date: {last_entry_date}")
|
|
|
|
# Perform the delete
|
|
success = data_manager.delete_entry(last_entry_date)
|
|
|
|
if success:
|
|
print("✓ Delete operation reported success")
|
|
|
|
# Reload data to verify deletion
|
|
df_after = data_manager.load_data()
|
|
print(f"✓ Data reloaded: {len(df_after)} entries (was {len(df)})")
|
|
|
|
# Check if the entry was actually deleted
|
|
deleted_entry_exists = last_entry_date in df_after["date"].values
|
|
if not deleted_entry_exists:
|
|
print("✓ Entry successfully deleted from CSV")
|
|
print("✓ Delete functionality is working correctly")
|
|
return True
|
|
else:
|
|
print("✗ Entry still exists in CSV after delete operation")
|
|
return False
|
|
else:
|
|
print("✗ Delete operation failed")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Error during delete 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_delete_functionality()
|