From 03a9861e73786e022cb48f1697ac7c76654a8c7b Mon Sep 17 00:00:00 2001 From: Eduardo Chiarotti Date: Mon, 29 Jul 2024 21:41:14 -0300 Subject: [PATCH] feat: change test_crew to evalaute_crew to avoid issues with testing libs --- src/crewai/cli/cli.py | 4 +-- .../cli/{test_crew.py => evaluate_crew.py} | 6 ++--- tests/cli/test_crew_test.py | 26 +++++++++---------- 3 files changed, 17 insertions(+), 19 deletions(-) rename src/crewai/cli/{test_crew.py => evaluate_crew.py} (83%) diff --git a/src/crewai/cli/cli.py b/src/crewai/cli/cli.py index c9f03f3fb..52d2bc75c 100644 --- a/src/crewai/cli/cli.py +++ b/src/crewai/cli/cli.py @@ -6,9 +6,9 @@ from crewai.memory.storage.kickoff_task_outputs_storage import ( ) from .create_crew import create_crew +from .evaluate_crew import evaluate_crew from .replay_from_task import replay_task_command from .reset_memories_command import reset_memories_command -from .test_crew import test_crew from .train_crew import train_crew @@ -144,7 +144,7 @@ def reset_memories(long, short, entities, kickoff_outputs, all): def test(n_iterations: int, model: str): """Test the crew and evaluate the results.""" click.echo(f"Testing the crew for {n_iterations} iterations with model {model}") - test_crew(n_iterations, model) + evaluate_crew(n_iterations, model) if __name__ == "__main__": diff --git a/src/crewai/cli/test_crew.py b/src/crewai/cli/evaluate_crew.py similarity index 83% rename from src/crewai/cli/test_crew.py rename to src/crewai/cli/evaluate_crew.py index 9bbe7bf47..30abda380 100644 --- a/src/crewai/cli/test_crew.py +++ b/src/crewai/cli/evaluate_crew.py @@ -2,12 +2,10 @@ import subprocess import click -# pytest.skip(allow_module_level=True) - -def test_crew(n_iterations: int, model: str) -> None: +def evaluate_crew(n_iterations: int, model: str) -> None: """ - Test the crew by running a command in the Poetry environment. + Test and Evaluate the crew by running a command in the Poetry environment. Args: n_iterations (int): The number of iterations to test the crew. diff --git a/tests/cli/test_crew_test.py b/tests/cli/test_crew_test.py index 90649710a..578e413bc 100644 --- a/tests/cli/test_crew_test.py +++ b/tests/cli/test_crew_test.py @@ -3,7 +3,7 @@ from unittest import mock import pytest -from crewai.cli import test_crew +from crewai.cli import evaluate_crew @pytest.mark.parametrize( @@ -14,13 +14,13 @@ from crewai.cli import test_crew (10, "gpt-4"), ], ) -@mock.patch("crewai.cli.test_crew.subprocess.run") +@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"poetry run test {n_iterations} {model}", returncode=0 ) - result = test_crew.test_crew(n_iterations, model) + result = evaluate_crew.evaluate_crew(n_iterations, model) mock_subprocess_run.assert_called_once_with( ["poetry", "run", "test", str(n_iterations), model], @@ -31,26 +31,26 @@ def test_crew_success(mock_subprocess_run, n_iterations, model): assert result is None -@mock.patch("crewai.cli.test_crew.click") +@mock.patch("crewai.cli.evaluate_crew.click") def test_test_crew_zero_iterations(click): - test_crew.test_crew(0, "gpt-4o") + 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.test_crew.click") +@mock.patch("crewai.cli.evaluate_crew.click") def test_test_crew_negative_iterations(click): - test_crew.test_crew(-2, "gpt-4o") + 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.test_crew.click") -@mock.patch("crewai.cli.test_crew.subprocess.run") +@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( @@ -59,7 +59,7 @@ def test_test_crew_called_process_error(mock_subprocess_run, click): output="Error", stderr="Some error occurred", ) - test_crew.test_crew(n_iterations, "gpt-4o") + evaluate_crew.evaluate_crew(n_iterations, "gpt-4o") mock_subprocess_run.assert_called_once_with( ["poetry", "run", "test", "5", "gpt-4o"], @@ -78,13 +78,13 @@ def test_test_crew_called_process_error(mock_subprocess_run, click): ) -@mock.patch("crewai.cli.test_crew.click") -@mock.patch("crewai.cli.test_crew.subprocess.run") +@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") - test_crew.test_crew(n_iterations, "gpt-4o") + evaluate_crew.evaluate_crew(n_iterations, "gpt-4o") mock_subprocess_run.assert_called_once_with( ["poetry", "run", "test", "5", "gpt-4o"],