Skip to content

Commit

Permalink
Merge pull request #129 from fetchai/tests/agent_test
Browse files Browse the repository at this point in the history
Tests/agent test
  • Loading branch information
marcofavorito authored Sep 26, 2019
2 parents 2cb312f + baa838b commit f8a0707
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aea/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def agent_state(self) -> AgentState:
elif self.mailbox.is_connected and not self.liveness.is_stopped:
return AgentState.RUNNING
else:
raise ValueError("Agent state not recognized.")
raise ValueError("Agent state not recognized.") # pragma: no cover

def start(self) -> None:
"""
Expand Down
69 changes: 68 additions & 1 deletion tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,71 @@
# limitations under the License.
#
# ------------------------------------------------------------------------------
"""This module contains the tests for aea.agent.py."""

"""This module contains the tests of the agent module."""

import time
from threading import Thread

from aea.agent import Agent, AgentState
from aea.connections.local.connection import LocalNode, OEFLocalConnection
from aea.crypto.base import Crypto
from aea.mail.base import MailBox, InBox, OutBox


class DummyAgent(Agent):
"""A dummy agent for testing."""

def __init__(self, *args, **kwargs):
"""Initialize the agent."""
super().__init__(*args, **kwargs)

def setup(self) -> None:
"""Set up the agent."""
pass

def act(self) -> None:
"""Act."""
pass

def react(self) -> None:
"""React to events."""
pass

def update(self) -> None:
"""Update the state of the agent."""
pass

def teardown(self) -> None:
"""Tear down the agent."""
pass


def test_run_agent():
"""Test that we can set up and then run the agent."""
agent_name = "dummyagent"
agent = DummyAgent(agent_name)
mailbox = MailBox(OEFLocalConnection("mypbk", LocalNode()))
agent.mailbox = mailbox
assert agent.name == agent_name
assert isinstance(agent.crypto, Crypto)
assert agent.agent_state == AgentState.INITIATED,\
"Agent state must be 'initiated'"

agent.mailbox.connect()
assert agent.agent_state == AgentState.CONNECTED,\
"Agent state must be 'connected'"

assert isinstance(agent.inbox, InBox)
assert isinstance(agent.outbox, OutBox)

agent_thread = Thread(target=agent.start)
agent_thread.start()
time.sleep(1)

assert agent.agent_state == AgentState.RUNNING,\
"Agent state must be 'running'"

agent.stop()
agent.mailbox.disconnect()
agent_thread.join()
19 changes: 19 additions & 0 deletions tests/test_scaffold_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2018-2019 Fetch.AI Limited
#
# 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.
#
# ------------------------------------------------------------------------------
"""This module contains the tests for aea.aea.py."""

0 comments on commit f8a0707

Please sign in to comment.