Skip to main content

Code-Guardian by TGSC

Project description

Code Guardian

Generate tests with swarms of agents

Join our Discord Subscribe on YouTube Connect on LinkedIn Follow on X.com

CodeGuardian is an intelligent agent designed to automate the generation of production-grade unit tests for your Python code. It not only creates and runs these tests but also monitors them in real-time, providing you with comprehensive summaries of your code health. With CodeGuardian, you can enhance code reliability, maintainability, and accelerate your development workflow.

Features

  • Automated Test Generation: Automatically generate unit tests for your existing Python codebase.
  • Test Execution: Run generated tests seamlessly and view results instantly.
  • Real-Time Monitoring: Watch tests in real-time to observe code behavior and performance.
  • Code Health Summaries: Receive detailed reports on test coverage, code quality, and potential issues.
  • Easy Integration: Integrate effortlessly with existing projects and CI/CD pipelines.
  • Customizable Configurations: Tailor settings to match your project requirements.

Prerequisites

  • Python 3.7 or higher
  • pip package manager

Installation

pip3 install -U code-guardian

Example

import os

from dotenv import load_dotenv
from swarms import Agent, OpenAIChat

from code_guardian.main import CodeGuardian

load_dotenv()

# Get the OpenAI API key from the environment variable
api_key = os.getenv("OPENAI_API_KEY")

# Create an instance of the OpenAIChat class
model = OpenAIChat(
    openai_api_key=api_key,
    model_name="gpt-4o-mini",
    temperature=0.1,
    max_tokens=2000,
)

# Initialize the agent for generating unit tests
agent = Agent(
    agent_name="Unit-Test-Generator-Agent",  # Changed agent name
    system_prompt="Generate unit tests for the provided classes using pytest.",  # Updated system prompt
    llm=model,
    max_loops=1,
    autosave=True,
    dashboard=False,
    verbose=True,
    dynamic_temperature_enabled=True,
    saved_state_path="unit_test_agent.json",  # Updated saved state path
    user_name="swarms_corp",
    retry_attempts=1,
    context_length=200000,
    return_step_meta=False,
    # output_type="json",
)

# Classes you want to generate tests for
classes_to_test = [CodeGuardian]

# Initialize CodeGuardian and run
guardian = CodeGuardian(
    classes=classes_to_test, # classes to test
    agent=agent, # agent to use
    dir_path="tests", # directory to save tests
    package_name="code-guardian", # package name
    module_name="code_guardian.main", # module name
)
guardian.run()

Configuration Options

  • test_directory: Directory where tests are stored.
  • source_directory: Directory containing your source code.
  • exclude_patterns: Files or directories to exclude.
  • report_format: Format of the code health report (html, json, xml).
  • watch: Settings for real-time monitoring.

Roadmap

  • Multi-language Support: Extend functionality to other programming languages.
  • Advanced Static Analysis: Integrate deeper code analysis tools.
  • IDE Plugins: Develop plugins for popular IDEs like VSCode and PyCharm.
  • Enhanced Reporting: Add more detailed metrics and visualizations.

Contributing

We welcome contributions! Please see our Contributing Guidelines for details on how to get started.

License

CodeGuardian is licensed under the MIT License.

Acknowledgements

  • Inspired by the need for robust automated testing tools.
  • Thanks to the open-source community for their invaluable contributions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_guardian-0.1.4.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

code_guardian-0.1.4-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file code_guardian-0.1.4.tar.gz.

File metadata

  • Download URL: code_guardian-0.1.4.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/23.3.0

File hashes

Hashes for code_guardian-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2f31f48a891bfe37d40a30e30303b34e91fa796a10dc6dd0563f3eb696513755
MD5 5dffbbf98629e95d6688b13dc433ad98
BLAKE2b-256 1d4ec3276ad884702862c47ea200cce13e199231ecb9a1d3ef8a1dad9072eee8

See more details on using hashes here.

Provenance

File details

Details for the file code_guardian-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: code_guardian-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Darwin/23.3.0

File hashes

Hashes for code_guardian-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 dad3a855725d528a9c9e1a80d651de84954b18d62b566bfcc51d7b0cafe1d33d
MD5 b5e496a0b3422feeec80576ddd83508f
BLAKE2b-256 86edf05a2d8ce462167112f51d31f2d4f0c87891c33d7eec4be7c51fb9e3d50f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page