Files
2025-11-25 09:29:54 +00:00

134 lines
4.5 KiB
Python

"""
Singleton Pattern Import Test
Verifies that all nodes can be imported without errors
"""
import sys
from pathlib import Path
# Add current directory to path
current_dir = Path(__file__).parent
sys.path.insert(0, str(current_dir))
def test_imports():
"""Test that all imports work correctly"""
print("Testing Singleton Pattern Implementation")
print("=" * 80)
errors = []
# Test 1: Import singleton module
print("\n1. Testing core.singleton import...")
try:
from core.singleton import get_orchestrator, reset_orchestrator
print(" ✓ core.singleton imported successfully")
except Exception as e:
errors.append(f"core.singleton: {e}")
print(f" ✗ Failed: {e}")
# Test 2: Import nodes module
print("\n2. Testing nodes module import...")
try:
from nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
print(f" ✓ nodes module imported successfully")
print(f" ✓ Found {len(NODE_CLASS_MAPPINGS)} node classes")
print(f" ✓ Found {len(NODE_DISPLAY_NAME_MAPPINGS)} display names")
except Exception as e:
errors.append(f"nodes module: {e}")
print(f" ✗ Failed: {e}")
return errors
# Test 3: Verify all node classes
print("\n3. Testing individual node classes...")
expected_nodes = [
"PromptLightingModifier",
"PromptSeasonalModifier",
"PromptLocationModifier",
"PromptWeatherModifier",
"PromptMoodModifier",
"PromptCameraModifier",
"PromptColorGrading",
"PromptActionModifier",
"PromptEraModifier",
"PromptDetailModifier",
"PromptComposition",
"PromptStyleTransform",
"PromptMultiStyle",
"PromptBatchVariation",
"PromptPresetCollection",
"PromptModifierInfo",
"PromptCombiner",
"PromptRandomModifier",
"PromptSmartVariation",
]
for node_name in expected_nodes:
if node_name in NODE_CLASS_MAPPINGS:
print(f" ✓ {node_name}")
else:
errors.append(f"Missing node: {node_name}")
print(f" ✗ Missing: {node_name}")
# Test 4: Test singleton orchestrator
print("\n4. Testing singleton orchestrator...")
try:
from core.singleton import get_orchestrator
orch1 = get_orchestrator()
orch2 = get_orchestrator()
if orch1 is orch2:
print(" ✓ Singleton pattern working (same instance returned)")
else:
errors.append("Singleton pattern failed (different instances)")
print(" ✗ Different instances returned!")
except Exception as e:
errors.append(f"Singleton test: {e}")
print(f" ✗ Failed: {e}")
# Test 5: Test node instantiation
print("\n5. Testing node instantiation...")
try:
from nodes.lighting_node import PromptLightingModifierNode
node = PromptLightingModifierNode()
print(" ✓ PromptLightingModifierNode instantiated")
# Test the apply_modifier method
result = node.apply_modifier("test prompt", 7, True)
print(f" ✓ apply_modifier() works: {result[0][:50]}...")
except Exception as e:
errors.append(f"Node instantiation: {e}")
print(f" ✗ Failed: {e}")
# Test 6: Test lazy loading
print("\n6. Testing lazy loading...")
try:
from core.singleton import reset_orchestrator, get_orchestrator
reset_orchestrator()
orch = get_orchestrator()
# Accessing modifiers should trigger lazy loading
modifiers = orch.modifiers
print(f" ✓ Lazy loading works: {len(modifiers)} lighting modifiers loaded")
seasonal = orch.seasonal_modifiers
print(f" ✓ Seasonal modifiers loaded: {len(seasonal)} modifiers")
except Exception as e:
errors.append(f"Lazy loading: {e}")
print(f" ✗ Failed: {e}")
# Summary
print("\n" + "=" * 80)
if errors:
print(f"FAILED: {len(errors)} error(s) found:")
for error in errors:
print(f" - {error}")
return False
else:
print("SUCCESS: All tests passed!")
print("✓ All 19 nodes should now load correctly in ComfyUI")
return True
if __name__ == "__main__":
success = test_imports()
sys.exit(0 if success else 1)