mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-13 01:58:30 +00:00
Fix issue #2528: Restore language option in crew configuration
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
40
tests/crew_language_test.py
Normal file
40
tests/crew_language_test.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
from crewai import Crew, Agent, Process, Task
|
||||
from crewai.utilities.i18n import I18N
|
||||
|
||||
|
||||
def test_crew_with_language():
|
||||
i18n = I18N(language="en")
|
||||
|
||||
agent = Agent(
|
||||
role="Test Agent",
|
||||
goal="Test Goal",
|
||||
backstory="Test Backstory",
|
||||
verbose=True
|
||||
)
|
||||
|
||||
task = Task(
|
||||
description="Test Task",
|
||||
expected_output="Test Output",
|
||||
agent=agent
|
||||
)
|
||||
|
||||
with patch('crewai.crew.I18N') as mock_i18n:
|
||||
mock_i18n.return_value = i18n
|
||||
|
||||
crew = Crew(
|
||||
agents=[agent],
|
||||
tasks=[task],
|
||||
process=Process.sequential,
|
||||
verbose=True,
|
||||
language="fr" # Use French as an example
|
||||
)
|
||||
|
||||
with patch.object(crew, '_run_sequential_process'):
|
||||
with patch.object(crew, '_set_tasks_callbacks'):
|
||||
with patch('crewai.agent.Agent.create_agent_executor'):
|
||||
crew.kickoff()
|
||||
|
||||
mock_i18n.assert_called_with(prompt_file=None, language="fr")
|
||||
@@ -42,3 +42,13 @@ def test_prompt_file():
|
||||
i18n.load_prompts()
|
||||
assert isinstance(i18n.retrieve("slices", "role_playing"), str)
|
||||
assert i18n.retrieve("slices", "role_playing") == "Lorem ipsum dolor sit amet"
|
||||
|
||||
|
||||
def test_language_parameter():
|
||||
i18n = I18N(language="en")
|
||||
i18n.load_prompts()
|
||||
assert isinstance(i18n.slice("role_playing"), str)
|
||||
|
||||
i18n = I18N(language="nonexistent")
|
||||
i18n.load_prompts()
|
||||
assert isinstance(i18n.slice("role_playing"), str)
|
||||
|
||||
Reference in New Issue
Block a user