Пример #1
0
    def setup_class(cls):
        """Set the test up."""
        agent_name = "MyAgent"
        private_key_path = os.path.join(CUR_PATH, "data",
                                        "fet_private_key.txt")
        wallet = Wallet({FETCHAI: private_key_path})
        ledger_apis = LedgerApis({}, FETCHAI)
        resources = Resources()
        resources.add_component(
            Skill.from_dir(Path(CUR_PATH, "data", "dummy_skill")))
        identity = Identity(agent_name, address=wallet.addresses[FETCHAI])
        cls.input_file = tempfile.mkstemp()[1]
        cls.output_file = tempfile.mkstemp()[1]
        cls.agent = AEA(
            identity,
            [_make_local_connection(identity.address, LocalNode())],
            wallet,
            ledger_apis,
            resources,
        )
        for skill in resources.get_all_skills():
            skill.skill_context.set_agent_context(cls.agent.context)

        cls.t = Thread(target=cls.agent.start)
        cls.t.start()
        time.sleep(1.0)
Пример #2
0
 def setup_class(cls):
     """Set the test up."""
     agent_name = "my_agent"
     private_key_path = os.path.join(CUR_PATH, "data",
                                     "fet_private_key.txt")
     wallet = Wallet({FETCHAI: private_key_path})
     ledger_apis = LedgerApis({}, FETCHAI)
     resources = Resources()
     resources.add_component(
         Skill.from_dir(Path(CUR_PATH, "data", "dummy_skill")))
     identity = Identity(agent_name, address=wallet.addresses[FETCHAI])
     cls.context_namespace = {"key1": 1, "key2": 2}
     cls.agent = AEA(
         identity, [_make_local_connection(identity.address, LocalNode())],
         wallet, ledger_apis, resources, **cls.context_namespace)
     for skill in resources.get_all_skills():
         skill.skill_context.set_agent_context(cls.agent.context)
Пример #3
0
    def setup_class(cls):
        """Set the test up."""
        agent_name = "my_agent"
        private_key_path = os.path.join(CUR_PATH, "data",
                                        DEFAULT_PRIVATE_KEY_FILE)
        wallet = Wallet({DEFAULT_LEDGER: private_key_path})
        identity = Identity(agent_name,
                            address=wallet.addresses[DEFAULT_LEDGER])
        connection = _make_local_connection(identity.address, LocalNode())
        resources = Resources()
        cls.context_namespace = {"key1": 1, "key2": 2}
        cls.agent = AEA(identity, wallet, resources, **cls.context_namespace)

        resources.add_connection(connection)
        resources.add_component(
            Skill.from_dir(Path(CUR_PATH, "data", "dummy_skill"),
                           agent_context=cls.agent.context))
        for skill in resources.get_all_skills():
            skill.skill_context.set_agent_context(cls.agent.context)
Пример #4
0
def test_add_behaviour_dynamically():
    """Test that we can add a behaviour dynamically."""

    agent_name = "MyAgent"
    private_key_path = os.path.join(CUR_PATH, "data", "fet_private_key.txt")
    wallet = Wallet({FETCHAI: private_key_path})
    resources = Resources()
    identity = Identity(agent_name, address=wallet.addresses[FETCHAI])
    connection = _make_local_connection(identity.address, LocalNode())
    agent = AEA(
        identity,
        wallet,
        resources,
        default_connection=connection.public_id,
    )
    resources.add_connection(connection)
    resources.add_component(
        Skill.from_dir(Path(CUR_PATH, "data", "dummy_skill"),
                       agent_context=agent.context))
    for skill in resources.get_all_skills():
        skill.skill_context.set_agent_context(agent.context)

    with run_in_thread(agent.start, timeout=5, on_exit=agent.stop):
        wait_for_condition(
            lambda: agent._main_loop and agent._main_loop.is_running,
            timeout=10)

        dummy_skill_id = PublicId("dummy_author", "dummy", "0.1.0")
        dummy_skill = agent.resources.get_skill(dummy_skill_id)

        wait_for_condition(lambda: dummy_skill is not None, timeout=10)

        new_behaviour = DummyBehaviour(name="dummy2",
                                       skill_context=dummy_skill.skill_context)
        dummy_skill.skill_context.new_behaviours.put(new_behaviour)

        wait_for_condition(lambda: new_behaviour.nb_act_called > 0, timeout=10)
        wait_for_condition(
            lambda: len(agent.resources.get_behaviours(dummy_skill_id)) == 2,
            timeout=10)
Пример #5
0
def test_add_behaviour_dynamically():
    """Test that we can add a behaviour dynamically."""
    agent_name = "MyAgent"
    private_key_path = os.path.join(CUR_PATH, "data", DEFAULT_PRIVATE_KEY_FILE)
    wallet = Wallet({DEFAULT_LEDGER: private_key_path})
    resources = Resources()
    identity = Identity(agent_name, address=wallet.addresses[DEFAULT_LEDGER])
    connection = _make_local_connection(identity.address, LocalNode())
    agent = AEA(
        identity,
        wallet,
        resources,
        default_connection=connection.public_id,
    )
    resources.add_connection(connection)
    resources.add_component(
        Skill.from_dir(Path(CUR_PATH, "data", "dummy_skill"),
                       agent_context=agent.context))
    for skill in resources.get_all_skills():
        skill.skill_context.set_agent_context(agent.context)

    with run_in_thread(agent.start, timeout=5, on_exit=agent.stop):
        wait_for_condition(lambda: agent.is_running, timeout=10)

        dummy_skill_id = DUMMY_SKILL_PUBLIC_ID
        dummy_skill = agent.resources.get_skill(dummy_skill_id)

        wait_for_condition(lambda: dummy_skill is not None, timeout=10)

        new_behaviour = DummyBehaviour(name="dummy2",
                                       skill_context=dummy_skill.skill_context)
        dummy_skill.skill_context.new_behaviours.put(new_behaviour)

        wait_for_condition(lambda: new_behaviour.nb_act_called > 0, timeout=10)
        wait_for_condition(
            lambda: len(agent.resources.get_behaviours(dummy_skill_id)) == 2,
            timeout=10)