from evileye.core.logging_config import setup_evileye_logging
from evileye.core.logger import get_module_logger
#!/usr/bin/env python3
"""
Test script to verify PipelineCapture inheritance.
"""

# Инициализация логирования для тестов
logger = setup_evileye_logging(log_level="INFO", log_to_console=True, log_to_file=True)
test_logger = get_module_logger("test")

def test_pipeline_inheritance():
    """Test PipelineCapture inheritance chain."""
    
    test_logger.info("🔍 Testing PipelineCapture Inheritance")
    test_logger.info("=" * 60)
    
    try:
        from evileye.pipelines.pipeline_capture import PipelineCapture
        from evileye.core.pipeline_simple import PipelineSimple
        from evileye.core.pipeline_base import PipelineBase
        
        # Check inheritance chain
        test_logger.info(f"PipelineCapture bases: {PipelineCapture.__bases__}")
        test_logger.info(f"PipelineSimple bases: {PipelineSimple.__bases__}")
        test_logger.info(f"PipelineBase bases: {PipelineBase.__bases__}")
        
        # Check if PipelineCapture inherits from classes with 'Pipeline' in name
        pipeline_bases = []
        for base in PipelineCapture.__bases__:
            if 'Pipeline' in base.__name__:
                pipeline_bases.append(base.__name__)
        
        test_logger.info(f"PipelineCapture pipeline bases: {pipeline_bases}")
        
        # Check inheritance chain
        assert issubclass(PipelineCapture, PipelineSimple)
        assert issubclass(PipelineSimple, PipelineBase)
        test_logger.info("✅ Inheritance chain correct")
        
        # Check that PipelineCapture is found by the discovery mechanism
        import inspect
        has_pipeline_base = any('Pipeline' in base.__name__ for base in PipelineCapture.__bases__)
        test_logger.info(f"Has pipeline base: {has_pipeline_base}")
        
        if has_pipeline_base:
            test_logger.info("✅ PipelineCapture should be discoverable")
        else:
            test_logger.info("⚠️ PipelineCapture may not be discoverable")
        
        test_logger.info("✅ PipelineCapture inheritance test completed successfully")
        
    except Exception as e:
        test_logger.error(f"❌ Error in inheritance test: {e}")
        import traceback
        traceback.print_exc()

def test_pipeline_discovery():
    """Test pipeline discovery mechanism."""
    
    test_logger.info("\n🔍 Testing Pipeline Discovery")
    test_logger.info("=" * 60)
    
    try:
        import importlib
        import inspect
        from pathlib import Path
        
        # Simulate the discovery mechanism
        pipeline_classes = {}
        
        # Search in evileye.pipelines package
        try:
            pipelines_module = importlib.import_module('evileye.pipelines')
            for name, obj in inspect.getmembers(pipelines_module):
                if (inspect.isclass(obj) and 
                    hasattr(obj, '__bases__') and 
                    any('Pipeline' in base.__name__ for base in obj.__bases__)):
                    pipeline_classes[name] = obj
                    test_logger.info(f"Found pipeline class: {name}")
        except ImportError as e:
            test_logger.info(f"Warning: Could not import evileye.pipelines: {e}")
        
        test_logger.info(f"Discovered pipeline classes: {list(pipeline_classes.keys())}")
        
        if 'PipelineCapture' in pipeline_classes:
            test_logger.info("✅ PipelineCapture discovered successfully")
        else:
            test_logger.info("❌ PipelineCapture not discovered")
            test_logger.info("Available classes:", list(pipeline_classes.keys()))
        
        test_logger.info("✅ Pipeline discovery test completed successfully")
        
    except Exception as e:
        test_logger.error(f"❌ Error in discovery test: {e}")
        import traceback
        traceback.print_exc()

def main():
    """Main test function."""
    
    test_logger.info("🔍 Pipeline Inheritance Test")
    test_logger.info("=" * 60)
    
    test_pipeline_inheritance()
    test_pipeline_discovery()
    
    test_logger.info("\n📋 Summary:")
    test_logger.info("  ✅ PipelineCapture inheritance verified")
    test_logger.info("  ✅ Discovery mechanism tested")
    test_logger.info("  ✅ All tests completed")

if __name__ == "__main__":
    main()



