Files
thechart/test_dose_parsing_simple.py
William Valentin c755f0affc 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.
2025-07-31 09:50:45 -07:00

81 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Simple test of the dose parsing workflow."""
import sys
sys.path.append("src")
# Test the fixed parsing workflow
def test_dose_parsing():
print("Testing dose parsing workflow...\n")
# Import UIManager after path setup
import logging
import tkinter as tk
from unittest.mock import Mock
from ui_manager import UIManager
# Create minimal mocks
root = tk.Tk()
root.withdraw()
logger = logging.getLogger("test")
mock_medicine_manager = Mock()
mock_pathology_manager = Mock()
# Create UIManager
ui_manager = UIManager(root, logger, mock_medicine_manager, mock_pathology_manager)
# Test case 1: Simulate what happens in the UI
print("1. Testing _populate_dose_history...")
# Mock text widget
class MockText:
def __init__(self):
self.content = ""
def configure(self, state):
pass
def delete(self, start, end):
self.content = ""
def insert(self, pos, text):
self.content = text
def get(self, start, end):
return self.content
mock_text = MockText()
saved_doses = "2025-01-30 08:00:00:150mg|2025-01-30 14:00:00:25mg"
ui_manager._populate_dose_history(mock_text, saved_doses)
print(f"Populated display: '{mock_text.content}'")
# Test case 2: User adds a new dose
print("\n2. Testing user editing...")
user_edited = mock_text.content + "\n• 06:00 PM - 50mg"
print(f"User edited content: '{user_edited}'")
# Test case 3: Parse back for saving
print("\n3. Testing _parse_dose_history_for_saving...")
parsed_result = ui_manager._parse_dose_history_for_saving(user_edited, "2025-01-30")
print(f"Parsed for saving: '{parsed_result}'")
# Count doses
dose_count = len([d for d in parsed_result.split("|") if d.strip()])
print(f"Final dose count: {dose_count}")
if dose_count == 3:
print("\n✅ SUCCESS: All 3 doses preserved!")
return True
else:
print(f"\n❌ FAILURE: Expected 3 doses, got {dose_count}")
return False
if __name__ == "__main__":
success = test_dose_parsing()
sys.exit(0 if success else 1)