Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
args: [--line-length=79]
exclude: ^ExampleTests/generatedTests/.*$
# Only run on changed files
stages: [commit]
stages: [pre-commit]

- repo: https://github.com/pycqa/flake8
rev: 6.0.0 # Choose the appropriate version
Expand All @@ -17,15 +17,19 @@ repos:
'flake8-bugbear',
'flake8-comprehensions',
]
exclude: ^(ExampleTests/generatedTests/|ExampleTests/pythonTestPrograms/).*$
exclude: ^(ExampleTests/generatedTests/|ExampleTests/pythonTestPrograms/|backend/extracted/|backend/cli_implementation_summary\.py|backend/demo_.*\.py|backend/export_manager\.py|backend/implementation_complete\.py|backend/test_.*\.py|backend/tests/|backend/modules/export_manager\.py).*$
# Only run on changed files
stages: [commit]
stages: [pre-commit]
# This ensures flake8 only runs on files being committed
pass_filenames: true
# Optional: specify file types to check
types: [python]

- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: pytest -q
entry: python3 -m pytest -q
language: system
pass_filenames: false
always_run: true
stages: [pre-commit]
1 change: 0 additions & 1 deletion Deliverables/sprint-01/Dummy.md

This file was deleted.

1 change: 0 additions & 1 deletion Deliverables/sprint-02/dummy.md

This file was deleted.

23 changes: 10 additions & 13 deletions backend/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""API module for the AI-driven testing backend."""

import os
import json
import importlib
Expand Down Expand Up @@ -58,6 +60,7 @@
def discover_modules() -> List[Dict[str, str]]:
"""
Automatically discover all valid modules in the modules directory.

Returns a list of module information dictionaries.
"""
modules_dir = os.path.join(SCRIPT_DIR, "modules")
Expand Down Expand Up @@ -129,9 +132,7 @@ def discover_modules() -> List[Dict[str, str]]:


async def process_prompt_request(req: PromptData) -> Dict:
"""
Process a prompt request through the LLM pipeline with optional module processing.
"""
"""Process a prompt request through the LLM pipeline with optional module processing."""
logger.debug(f"Request details: {req}")

model_id = req.model.id
Expand Down Expand Up @@ -199,6 +200,7 @@ def format_prompt_response(
"ccc_complexity_output": response_data.output.ccc_complexity,
"mcc_complexity_output": response_data.output.mcc_complexity,
"lm_eval": response_data.output.lm_eval,
"coverage_data": response_data.output.coverage_data,
},
"timing": {
"loading_time": response_data.timing.loading_time,
Expand All @@ -219,9 +221,7 @@ def format_prompt_response(
# --------------------------------------------------------------------------- #
@app.get("/models")
def list_models() -> List[Dict]:
"""
Returns the list of allowed models and whether the container is currently running.
"""
"""Return the list of allowed models and whether the container is currently running."""
out = []
for m in AVAILABLE_MODELS:
m_id = m["id"]
Expand All @@ -239,9 +239,7 @@ def list_models() -> List[Dict]:

@app.post("/prompt")
async def prompt(req: PromptData):
"""
Process a prompt request through the LLM pipeline with optional module processing.
"""
"""Process a prompt request through the LLM pipeline with optional module processing."""
try:
return await process_prompt_request(req)
except HTTPException:
Expand All @@ -255,9 +253,7 @@ async def prompt(req: PromptData):

@app.post("/shutdown")
async def shutdown(req: Dict[str, str]):
"""
Shutdown a running model container.
"""
"""Shutdown a running model container."""
model_id = req.get("model_id")
if not model_id:
raise HTTPException(status_code=400, detail="Missing 'model_id'")
Expand All @@ -268,7 +264,8 @@ async def shutdown(req: Dict[str, str]):
@app.get("/modules")
def list_modules() -> List[Dict]:
"""
Returns the list of all available modules in the modules directory.
Return the list of all available modules in the modules directory.

Each module entry contains id, name, and metadata about when it applies.
"""
try:
Expand Down
Empty file.
Empty file added backend/demo_cli_export.py
Empty file.
Empty file.
Empty file added backend/demo_export_manager.py
Empty file.
Empty file added backend/export_manager.py
Empty file.
54 changes: 37 additions & 17 deletions backend/extracted/prompt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
"""Simple command-line calculator application.
"""Simple command-line calculator application."""


def calculate_result(a, b, op):
"""Calculate result of two numbers with given operator.

Args:
a: First number
b: Second number
op: Operator (+, -, *, /)

Returns:
The calculated result

Raises:
ValueError: If operator is invalid
"""
if op == "+":
return a + b
elif op == "-":
return a - b
elif op == "*":
return a * b
elif op == "/":
if b == 0:
raise ValueError("Division by zero")
return a / b
else:
raise ValueError(f"Invalid operator: {op}")


def calculator():
"""Run an interactive command-line calculator.
Expand All @@ -15,22 +44,13 @@ def calculator():
op = input("Enter operator (+, -, *, /): ")
b = float(input("Enter second number: "))

if op == "+":
result = a + b
elif op == "-":
result = a - b
elif op == "*":
result = a * b
elif op == "/":
if b == 0:
print("Error: Division by zero")
return
result = a / b
else:
print("Invalid operator")
try:
result = calculate_result(a, b, op)
print("Result:", result)
except ValueError as e:
print(f"Error: {e}")
return

print("Result:", result)


calculator()
if __name__ == "__main__":
calculator()
81 changes: 50 additions & 31 deletions backend/extracted/response.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,69 @@
import sys
from pathlib import Path
sys.path.insert(0, '/code/extracted') # Add extracted dir to import path
from prompt import * # Import functions from prompt.py
import unittest

sys.path.insert(0, "/code/extracted") # Add extracted dir to import path
from prompt import (
calculate_result,
calculator,
) # Import functions from prompt.py
import pytest # required for pytest
import math # required for math functions
from calculator import (
calculator,
) # import calculator module as defined earlier in this file


class TestCalculateResult(unittest.TestCase):
def test_addition(self):
self.assertEqual(calculate_result(2, 3, "+"), 5)

def test_subtraction(self):
self.assertEqual(calculate_result(5, 3, "-"), 2)

def test_multiplication(self):
self.assertEqual(calculate_result(4, 3, "*"), 12)

def test_division(self):
self.assertEqual(calculate_result(10, 2, "/"), 5.0)

def test_division_by_zero(self):
with self.assertRaises(ValueError):
calculate_result(10, 0, "/")

def test_invalid_operator(self):
with self.assertRaises(ValueError):
calculate_result(5, 3, "%")


def test_addition():
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
result = calculator()
assert result == (a + b)
"""Test addition using pytest."""
assert calculate_result(2, 3, "+") == 5


def test_subtraction():
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
result = calculator()
assert result == (a - b)
"""Test subtraction using pytest."""
assert calculate_result(5, 3, "-") == 2


def test_multiplication():
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
result = calculator()
assert result == (a * b)
"""Test multiplication using pytest."""
assert calculate_result(4, 3, "*") == 12


def test_division():
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
if b == 0:
print("Error: Division by zero")
return
result = calculator()
assert result == (a / b)
"""Test division using pytest."""
assert calculate_result(10, 2, "/") == 5.0


def test_division_by_zero():
"""Test division by zero raises ValueError."""
with pytest.raises(ValueError):
calculate_result(10, 0, "/")


def test_invalid_operator():
a = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): ")
if op != "+":
print("Invaliad operator")
return
result = calculator()
assert result is None
"""Test invalid operator raises ValueError."""
with pytest.raises(ValueError):
calculate_result(5, 3, "%")


if __name__ == "__main__":
unittest.main()
Empty file.
12 changes: 12 additions & 0 deletions backend/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Modules package for the AI-driven testing system.

This package contains various modules that extend the functionality
of the LLM-based testing system.
"""

from .code_coverage_analyzer import CodeCoverageAnalyzer

__all__ = [
"CodeCoverageAnalyzer",
]
Loading
Loading