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:
William Valentin
2025-07-31 09:50:45 -07:00
parent b8600ae57a
commit c755f0affc
22 changed files with 2801 additions and 394 deletions

View File

@@ -8,16 +8,21 @@ from matplotlib.axes import Axes
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from medicine_manager import MedicineManager
from pathology_manager import PathologyManager
class GraphManager:
"""Handle all graph-related operations for the application."""
def __init__(
self, parent_frame: ttk.LabelFrame, medicine_manager: MedicineManager
self,
parent_frame: ttk.LabelFrame,
medicine_manager: MedicineManager,
pathology_manager: PathologyManager,
) -> None:
self.parent_frame: ttk.LabelFrame = parent_frame
self.medicine_manager = medicine_manager
self.pathology_manager = pathology_manager
# Configure graph frame to expand
self.parent_frame.grid_rowconfigure(0, weight=1)
@@ -28,13 +33,13 @@ class GraphManager:
def _initialize_toggle_vars(self) -> None:
"""Initialize toggle variables for chart elements."""
# Initialize symptom toggles (always shown by default)
self.toggle_vars: dict[str, tk.BooleanVar] = {
"depression": tk.BooleanVar(value=True),
"anxiety": tk.BooleanVar(value=True),
"sleep": tk.BooleanVar(value=True),
"appetite": tk.BooleanVar(value=True),
}
self.toggle_vars: dict[str, tk.BooleanVar] = {}
# Initialize pathology toggles dynamically
for pathology_key in self.pathology_manager.get_pathology_keys():
pathology = self.pathology_manager.get_pathology(pathology_key)
default_value = pathology.default_enabled if pathology else True
self.toggle_vars[pathology_key] = tk.BooleanVar(value=default_value)
# Add medicine toggles dynamically
for medicine_key in self.medicine_manager.get_medicine_keys():
@@ -77,25 +82,20 @@ class GraphManager:
side="left", padx=5
)
# Symptoms toggles
symptoms_frame = ttk.LabelFrame(self.control_frame, text="Symptoms")
symptoms_frame.pack(side="left", padx=5, pady=2)
# Pathologies toggles - dynamic based on pathology manager
pathologies_frame = ttk.LabelFrame(self.control_frame, text="Pathologies")
pathologies_frame.pack(side="left", padx=5, pady=2)
symptom_configs = [
("depression", "Depression"),
("anxiety", "Anxiety"),
("sleep", "Sleep"),
("appetite", "Appetite"),
]
for key, label in symptom_configs:
checkbox = ttk.Checkbutton(
symptoms_frame,
text=label,
variable=self.toggle_vars[key],
command=self._handle_toggle_changed,
)
checkbox.pack(side="left", padx=3)
for pathology_key in self.pathology_manager.get_pathology_keys():
pathology = self.pathology_manager.get_pathology(pathology_key)
if pathology:
checkbox = ttk.Checkbutton(
pathologies_frame,
text=pathology.display_name,
variable=self.toggle_vars[pathology_key],
command=self._handle_toggle_changed,
)
checkbox.pack(side="left", padx=3)
# Medicines toggles - dynamic based on medicine manager
medicines_frame = ttk.LabelFrame(self.control_frame, text="Medicines")
@@ -135,35 +135,26 @@ class GraphManager:
# Track if any series are plotted
has_plotted_series = False
# Plot data series based on toggle states
if self.toggle_vars["depression"].get():
self._plot_series(
df, "depression", "Depression (0:good, 10:bad)", "o", "-"
)
has_plotted_series = True
if self.toggle_vars["anxiety"].get():
self._plot_series(df, "anxiety", "Anxiety (0:good, 10:bad)", "o", "-")
has_plotted_series = True
if self.toggle_vars["sleep"].get():
self._plot_series(df, "sleep", "Sleep (0:bad, 10:good)", "o", "dashed")
has_plotted_series = True
if self.toggle_vars["appetite"].get():
self._plot_series(
df, "appetite", "Appetite (0:bad, 10:good)", "o", "dashed"
)
has_plotted_series = True
# Plot pathology data series based on toggle states
for pathology_key in self.pathology_manager.get_pathology_keys():
if self.toggle_vars[pathology_key].get():
pathology = self.pathology_manager.get_pathology(pathology_key)
if pathology and pathology_key in df.columns:
label = f"{pathology.display_name} ({pathology.scale_info})"
linestyle = (
"dashed"
if pathology.scale_orientation == "inverted"
else "-"
)
self._plot_series(df, pathology_key, label, "o", linestyle)
has_plotted_series = True
# Plot medicine dose data
# Get medicine colors from medicine manager
medicine_colors = self.medicine_manager.get_graph_colors()
medicines = [
"bupropion",
"hydroxyzine",
"gabapentin",
"propranolol",
"quetiapine",
]
# Get medicines dynamically from medicine manager
medicines = self.medicine_manager.get_medicine_keys()
# Track medicines with and without data for legend
medicines_with_data = []