#!/usr/bin/env python3 """ Test script to validate the pathology management system. """ import os import sys # Add src to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src")) from init import logger from pathology_manager import Pathology, PathologyManager def test_pathology_system(): """Test the complete pathology system.""" print("๐Ÿงช Testing Pathology Management System...") # Test 1: Initialize PathologyManager print("\n1. Testing PathologyManager initialization...") pathology_manager = PathologyManager("test_pathologies.json", logger) pathologies = pathology_manager.get_all_pathologies() print(f" โœ… Successfully loaded {len(pathologies)} pathologies") for key, pathology in pathologies.items(): print(f" - {key}: {pathology.display_name} ({pathology.scale_info})") # Test 2: Add a new pathology print("\n2. Testing pathology addition...") new_pathology = Pathology( key="stress", display_name="Stress Level", scale_info="0:calm, 10:overwhelmed", color="#9B59B6", default_enabled=True, scale_min=0, scale_max=10, scale_orientation="normal", ) if pathology_manager.add_pathology(new_pathology): print(" โœ… Successfully added Stress Level pathology") updated_pathologies = pathology_manager.get_all_pathologies() print(f" Now have {len(updated_pathologies)} pathologies") else: print(" โŒ Failed to add Stress Level pathology") # Test 3: Test CSV headers with DataManager print("\n3. Testing CSV headers generation...") from data_manager import DataManager from medicine_manager import MedicineManager medicine_manager = MedicineManager("medicines.json", logger) DataManager( "test_pathologies_data.csv", logger, medicine_manager, pathology_manager ) if os.path.exists("test_pathologies_data.csv"): with open("test_pathologies_data.csv") as f: headers = f.readline().strip() print(f" CSV headers: {headers}") os.remove("test_pathologies_data.csv") # Clean up print(" โœ… CSV headers generated successfully") # Test 4: Test pathology configuration methods print("\n4. Testing pathology configuration methods...") keys = pathology_manager.get_pathology_keys() display_names = pathology_manager.get_display_names() colors = pathology_manager.get_graph_colors() enabled = pathology_manager.get_default_enabled_pathologies() print(f" Keys: {keys}") print(f" Display names: {display_names}") print(f" Colors: {colors}") print(f" Default enabled: {enabled}") print(" โœ… All configuration methods working") # Clean up test file if os.path.exists("test_pathologies.json"): os.remove("test_pathologies.json") print("\n๐Ÿงน Cleaned up test files") print("\nโœ… All pathology system tests passed!") if __name__ == "__main__": try: test_pathology_system() except Exception as e: print(f"โŒ Test failed with error: {e}") import traceback traceback.print_exc()