Skip to content

Latest commit

History

61 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Code Testing Agent Framework

📋 Table of Contents

  • Overview
  • Key Features
  • Installation
  • Configuration
  • Detailed Component Breakdown
  • Advanced Usage
  • Error Handling
  • Performance Considerations
  • Future Roadmap

🚀 Overview

An AI-powered code testing framework that analyzes, tests, and provides feedback on code based on specifications.

✨ Key Features

  • Static code analysis using AST
  • Automatic test case generation
  • AI-powered edge case analysis
  • Comprehensive test execution
  • Detailed feedback and reporting

🤖 Supported Language Models

ModelProviderSupport LevelCapabilities
GPT-4OpenAIFullAdvanced analysis, comprehensive feedback
GPT-3.5 TurboOpenAIBasicStandard analysis, limited depth
Claude 3 OpusAnthropicExperimentalAdvanced reasoning, nuanced feedback

💻 Installation

Install from PyPI

pip install code-testing-agent

Or install from source

git clone https://github.com/yourusername/code-testing-agent.git
cd code-testing-agent
pip install -e .

🔧 Configuration

🔑 API Key Management

Environment Variables

importosfromdotenvimportload_dotenv# Load API keys from .env fileload_dotenv()
# Set OpenAI API keyos.environ['OPENAI_API_KEY'] ='your-openai-api-key'

Direct Configuration

fromcode_testing_agentimportCodeTester# Initialize with API keytester=CodeTester(llm_api_key='your-api-key')

🔬 Detailed Component Breakdown

1. CodeSpec (Specification Model)

CodeSpec(
description: str, # Human-readable description of the codeexpected_inputs: Dict[str, type], # Input type constraintsexpected_outputs: Dict[str, type], # Output type constraintsexample_test_cases: List[Dict[str, Any]], # Predefined test casesconstraints: Optional[List[str]] =None# Additional code constraints
)

Example

spec=CodeSpec(
description="Calculate average of a list of numbers",
expected_inputs={"numbers": list},
expected_outputs={"result": float},
example_test_cases=[
{
"inputs": {"numbers": [1, 2, 3, 4, 5]},
"expected": 3.0
}
],
constraints=[
"Input list must contain only numbers",
"Handles empty list by returning 0"
]
)

2. 🕵️ Advanced Analysis Techniques

Static Code Analysis

  • Abstract Syntax Tree (AST) parsing
  • Syntax structure evaluation
  • Potential issue detection
  • Code complexity assessment

Potential Detected Issues

  • Mutable default arguments
  • Infinite loops
  • Redundant comparisons
  • Exception handling anti-patterns

🚀 Advanced Usage

Custom Model Configuration

fromcode_testing_agentimportCodeTester
# Configure with custom OpenAI modeltester=CodeTester(
llm_api_key='your-key',
model='gpt-4', # Specify modeltemperature=0.7, # Adjust creativitymax_tokens=500# Limit response length
)

Extending Analysis

fromcode_testing_agent.analyzersimportCodeAnalyzerclassCustomCodeAnalyzer(CodeAnalyzer):
defadditional_checks(self, tree: ast.AST):
# Add custom static analysis rulespass

🛠 Error Handling

Custom Exceptions

CodeTestingError: Base exception ValidationError: Code validation failures TestExecutionError: Test runtime errors

try:
result=tester.test_code(code, spec)
exceptValidationErrorase:
print(f"Code validation failed: {e}")
exceptTestExecutionErrorase:
print(f"Test execution error: {e}")

📊 Performance Considerations

  • Caching analysis results
  • Configurable recursion limits
  • Timeout mechanisms for long-running tests
  • Selective test case execution

🚦 Future Roadmap

  • Multi-language support
  • More advanced AI models
  • Enhanced test case generation
  • Performance profiling
  • Integration with CI/CD pipelines

About

🧪 AI-Powered Code Testing Agent: Comprehensive framework for (1) Static code analysis, (2) Automatic test case generation, and (3) Intelligent code feedback. Supports multiple AI models (GPT-4, Claude 3 Opus) with advanced error detection and customizable testing strategies 🤖

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages