Skip to content

Commit

Permalink
adding extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura committed Nov 13, 2023
1 parent e6f928a commit 4e984e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def check_config(_cls, values):

if values.get('config'):
config = json.loads(values.get('config'))
if not config['agents'] or not config['tasks']:
if not config.get('agents') or not config.get('tasks'):
raise ValueError('Config should have agents and tasks.')

values['agents'] = [Agent(**agent) for agent in config['agents']]
Expand Down
26 changes: 26 additions & 0 deletions tests/crew_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ def test_crew_config_conditional_requirement():
assert [agent.role for agent in crew.agents] == [agent['role'] for agent in parsed_config['agents']]
assert [task.description for task in crew.tasks] == [task['description'] for task in parsed_config['tasks']]

def test_crew_config_with_wrong_keys():
no_tasks_config = json.dumps({
"agents": [
{
"role": "Senior Researcher",
"goal": "Make the best research and analysis on content about AI and AI agents",
"backstory": "You're an expert researcher, specialized in technology, software engineering, AI and startups. You work as a freelancer and is now working on doing research and analysis for a new customer."
}
]
})

no_agents_config = json.dumps({
"tasks": [
{
"description": "Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
"agent": "Senior Researcher"
}
]
})
with pytest.raises(ValueError):
Crew(process=Process.sequential, config='{"wrong_key": "wrong_value"}')
with pytest.raises(ValueError):
Crew(process=Process.sequential, config=no_tasks_config)
with pytest.raises(ValueError):
Crew(process=Process.sequential, config=no_agents_config)

@pytest.mark.vcr()
def test_crew_creation():
tasks = [
Expand Down

0 comments on commit 4e984e9

Please sign in to comment.