From 4ff85cd6bda6cdb3fc53471d680a3aead1734d03 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Fri, 11 Jul 2025 16:01:17 +0100 Subject: [PATCH] Test infra --- check_imports.py | 74 +++++++++++++++++++++++++++++++++++++++++++++ install_packages.sh | 28 +++++++++++++++++ run_tests.sh | 48 +++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100755 check_imports.py create mode 100755 install_packages.sh create mode 100755 run_tests.sh diff --git a/check_imports.py b/check_imports.py new file mode 100755 index 00000000..f8c6aa95 --- /dev/null +++ b/check_imports.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +""" +Check if TrustGraph imports work correctly for testing +""" + +import sys +import traceback + +def check_import(module_name, description): + """Try to import a module and report the result""" + try: + __import__(module_name) + print(f"✅ {description}: {module_name}") + return True + except ImportError as e: + print(f"❌ {description}: {module_name}") + print(f" Error: {e}") + return False + except Exception as e: + print(f"❌ {description}: {module_name}") + print(f" Unexpected error: {e}") + return False + +def main(): + print("Checking TrustGraph imports for testing...") + print("=" * 50) + + imports_to_check = [ + ("trustgraph", "Base trustgraph package"), + ("trustgraph.base", "Base classes"), + ("trustgraph.base.llm_service", "LLM service base class"), + ("trustgraph.schema", "Schema definitions"), + ("trustgraph.exceptions", "Exception classes"), + ("trustgraph.model", "Model package"), + ("trustgraph.model.text_completion", "Text completion package"), + ("trustgraph.model.text_completion.vertexai", "VertexAI package"), + ] + + success_count = 0 + total_count = len(imports_to_check) + + for module_name, description in imports_to_check: + if check_import(module_name, description): + success_count += 1 + print() + + print("=" * 50) + print(f"Import Check Results: {success_count}/{total_count} successful") + + if success_count == total_count: + print("✅ All imports successful! Tests should work.") + else: + print("❌ Some imports failed. Please install missing packages.") + print("\nTo fix, run:") + print(" ./install_packages.sh") + print("or install packages manually:") + print(" cd trustgraph-base && pip install -e . && cd ..") + print(" cd trustgraph-vertexai && pip install -e . && cd ..") + print(" cd trustgraph-flow && pip install -e . && cd ..") + + # Test the specific import used in the test + print("\n" + "=" * 50) + print("Testing specific import from test file...") + try: + from trustgraph.model.text_completion.vertexai.llm import Processor + from trustgraph.schema import TextCompletionRequest, TextCompletionResponse, Error + from trustgraph.base import LlmResult + print("✅ Test imports successful!") + except Exception as e: + print(f"❌ Test imports failed: {e}") + traceback.print_exc() + +if __name__ == "__main__": + main() diff --git a/install_packages.sh b/install_packages.sh new file mode 100755 index 00000000..4887b530 --- /dev/null +++ b/install_packages.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Install TrustGraph packages for testing + +echo "Installing TrustGraph packages..." + +# Install base package first (required by others) +cd trustgraph-base +pip install -e . +cd .. + +# Install base package first (required by others) +cd trustgraph-cli +pip install -e . +cd .. + +# Install vertexai package (depends on base) +cd trustgraph-vertexai +pip install -e . +cd .. + +# Install flow package (for additional components) +cd trustgraph-flow +pip install -e . +cd .. + +echo "Package installation complete!" +echo "Verify installation:" +#python -c "import trustgraph.model.text_completion.vertexai.llm; print('VertexAI import successful')" diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..fbbe78f2 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Test runner script for TrustGraph + +echo "TrustGraph Test Runner" +echo "====================" + +# Check if we're in the right directory +if [ ! -f "install_packages.sh" ]; then + echo "❌ Error: Please run this script from the project root directory" + echo " Expected files: install_packages.sh, check_imports.py" + exit 1 +fi + +# Step 1: Check current imports +echo "Step 1: Checking current imports..." +python check_imports.py + +# Step 2: Install packages if needed +echo "" +echo "Step 2: Installing TrustGraph packages..." +echo "This may take a moment..." +./install_packages.sh + +# Step 3: Check imports again +echo "" +echo "Step 3: Verifying imports after installation..." +python check_imports.py + +# Step 4: Install test dependencies +echo "" +echo "Step 4: Installing test dependencies..." +cd tests/ +pip install -r requirements.txt +cd .. + +# Step 5: Run the tests +echo "" +echo "Step 5: Running VertexAI tests..." +echo "Command: pytest tests/unit/test_text_completion/test_vertexai_processor.py -v" +echo "" + +# Set Python path just in case +export PYTHONPATH=$PWD:$PYTHONPATH + +pytest tests/unit/test_text_completion/test_vertexai_processor.py -v + +echo "" +echo "Test run complete!" \ No newline at end of file