# Path: osbrain/agent.py
# def run_agent(
#     name='',
#     nsaddr=None,
#     addr=None,
#     base=Agent,
#     serializer=None,
#     transport=None,
#     safe=None,
#     attributes=None,
# ):
#     """
#     Ease the agent creation process.
# 
#     This function will create a new agent, start the process and then run
#     its main loop through a proxy.
# 
#     Parameters
#     ----------
#     name : str, default is ''
#         Agent name or alias.
#     nsaddr : SocketAddress, default is None
#         Name server address.
#     addr : SocketAddress, default is None
#         New agent address, if it is to be fixed.
#     transport : str, AgentAddressTransport, default is None
#         Transport protocol.
#     safe : bool, default is None
#         Use safe calls by default from the Proxy.
#     attributes : dict, default is None
#         A dictionary that defines initial attributes for the agent.
# 
#     Returns
#     -------
#     proxy
#         A proxy to the new agent.
#     """
#     if not nsaddr:
#         nsaddr = os.environ.get('OSBRAIN_NAMESERVER_ADDRESS')
#     agent = AgentProcess(
#         name=name,
#         nsaddr=nsaddr,
#         addr=addr,
#         base=base,
#         serializer=serializer,
#         transport=transport,
#         attributes=attributes,
#     )
#     agent_name = agent.start()
# 
#     proxy = Proxy(agent_name, nsaddr, safe=safe)
#     proxy.run()
#     proxy.wait_for_running()
# 
#     return proxy
# 
# Path: osbrain/helper.py
# def wait_agent_condition(agent, condition, *args, timeout=3, **kwargs):
#     """
#     Wait for an agent's condition to be true.
# 
#     The condition is passed as a function which must take, at least, the
#     actual agent as a parameter, and must evaluate to a boolean result.
# 
#     Parameters
#     ----------
#     agent : Proxy
#         A proxy to the agent.
#     condition : Callable
#         A function that evaluates the desired condition.
#     timeout : float, default is 3
#         After this number of seconds the function will return `False`.
# 
#     Returns
#     -------
#     bool
#         Whether the specified condition was True.
#     """
#     return wait_condition(
#         agent.execute_as_method, condition, *args, timeout=timeout, **kwargs
#     )


import sys
from osbrain import run_agent
from osbrain.helper import wait_agent_condition
"""
Test file for bugs found in osbrain.
"""



def test_timer_recursion(nsproxy):
    """
    This bug occurred with the first implementation of the timer. After
    some iterations the timer would throw an exception when the recursion
    limit was exceeded. Timers should never reach a recursion limit.
    """

    def inc(agent):
        agent.count += 1


# Path: osbrain/agent.py
# def run_agent(
#     name='',
#     nsaddr=None,
#     addr=None,
#     base=Agent,
#     serializer=None,
#     transport=None,
#     safe=None,
#     attributes=None,
# ):
#     """
#     Ease the agent creation process.
# 
#     This function will create a new agent, start the process and then run
#     its main loop through a proxy.
# 
#     Parameters
#     ----------
#     name : str, default is ''
#         Agent name or alias.
#     nsaddr : SocketAddress, default is None
#         Name server address.
#     addr : SocketAddress, default is None
#         New agent address, if it is to be fixed.
#     transport : str, AgentAddressTransport, default is None
#         Transport protocol.
#     safe : bool, default is None
#         Use safe calls by default from the Proxy.
#     attributes : dict, default is None
#         A dictionary that defines initial attributes for the agent.
# 
#     Returns
#     -------
#     proxy
#         A proxy to the new agent.
#     """
#     if not nsaddr:
#         nsaddr = os.environ.get('OSBRAIN_NAMESERVER_ADDRESS')
#     agent = AgentProcess(
#         name=name,
#         nsaddr=nsaddr,
#         addr=addr,
#         base=base,
#         serializer=serializer,
#         transport=transport,
#         attributes=attributes,
#     )
#     agent_name = agent.start()
# 
#     proxy = Proxy(agent_name, nsaddr, safe=safe)
#     proxy.run()
#     proxy.wait_for_running()
# 
#     return proxy
# 
# Path: osbrain/helper.py
# def wait_agent_condition(agent, condition, *args, timeout=3, **kwargs):
#     """
#     Wait for an agent's condition to be true.
# 
#     The condition is passed as a function which must take, at least, the
#     actual agent as a parameter, and must evaluate to a boolean result.
# 
#     Parameters
#     ----------
#     agent : Proxy
#         A proxy to the agent.
#     condition : Callable
#         A function that evaluates the desired condition.
#     timeout : float, default is 3
#         After this number of seconds the function will return `False`.
# 
#     Returns
#     -------
#     bool
#         Whether the specified condition was True.
#     """
#     return wait_condition(
#         agent.execute_as_method, condition, *args, timeout=timeout, **kwargs
#     )


# Path: osbrain/tests/test_bugs.py
import sys
from osbrain import run_agent
from osbrain.helper import wait_agent_condition

"""
Test file for bugs found in osbrain.
"""



def test_timer_recursion(nsproxy):
    """
    This bug occurred with the first implementation of the timer. After
    some iterations the timer would throw an exception when the recursion
    limit was exceeded. Timers should never reach a recursion limit.
    """

    def inc(agent):
        agent.count += 1


    agent = run_agent('a0')