#!/usr/bin/env python3 """Verification tests for plugin compatibility fixes. This module tests that the tool compatibility system and related utilities work correctly after recent fixes. """ import sys import os import traceback from typing import List # Add project root to path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def test_tool_compatibility_import(): """Test that ToolCompatibility can be imported and used.""" try: print("๐Ÿงช Testing ToolCompatibility import...") # Test the import that was failing from nodupe.core.tool_system.compatibility import ToolCompatibility, ToolCompatibilityError print("โœ… ToolCompatibility import successful") # Test instantiation compat = ToolCompatibility() print(f"โœ… ToolCompatibility instance created: {type(compat)}") # Test basic functionality from nodupe.core.tool_system.base import Tool class TestTool(Tool): """Test tool class for compatibility testing.""" @property def name(self) -> str: """Return the tool name.""" return "test_tool" @property def version(self) -> str: """Return the tool version.""" return "1.0.0" @property def dependencies(self) -> List[str]: """Return the tool dependencies.""" return ["core>=1.0.0"] def __init__(self): """Initialize the test tool.""" self.initialized = False def initialize(self, container): """Initialize the tool with a container. Args: container: The service container to use for initialization. """ self.initialized = True def shutdown(self): """Clean up tool resources.""" pass def get_capabilities(self): """Return the tool capabilities. Returns: Dictionary of capabilities. """ return {"test": True} test_tool = TestTool() # Test compatibility checking report = compat.check_compatibility(test_tool) print(f"โœ… Compatibility check successful: {report}") # Test detailed report detailed_report = compat.get_compatibility_report(test_tool) print(f"โœ… Detailed report successful: {detailed_report}") return True except ImportError as e: print(f"โŒ ImportError: {e}") traceback.print_exc() return False except Exception as e: print(f"โŒ Error: {e}") traceback.print_exc() return False def test_performance_utils(): """Test that performance utilities work correctly.""" try: print("\n๐Ÿงช Testing performance utilities...") from tests.utils import performance # Test basic functionality def test_func(x): """Test function for benchmarking.""" return x * 2 result = performance.benchmark_function_performance(test_func, 10, 2, 5) print(f"โœ… Performance benchmark successful: {result}") # Test memory measurement (should work even without psutil) mem_result = performance.measure_memory_usage(test_func, 5, 5) print(f"โœ… Memory measurement successful: {mem_result}") return True except ImportError as e: print(f"โŒ ImportError in performance utils: {e}") traceback.print_exc() return False except Exception as e: print(f"โŒ Error in performance utils: {e}") traceback.print_exc() return False def test_test_utils(): """Test that test_utils.py can be imported.""" try: print("\n๐Ÿงช Testing test_utils.py import...") # This was the file that had the resource module issue import tests.test_utils print("โœ… test_utils.py import successful") return True except ImportError as e: print(f"โŒ ImportError in test_utils: {e}") traceback.print_exc() return False except Exception as e: print(f"โŒ Error in test_utils: {e}") traceback.print_exc() return False if __name__ == "__main__": print("๐Ÿš€ Running verification tests for fixes...") results = [] results.append(test_tool_compatibility_import()) results.append(test_performance_utils()) results.append(test_test_utils()) print(f"\n๐Ÿ“Š Results: {sum(results)}/{len(results)} tests passed") if all(results): print("๐ŸŽ‰ All verification tests passed! Fixes are working correctly.") sys.exit(0) else: print("โŒ Some tests failed. Please check the errors above.") sys.exit(1)