#!/usr/bin/env python3
"""
#exonware/xwdata/tests/2.integration/runner.py
Integration test runner for xwdata.
Company: eXonware.com
Author: eXonware Backend Team
Email: connect@exonware.com
Version: 0.0.1.3
Generation Date: 26-Oct-2025
"""

import sys
import pytest
from pathlib import Path
from datetime import datetime
import io
# Set UTF-8 encoding for Windows console
if sys.platform == 'win32':
    try:
        sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
        sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
    except:
        pass


def main():
    """Integration test runner."""
    # Add src to Python path
    src_path = Path(__file__).parent.parent.parent / "src"
    sys.path.insert(0, str(src_path))
    print("🔗 Integration Tests - Cross-Module Scenarios")
    # Run integration tests
    exit_code = pytest.main([
        "-v",
        "--tb=short",
        str(Path(__file__).parent),
        "-m", "xwdata_integration"
    ])
    # Status
    status = "✅ Integration tests PASSED" if exit_code == 0 else "❌ Integration tests FAILED"
    print(f"\n{status}")
    # Save Markdown output
    output_file = Path(__file__).parent / "runner_out.md"
    markdown_content = f"""# Integration Test Results
**Layer:** 2.integration
**Generated:** {datetime.now().strftime("%d-%b-%Y %H:%M:%S")}
**Status:** {'PASSED' if exit_code == 0 else 'FAILED'}
---
## Result
{status}
**Exit Code:** {exit_code}
---
*Generated by eXonware test runner - Production Excellence Edition*
"""
    output_file.write_text(markdown_content, encoding='utf-8')
    print(f"📝 Results saved to: {output_file}")
    sys.exit(exit_code)
if __name__ == "__main__":
    main()
