#!/usr/bin/env python3
"""
#exonware/xwsystem/tests/3.advance/caching/runner.py

Advance test runner for caching module - Excellence Validation (v1.0.0+).

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

OPTIONAL until v1.0.0, MANDATORY for use releases.

Usage:
    python tests/3.advance/caching/runner.py              # All advance tests
    python tests/3.advance/caching/runner.py --security    # Security only
    python tests/3.advance/caching/runner.py --performance # Performance only
"""

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

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


def main():
    """Advance test runner - Excellence validation."""
    args = sys.argv[1:]
    
    print("🎓 Advance Caching Tests - Excellence Validation")
    print("   Testing against eXonware's 5 Core Priorities")
    print(f"📂 Test Directory: {Path(__file__).parent.absolute()}")
    print()

    # Determine which tests to run
    if "--security" in args:
        print("   Priority #1: Security Excellence")
        marker = "xsystem_security and xsystem_caching"
        category = "Security"
    elif "--performance" in args:
        print("   Priority #4: Performance Excellence")
        marker = "xsystem_performance and xsystem_caching"
        category = "Performance"
    else:
        print("   All Priorities")
        marker = "xsystem_advance and xsystem_caching"
        category = "All"

    # Run tests
    exit_code = pytest.main([
        "-v",
        "--tb=short",
        "-x",
        str(Path(__file__).parent),
        "-m", marker
    ])

    # Status
    if exit_code == 0:
        status = "✅ Advance caching tests PASSED"
    else:
        status = "❌ Advance caching tests FAILED"

    print()
    print(status)

    # Save Markdown output
    output_file = Path(__file__).parent / "runner_out.md"
    markdown_content = f"""# Advance Caching Test Results

**Module:** Caching
**Layer:** 3.advance
**Category:** {category}
**Generated:** {datetime.now().strftime("%d-%b-%Y %H:%M:%S")}
**Status:** {'PASSED' if exit_code == 0 else 'FAILED'}

---

## eXonware's 5 Core Priorities

| Priority | Category | Status |
|----------|----------|--------|
| #1 | **Security** | {'✅ Tested' if category in ['Security', 'All'] else 'N/A'} |
| #2 | **Usability** | N/A |
| #3 | **Maintainability** | N/A |
| #4 | **Performance** | {'✅ Tested' if category in ['Performance', 'All'] else 'N/A'} |
| #5 | **Extensibility** | N/A |

---

## Test Execution

**Command:** `python tests/3.advance/caching/runner.py`

**Marker:** `{marker}`

---

## Result

{status}

**Exit Code:** {exit_code}

---

### Readiness

{'✅ This module meets excellence standards for the tested category.' if exit_code == 0 else '❌ This module requires improvements before deployment.'}

---

*Generated by eXonware test runner - Excellence Edition*
"""

    output_file.write_text(markdown_content, encoding='utf-8')
    print(f"📝 Results saved to: {output_file.absolute()}")

    sys.exit(exit_code)


if __name__ == "__main__":
    main()

