OverviewFilesCommitsIssuesDocsReleasesPeers

ollama_semantic_function_calling / ollamatools-new / tests / test_keet_messaging.py

78 lines · python ref:
#!/usr/bin/env python3
"""
Test script to verify basic Keet messaging functionality.
This script runs the JavaScript test script as a subprocess.
"""

import logging
import sys
import os
import subprocess
import json
from pathlib import Path

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def test_keet_messaging():
    """Test basic Keet messaging functionality by running the JavaScript test script."""
    try:
        # Get the directory of this script
        script_dir = Path(__file__).parent.absolute()
        
        # Path to the JavaScript test script
        js_test_script = script_dir / "keet_messaging_test.js"
        
        if not js_test_script.exists():
            logger.error(f"JavaScript test script not found at {js_test_script}")
            return False
        
        # Check if Node.js is available
        try:
            subprocess.run(["node", "--version"], check=True, capture_output=True)
        except (subprocess.SubprocessError, FileNotFoundError):
            logger.error("Node.js is not available. Skipping test.")
            return False
        
        # Check if the required npm packages are installed
        package_json = script_dir / "package.json"
        if not package_json.exists():
            logger.error(f"package.json not found at {package_json}")
            return False
        
        # Run the JavaScript test script
        logger.info("Running Keet messaging test script...")
        result = subprocess.run(
            ["node", str(js_test_script)],
            cwd=script_dir,
            capture_output=True,
            text=True
        )
        
        # Log the output
        for line in result.stdout.splitlines():
            logger.info(line)
        
        for line in result.stderr.splitlines():
            logger.error(line)
        
        # Check if the test was successful
        if result.returncode == 0:
            logger.info("Keet messaging test successful!")
            return True
        else:
            logger.error("Keet messaging test failed!")
            return False
        
    except Exception as e:
        logger.error(f"Error in Keet messaging test: {e}")
        return False

if __name__ == "__main__":
    success = test_keet_messaging()
    if success:
        sys.exit(0)
    else:
        sys.exit(1)