Skip to content

Commit

Permalink
Various changes to get all pytest running GREEN (#219)
Browse files Browse the repository at this point in the history
* various changes to get all tests passing via running pytest in the root maestro directory

* address CI check-schema failures

* fixing imports
  • Loading branch information
maximilien authored Feb 13, 2025
1 parent ad7b52a commit 8e9f196
Show file tree
Hide file tree
Showing 25 changed files with 155 additions and 104 deletions.
9 changes: 3 additions & 6 deletions maestro/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import dotenv
import os, sys, dotenv

dotenv.load_dotenv()

from .cli import CLI

__all__ = {
"CLI"
}
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../src")
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../cli")
36 changes: 0 additions & 36 deletions maestro/cli/cli.py

This file was deleted.

27 changes: 24 additions & 3 deletions maestro/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,32 @@
import os, yaml, json, jsonschema

from openai import OpenAI
from src.workflow import Workflow

from jsonschema.exceptions import ValidationError

from .common import Console, parse_yaml
from common import Console, parse_yaml
from src.workflow import Workflow

# Root CLI class
class CLI:
def __init__(self, args):
self.args = args
VERBOSE, DRY_RUN = False, False
if self.args['--verbose']:
VERBOSE = True
if self.args['--dry-run']:
DRY_RUN = True

def command(self):
if self.args.get('validate') and self.args['validate']:
return Validate(self.args)
elif self.args.get('create') and self.args['create']:
return Create(self.args)
elif self.args.get('run') and self.args['run']:
return Run(self.args)
elif self.args.get('deploy') and self.args['deploy']:
return Deploy(self.args)
else:
raise Exception("Invalid command")

# Base class for all commands
class Command:
Expand Down
4 changes: 2 additions & 2 deletions maestro/cli/maestro.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

from docopt import docopt

from .cli import CLI
from .common import Console
from commands import CLI
from common import Console

def __execute(command):
try:
Expand Down
1 change: 0 additions & 1 deletion maestro/demos/workflows/activity-planner-crewai.ai/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
sys.path.append("maestro/demos/agents/crewai/activity_planner")
sys.path.append("demos/agents/crewai/activity_planner")


def test_agent_runs() -> None:
"""
Verify the test agent runs correctly
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions maestro/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ readme = "README.md"
packages = [
{include = "src", from="."},
{include = "cli", from="."},
#{ include = "activity_planner", from = "demos/agents/crewai" }
# TODO - Packaging demos allows them to be run after a pip install
]

[tool.poetry.dependencies]
Expand Down
23 changes: 22 additions & 1 deletion maestro/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import dotenv

dotenv.load_dotenv()

from .workflow import Workflow
from .bee_agent import BeeAgent
from .agent import save_agent, restore_agent, remove_agent

__all__ = {
"Workflow"
}
1 change: 1 addition & 0 deletions maestro/src/agent_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
from enum import Enum
from typing import Callable, Type, Union

from .bee_agent import BeeAgent
from .crewai_agent import CrewAIAgent

Expand Down
5 changes: 2 additions & 3 deletions maestro/src/bee_agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#! /usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0

import os
import os, dotenv

import dotenv
from openai import AssistantEventHandler, OpenAI
from openai.types.beta import AssistantStreamEvent
from openai.types.beta.threads.runs import RunStep, RunStepDelta, ToolCall

from .agent import Agent
from src.agent import Agent

dotenv.load_dotenv()

Expand Down
Empty file modified maestro/src/mock_agent.py
100644 → 100755
Empty file.
20 changes: 8 additions & 12 deletions maestro/src/workflow.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#! /usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0

import os
import dotenv
from .step import Step
from .agent_factory import AgentFramework
import os, dotenv

# TODO: Refactor later to factory or similar
from .crewai_agent import CrewAIAgent
from .bee_agent import BeeAgent
from .mock_agent import MockAgent
from .agent import restore_agent
from src.step import Step
from src.agent_factory import AgentFramework

dotenv.load_dotenv()
from src.crewai_agent import CrewAIAgent
from src.bee_agent import BeeAgent
from src.mock_agent import MockAgent
from src.agent import restore_agent

dotenv.load_dotenv()

def find_index(steps, name):
for step in steps:
if step.get("name") == name:
return steps.index(step)


@staticmethod
def get_agent_class(framework: str) -> type:
if os.getenv("DRY_RUN"):
Expand All @@ -30,7 +27,6 @@ def get_agent_class(framework: str) -> type:
else:
return BeeAgent


class Workflow:
agents = {}
steps = {}
Expand Down
19 changes: 18 additions & 1 deletion maestro/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os, sys

sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../src")
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../cli")
28 changes: 18 additions & 10 deletions maestro/tests/bee/test_bee.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os, dotenv, yaml

from unittest import TestCase
import dotenv
import yaml
import os
from pytest_mock import mocker

# TODO consider moving to same directory as BeeAgent source
from src import Workflow
from src import BeeAgent
from src.workflow import Workflow
from src.bee_agent import BeeAgent

dotenv.load_dotenv()

Expand Down Expand Up @@ -43,5 +52,4 @@ def parse_yaml(file_path):
print(result)

assert result is not None
# This gets returned by the mock function which uses the prompt from the workflow
assert (result["final_prompt"]=="Mock agent: answer for Welcome")
assert result["final_prompt"].startswith("OK:Welcome")
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

from unittest import TestCase

from .cli import CLI
from cli.commands import CLI

class TestCommand(TestCase):
TEST_FIXTURES_ROOT_PATH = os.path.join(os.path.dirname(__file__), "../tests")
SCHEMAS_ROOT_PATH = os.path.join(os.path.dirname(__file__), "../schemas")
TEST_FIXTURES_ROOT_PATH = os.path.join(os.path.dirname(__file__), "..")
SCHEMAS_ROOT_PATH = os.path.join(os.path.dirname(__file__), "../../schemas")

def get_fixture(self, file_name):
return os.path.join(self.TEST_FIXTURES_ROOT_PATH, file_name)
Expand Down
23 changes: 17 additions & 6 deletions maestro/tests/crewai/test_crewai.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0

# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import dotenv, os, yaml

from unittest import TestCase
import dotenv
import os
import yaml

from src import Workflow
from src.workflow import Workflow

dotenv.load_dotenv()

# TODO: consider moving setup here
# @pytest.fixture(scope="module")


class CrewAITest(TestCase):

def test_agent_runs(self) -> None:
Expand Down
31 changes: 19 additions & 12 deletions maestro/tests/examples/test_condition.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#! /usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
#!/usr/bin/env python3

# Copyright © 2025 IBM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os, sys, json, dotenv, yaml

import json
import os
import sys

import dotenv
from openai import OpenAI
import yaml
from src import Workflow

dotenv.load_dotenv()
from src.workflow import Workflow

dotenv.load_dotenv()

def parse_yaml(file_path):
with open(file_path, "r") as file:
yaml_data = list(yaml.safe_load_all(file))
return yaml_data



if __name__ == "__main__":
agents_yaml = parse_yaml(os.path.join(os.path.dirname(__file__),"condition_agents.yaml"))
workflow_yaml = parse_yaml(os.path.join(os.path.dirname(__file__),"condition_workflow.yaml"))
Expand Down
Loading

0 comments on commit 8e9f196

Please sign in to comment.