#!/usr/bin/env python3 """ Test script to validate the modular medicine 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 medicine_manager import Medicine, MedicineManager def test_medicine_system(): """Test the complete medicine system.""" print("๐Ÿงช Testing Medicine System...") # Test 1: Initialize medicine manager print("\n1. Testing MedicineManager initialization...") medicine_manager = MedicineManager(logger=logger) medicines = medicine_manager.get_all_medicines() print(f" โœ… Loaded {len(medicines)} medicines") # Test 2: List current medicines print("\n2. Current medicines:") for key, medicine in medicines.items(): status = "๐ŸŸข" if medicine.default_enabled else "โšซ" print(f" {status} {key}: {medicine.display_name} ({medicine.dosage_info})") print(f" Quick doses: {medicine.quick_doses}") print(f" Color: {medicine.color}") # Test 3: Add a new medicine print("\n3. Testing adding new medicine...") new_medicine = Medicine( key="sertraline", display_name="Sertraline", dosage_info="50mg", quick_doses=["25", "50", "100"], color="#9B59B6", default_enabled=False, ) if medicine_manager.add_medicine(new_medicine): print(" โœ… Successfully added Sertraline") updated_medicines = medicine_manager.get_all_medicines() print(f" Now have {len(updated_medicines)} medicines") else: print(" โŒ Failed to add Sertraline") # Test 4: Test CSV headers print("\n4. Testing CSV headers generation...") from data_manager import DataManager DataManager("test_medicines.csv", logger, medicine_manager) if os.path.exists("test_medicines.csv"): with open("test_medicines.csv") as f: headers = f.readline().strip() print(f" CSV headers: {headers}") os.remove("test_medicines.csv") # Clean up print(" โœ… CSV headers generated successfully") # Test 5: Test graph colors print("\n5. Testing graph colors...") colors = medicine_manager.get_graph_colors() for key, color in colors.items(): print(f" {key}: {color}") print(" โœ… Graph colors retrieved successfully") # Clean up - remove test medicine print("\n6. Cleaning up...") if medicine_manager.remove_medicine("sertraline"): print(" โœ… Test medicine removed successfully") print("\n๐ŸŽ‰ All tests passed! Medicine system is working correctly.") return True if __name__ == "__main__": try: test_medicine_system() except Exception as e: print(f"โŒ Test failed with error: {e}") import traceback traceback.print_exc()