#!/usr/bin/env python3 """ Test script to verify ComfyUI DCI node registration """ import sys import os import re def test_node_registration(): """Test that all nodes are properly registered""" try: # Read the __init__.py file directly init_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "__init__.py") with open(init_file, 'r', encoding='utf-8') as f: content = f.read() print("โœ… Successfully read __init__.py file") # Extract NODE_CLASS_MAPPINGS class_mappings_match = re.search(r'NODE_CLASS_MAPPINGS\s*=\s*{([^}]+)}', content, re.DOTALL) if not class_mappings_match: print("โŒ Error: NODE_CLASS_MAPPINGS not found") return False # Extract NODE_DISPLAY_NAME_MAPPINGS display_mappings_match = re.search(r'NODE_DISPLAY_NAME_MAPPINGS\s*=\s*{([^}]+)}', content, re.DOTALL) if not display_mappings_match: print("โŒ Error: NODE_DISPLAY_NAME_MAPPINGS not found") return False # Parse node names from mappings class_mappings_content = class_mappings_match.group(1) node_names = re.findall(r'"([^"]+)":', class_mappings_content) print(f"๐Ÿ“Š Found {len(node_names)} node classes") # Check that all nodes have unique names with DCI prefix for node_name in node_names: if not node_name.startswith("DCI_"): print(f"โš ๏ธ Warning: Node '{node_name}' doesn't follow DCI_ naming convention") else: print(f"โœ… Node '{node_name}' follows naming convention") # Check for custom data types if "CUSTOM_DATA_TYPES" in content: print("โœ… Found CUSTOM_DATA_TYPES definition") # Check for expected data types expected_types = ["DCI_IMAGE_DATA", "BINARY_DATA"] for data_type in expected_types: if data_type in content: print(f"โœ… Custom data type '{data_type}' is defined") else: print(f"โŒ Missing custom data type '{data_type}'") else: print("โš ๏ธ CUSTOM_DATA_TYPES not found") # Check for proper imports if "from .py.nodes import" in content: print("โœ… Found proper relative imports from py.nodes") else: print("โš ๏ธ Relative imports from py.nodes not found") # Check for proper exports if "__all__" in content: print("โœ… Found __all__ export definition") else: print("โš ๏ธ __all__ export definition not found") print("\n๐ŸŽ‰ Node registration test completed!") return True except FileNotFoundError: print("โŒ Error: __init__.py file not found") return False except Exception as e: print(f"โŒ Unexpected error: {str(e)}") return False def test_nodes_file(): """Test that the nodes.py file has proper structure""" try: nodes_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "py", "nodes.py") with open(nodes_file, 'r', encoding='utf-8') as f: content = f.read() print("\n๐Ÿ“‹ Testing py/nodes.py structure...") # Check for proper exception handling bare_except_count = len(re.findall(r'except\s*:', content)) if bare_except_count > 0: print(f"โš ๏ธ Found {bare_except_count} bare except statements (should use specific exceptions)") else: print("โœ… No bare except statements found") # Check for proper folder_paths usage folder_paths_usage = re.findall(r'import folder_paths', content) if folder_paths_usage: print(f"โœ… Found {len(folder_paths_usage)} proper folder_paths imports") # Check for proper category usage categories = re.findall(r'CATEGORY\s*=\s*"([^"]+)"', content) dci_categories = [cat for cat in categories if cat.startswith("DCI/")] print(f"โœ… Found {len(dci_categories)} DCI category definitions") return True except FileNotFoundError: print("โŒ Error: py/nodes.py file not found") return False except Exception as e: print(f"โŒ Error testing nodes.py: {str(e)}") return False def test_install_scripts(): """Test that install scripts use proper pip invocation""" try: print("\n๐Ÿ”ง Testing install scripts...") # Test install.sh install_sh = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "install.sh") if os.path.exists(install_sh): with open(install_sh, 'r', encoding='utf-8') as f: content = f.read() if "python -m pip" in content: print("โœ… install.sh uses proper pip invocation") else: print("โš ๏ธ install.sh doesn't use 'python -m pip'") # Test install.bat install_bat = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "install.bat") if os.path.exists(install_bat): with open(install_bat, 'r', encoding='utf-8') as f: content = f.read() if "python -m pip" in content: print("โœ… install.bat uses proper pip invocation") else: print("โš ๏ธ install.bat doesn't use 'python -m pip'") return True except Exception as e: print(f"โŒ Error testing install scripts: {str(e)}") return False if __name__ == "__main__": print("๐Ÿงช Testing ComfyUI DCI Node Registration") print("=" * 50) success = True success &= test_node_registration() success &= test_nodes_file() success &= test_install_scripts() if success: print("\n๐ŸŽ‰ All tests passed!") sys.exit(0) else: print("\nโŒ Some tests failed!") sys.exit(1)