mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-05 06:08:29 +00:00
* feat: Start migrating to UV * feat: add uv to flows * feat: update docs on Poetry -> uv * feat: update docs and uv.locl * feat: update tests and github CI * feat: run ruff format * feat: update typechecking * feat: fix type checking * feat: update python version * feat: type checking gic * feat: adapt uv command to run the tool repo * Adapt tool build command to uv * feat: update logic to let only projects with crew to be deployed * feat: add uv to tools * fix; tests * fix: remove breakpoint * fix :test * feat: add crewai update to migrate from poetry to uv * fix: tests * feat: add validation for ˆ character on pyproject * feat: add run_crew to pyproject if doesnt exist * feat: add validation for poetry migration * fix: warning --------- Co-authored-by: Vinicius Brasil <vini@hey.com>
98 lines
2.9 KiB
Python
98 lines
2.9 KiB
Python
import subprocess
|
|
from unittest import mock
|
|
|
|
import pytest
|
|
|
|
from crewai.cli import evaluate_crew
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"n_iterations,model",
|
|
[
|
|
(1, "gpt-4o"),
|
|
(5, "gpt-3.5-turbo"),
|
|
(10, "gpt-4"),
|
|
],
|
|
)
|
|
@mock.patch("crewai.cli.evaluate_crew.subprocess.run")
|
|
def test_crew_success(mock_subprocess_run, n_iterations, model):
|
|
"""Test the crew function for successful execution."""
|
|
mock_subprocess_run.return_value = subprocess.CompletedProcess(
|
|
args=f"uv run test {n_iterations} {model}", returncode=0
|
|
)
|
|
result = evaluate_crew.evaluate_crew(n_iterations, model)
|
|
|
|
mock_subprocess_run.assert_called_once_with(
|
|
["uv", "run", "test", str(n_iterations), model],
|
|
capture_output=False,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
assert result is None
|
|
|
|
|
|
@mock.patch("crewai.cli.evaluate_crew.click")
|
|
def test_test_crew_zero_iterations(click):
|
|
evaluate_crew.evaluate_crew(0, "gpt-4o")
|
|
click.echo.assert_called_once_with(
|
|
"An unexpected error occurred: The number of iterations must be a positive integer.",
|
|
err=True,
|
|
)
|
|
|
|
|
|
@mock.patch("crewai.cli.evaluate_crew.click")
|
|
def test_test_crew_negative_iterations(click):
|
|
evaluate_crew.evaluate_crew(-2, "gpt-4o")
|
|
click.echo.assert_called_once_with(
|
|
"An unexpected error occurred: The number of iterations must be a positive integer.",
|
|
err=True,
|
|
)
|
|
|
|
|
|
@mock.patch("crewai.cli.evaluate_crew.click")
|
|
@mock.patch("crewai.cli.evaluate_crew.subprocess.run")
|
|
def test_test_crew_called_process_error(mock_subprocess_run, click):
|
|
n_iterations = 5
|
|
mock_subprocess_run.side_effect = subprocess.CalledProcessError(
|
|
returncode=1,
|
|
cmd=["uv", "run", "test", str(n_iterations), "gpt-4o"],
|
|
output="Error",
|
|
stderr="Some error occurred",
|
|
)
|
|
evaluate_crew.evaluate_crew(n_iterations, "gpt-4o")
|
|
|
|
mock_subprocess_run.assert_called_once_with(
|
|
["uv", "run", "test", "5", "gpt-4o"],
|
|
capture_output=False,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
click.echo.assert_has_calls(
|
|
[
|
|
mock.call.echo(
|
|
"An error occurred while testing the crew: Command '['uv', 'run', 'test', '5', 'gpt-4o']' returned non-zero exit status 1.",
|
|
err=True,
|
|
),
|
|
mock.call.echo("Error", err=True),
|
|
]
|
|
)
|
|
|
|
|
|
@mock.patch("crewai.cli.evaluate_crew.click")
|
|
@mock.patch("crewai.cli.evaluate_crew.subprocess.run")
|
|
def test_test_crew_unexpected_exception(mock_subprocess_run, click):
|
|
# Arrange
|
|
n_iterations = 5
|
|
mock_subprocess_run.side_effect = Exception("Unexpected error")
|
|
evaluate_crew.evaluate_crew(n_iterations, "gpt-4o")
|
|
|
|
mock_subprocess_run.assert_called_once_with(
|
|
["uv", "run", "test", "5", "gpt-4o"],
|
|
capture_output=False,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
click.echo.assert_called_once_with(
|
|
"An unexpected error occurred: Unexpected error", err=True
|
|
)
|