Beispiel #1
0
def test_sensor_actuator_indices(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    result, world_uid = micropsi.new_world('default', 'World')
    micropsi.set_nodenet_properties(test_nodenet,
                                    worldadapter='Default',
                                    world_uid=world_uid)
    sensor = netapi.create_node("Sensor", None, "static_sensor")
    sensor.set_parameter("datasource", "static_on")
    actor = netapi.create_node("Actor", None, "echo_actor")
    actor.set_parameter("datatarget", "echo")
    register = netapi.create_node("Register", None, "source")
    register.activation = 0.8
    netapi.link(register, 'gen', register, 'gen', weight=0.5)
    netapi.link(register, 'gen', actor, 'gen')
    assert sensor.activation == 0
    assert actor.get_gate('gen').activation == 0
    micropsi.step_nodenet(test_nodenet)
    micropsi.step_nodenet(test_nodenet)
    assert sensor.activation == 1
    assert round(actor.get_gate('gen').activation, 3) == 0.8
    netapi.delete_node(sensor)
    netapi.delete_node(actor)
    assert set(nodenet.rootpartition.actuator_indices) == {0}
    assert set(nodenet.rootpartition.sensor_indices) == {0}
Beispiel #2
0
def test_island(resourcepath):
    success, world_uid = micropsi.new_world("Misland",
                                            "Island",
                                            owner="tester")
    assert success
    world = runtime.worlds[world_uid]
    assert world.__class__.__name__ == 'Island'
    runtime.add_worldobject(world_uid,
                            "Lightsource", (10, 10),
                            uid='foobar',
                            name='foobar',
                            parameters={})
    runtime.save_world(world_uid)
    runtime.revert_world(world_uid)
    world = runtime.worlds[world_uid]
    assert world.objects["foobar"].__class__.__name__ == 'Lightsource'
    assert world.objects["foobar"].position == [10, 10]
    assert world.data['objects']['foobar']['position'] == [10, 10]
    assert world.__class__.__name__ == 'Island'
    runtime.set_worldobject_properties(world_uid, "foobar", position=(5, 5))
    assert world.objects["foobar"].position == (5, 5)
    assert world.data['objects']['foobar']['position'] == (5, 5)
    assert runtime.get_world_view(world_uid,
                                  -1)['objects']['foobar']['position'] == (5,
                                                                           5)
    runtime.delete_world(world_uid)
Beispiel #3
0
def edit_world():
    user_id, permissions, token = get_request_data()
    if "manage worlds" in permissions:
        result, uid = runtime.new_world(request.params['world_name'], request.params['world_type'], user_id)
        if result:
            return dict(status="success", msg="World created", world_uid=uid)
        else:
            return dict(status="error", msg=": %s" % result)
    return dict(status="error", msg="Insufficient rights to create world")
Beispiel #4
0
def test_world(request):
    """
    Fixture: A test world of type Island
    """
    global world_uid
    success, world_uid = micropsi.new_world("World of Pain", "Island", "Pytest User", uid=world_uid)
    yield world_uid
    try:
        micropsi.delete_world(world_uid)
    except:
        pass
def add_dummyworld(fixed_nodenet):
    nodenet = micropsi.get_nodenet(fixed_nodenet)
    if nodenet.world:
        micropsi.worlds[nodenet.world].unregister_nodenet(nodenet)

    worlduid = micropsi.new_world("DummyWorld", "DummyWorld", "DummyOwner")[1]

    nodenet.world = worlduid
    nodenet.worldadapter = "DummyWorldAdapter"
    micropsi.worlds[worlduid].register_nodenet("DummyWorldAdapter", nodenet)
    return micropsi.worlds[worlduid]
Beispiel #6
0
def default_world(request):
    """
    Fixture: A test world of type Island
    """
    global world_uid
    success, world_uid = micropsi_runtime.new_world("World of Pain", "DefaultWorld", "Pytest User")
    yield world_uid
    try:
        micropsi_runtime.delete_world(world_uid)
    except:
        pass
def add_dummyworld(fixed_nodenet):
    nodenet = micropsi.get_nodenet(fixed_nodenet)
    if nodenet.world:
        nodenet.world.unregister_nodenet(nodenet.uid)

    worlduid = micropsi.new_world("DummyWorld", "DummyWorld", "DummyOwner")[1]

    nodenet.world = micropsi.worlds[worlduid]
    nodenet.worldadapter = "DummyWorldAdapter"
    nodenet.world.register_nodenet("DummyWorldAdapter", nodenet)
    return nodenet.world
Beispiel #8
0
def test_world(request):
    global world_uid
    worlds = micropsi.get_available_worlds("Pytest User")
    if worlds:
        world_uid = list(worlds.keys())[0]
    else:
        success, world_uid = micropsi.new_world("World of Pain", "Island", "Pytest User")
    def fin():
        if DELETE_TEST_FILES_ON_EXIT:
            micropsi.delete_world(world_uid)
    request.addfinalizer(fin)
    return world_uid
Beispiel #9
0
def test_worlds_are_configurable():
    res, uid = runtime.new_world('testworld',
                                 'Island',
                                 config={
                                     'foo': 'bar',
                                     '42': '23'
                                 })
    assert uid in runtime.worlds
    assert runtime.worlds[uid].data['config']['foo'] == 'bar'
    runtime.revert_world(uid)
    assert runtime.worlds[uid].data['config']['foo'] == 'bar'
    assert runtime.worlds[uid].data['config']['42'] == '23'
Beispiel #10
0
def test_world(request):
    global world_uid
    worlds = micropsi.get_available_worlds("Pytest User")
    if world_uid not in worlds:
        success, world_uid = micropsi.new_world("World of Pain", "Island", "Pytest User", uid=world_uid)

    def fin():
        try:
            micropsi.revert_world(world_uid)
        except KeyError:
            pass  # world was deleted in test
    request.addfinalizer(fin)
    return world_uid
Beispiel #11
0
def edit_world():
    params = dict((key, request.forms.getunicode(key)) for key in request.forms)
    type = params['world_type']
    config = {}
    for p in params:
        if p.startswith(type + '_'):
            config[p[len(type) + 1:]] = params[p]
    user_id, permissions, token = get_request_data()
    if "manage worlds" in permissions:
        result, uid = runtime.new_world(params['world_name'], params['world_type'], user_id, config=config)
        if result:
            return dict(status="success", msg="World created", world_uid=uid)
        else:
            return dict(status="error", msg=": %s" % result)
    return dict(status="error", msg="Insufficient rights to create world")
Beispiel #12
0
def test_world(request):
    global world_uid
    worlds = micropsi.get_available_worlds("Pytest User")
    if world_uid not in worlds:
        success, world_uid = micropsi.new_world("World of Pain",
                                                "Island",
                                                "Pytest User",
                                                uid=world_uid)

    def fin():
        try:
            micropsi.delete_world(world_uid)
        except:
            pass  # world was deleted in test

    request.addfinalizer(fin)
    return world_uid
Beispiel #13
0
def test_island(resourcepath):
    success, world_uid = micropsi.new_world("Misland", "Island", owner="tester")
    assert success
    world = runtime.worlds[world_uid]
    assert world.__class__.__name__ == 'Island'
    runtime.add_worldobject(world_uid, "Lightsource", (10, 10), uid='foobar', name='foobar', parameters={})
    runtime.save_world(world_uid)
    runtime.revert_world(world_uid)
    world = runtime.worlds[world_uid]
    assert world.objects["foobar"].__class__.__name__ == 'Lightsource'
    assert world.objects["foobar"].position == [10, 10]
    assert world.data['objects']['foobar']['position'] == [10, 10]
    assert world.__class__.__name__ == 'Island'
    runtime.set_worldobject_properties(world_uid, "foobar", position=(5, 5))
    assert world.objects["foobar"].position == (5, 5)
    assert world.data['objects']['foobar']['position'] == (5, 5)
    assert runtime.get_world_view(world_uid, -1)['objects']['foobar']['position'] == (5, 5)
    runtime.delete_world(world_uid)
Beispiel #14
0
def test_new_world(resourcepath, test_world):
    success, world_uid = micropsi.new_world("Waterworld", "World", owner="tester")
    assert success
    assert world_uid != test_world
    world_properties = micropsi.get_world_properties(world_uid)
    assert world_properties["name"] == "Waterworld"
    w_path = os.path.join(resourcepath, runtime.WORLD_DIRECTORY, world_uid + ".json")
    assert os.path.exists(w_path)

    # get_available_worlds
    worlds = micropsi.get_available_worlds()
    myworlds = micropsi.get_available_worlds("tester")
    assert test_world in worlds
    assert world_uid in worlds
    assert world_uid in myworlds
    assert test_world not in myworlds

    # delete_world
    micropsi.delete_world(world_uid)
    assert world_uid not in micropsi.get_available_worlds()
    assert not os.path.exists(w_path)
def test_new_world(resourcepath, test_world):
    success, world_uid = micropsi.new_world("Waterworld", "World", owner="tester")
    assert success
    assert world_uid != test_world
    world_properties = micropsi.get_world_properties(world_uid)
    assert world_properties["name"] == "Waterworld"
    w_path = os.path.join(resourcepath, runtime.WORLD_DIRECTORY, world_uid + ".json")
    assert os.path.exists(w_path)

    # get_available_worlds
    worlds = micropsi.get_available_worlds()
    myworlds = micropsi.get_available_worlds("tester")
    assert test_world in worlds
    assert world_uid in worlds
    assert world_uid in myworlds
    assert test_world not in myworlds

    # delete_world
    micropsi.delete_world(world_uid)
    assert world_uid not in micropsi.get_available_worlds()
    assert not os.path.exists(w_path)
def test_sensor_actuator_indices(test_nodenet):
    nodenet = micropsi.get_nodenet(test_nodenet)
    netapi = nodenet.netapi
    result, world_uid = micropsi.new_world('default', 'World')
    micropsi.set_nodenet_properties(test_nodenet, worldadapter='Default', world_uid=world_uid)
    sensor = netapi.create_node("Sensor", None, "static_sensor")
    sensor.set_parameter("datasource", "static_on")
    actor = netapi.create_node("Actor", None, "echo_actor")
    actor.set_parameter("datatarget", "echo")
    register = netapi.create_node("Register", None, "source")
    register.activation = 0.8
    netapi.link(register, 'gen', register, 'gen', weight=0.5)
    netapi.link(register, 'gen', actor, 'gen')
    assert sensor.activation == 0
    assert actor.get_gate('gen').activation == 0
    micropsi.step_nodenet(test_nodenet)
    micropsi.step_nodenet(test_nodenet)
    assert sensor.activation == 1
    assert round(actor.get_gate('gen').activation, 3) == 0.8
    netapi.delete_node(sensor)
    netapi.delete_node(actor)
    assert set(nodenet.rootpartition.actuator_indices) == {0}
    assert set(nodenet.rootpartition.sensor_indices) == {0}
Beispiel #17
0
def new_world(world_name, world_type, owner=None):
    if owner is None:
        owner, _, _ = get_request_data()
    return runtime.new_world(world_name, world_type, owner)
Beispiel #18
0
def new_world(world_name, world_type, owner=None, config={}):
    """ Create a new world with the given name, of the given type """
    if owner is None:
        owner, _, _ = get_request_data()
    return runtime.new_world(world_name, world_type, owner=owner, config=config)
Beispiel #19
0
def new_world(world_name, world_type, owner=""):
    return runtime.new_world(world_name, world_type, owner)