#!/usr/bin/env python3
"""
#exonware/xwsystem/tests/1.unit/caching_tests/runner.py

Test runner for caching module unit tests.

Company: eXonware.com
Author: Eng. Muhammad AlShehri
Email: connect@exonware.com
Version: 0.0.1.388
Generation Date: 01-Nov-2025
"""

import sys
import pytest
from pathlib import Path
from datetime import datetime

# Add src to path
src_path = Path(__file__).parent.parent.parent.parent / "src"
sys.path.insert(0, str(src_path))


def main():
    """Run caching module unit tests."""
    module_name = Path(__file__).parent.name.replace('_tests', '')
    print(f"🧪 Testing: {module_name}")
    
    # Run module tests
    exit_code = pytest.main([
        "-v",
        "--tb=short",
        "-x",  # Stop on first failure
        str(Path(__file__).parent),
        "-m", "xsystem_unit"
    ])
    
    # Save Markdown output
    status = "PASSED" if exit_code == 0 else "FAILED"
    output_file = Path(__file__).parent / "runner_out.md"
    
    markdown_content = f"""# Module Test Results: {module_name}

**Module:** {module_name}
**Layer:** 1.unit
**Generated:** {datetime.now().strftime("%d-%b-%Y %H:%M:%S")}
**Status:** {status}

---

## Test Execution

**Command:** `python tests/1.unit/{module_name}_tests/runner.py`

**Markers:** `xsystem_unit`

**Options:**
- Verbose output (`-v`)
- Short traceback (`--tb=short`)
- Stop on first failure (`-x`)

---

## Result

{'✅ PASSED' if exit_code == 0 else '❌ FAILED'}

**Exit Code:** {exit_code}

---

*Generated by eXonware test runner - Excellence Edition*
"""
    
    output_file.write_text(markdown_content, encoding='utf-8')
    
    print(f"\n📝 Results saved to: {output_file}")
    
    sys.exit(exit_code)


if __name__ == "__main__":
    main()

