Пример #1
0
def test_generate_netapi_fragment(test_nodenet, resourcepath):
    import os
    netapi = micropsi.nodenets[test_nodenet].netapi
    # create a bunch of nodes and link them
    linktypes = ['subsur', 'porret', 'catexp']
    nodes = []
    for t in linktypes:
        p1 = netapi.create_node('Pipe', None, t)
        p2 = netapi.create_node('Pipe', None, t + '2')
        nodes.extend([p1, p2])
        netapi.link_with_reciprocal(p1, p2, t)
    reg = netapi.create_node('Register', None, 'reg')
    netapi.link(reg, 'gen', nodes[0], 'gen')
    ns = netapi.create_nodespace(None, 'ns1')
    nodes.extend([reg, ns])
    # remember their names
    names = [n.name for n in nodes]
    fragment = micropsi.generate_netapi_fragment(test_nodenet,
                                                 [n.uid for n in nodes])
    micropsi.nodenets[test_nodenet].clear()
    code = "def foo(netapi):\n    " + "\n    ".join(fragment.split('\n'))
    # save the fragment as recipe & run
    with open(os.path.join(resourcepath, 'recipes.py'), 'w+') as fp:
        fp.write(code)
    micropsi.reload_native_modules()
    micropsi.run_recipe(test_nodenet, 'foo', {})
    # assert that all the nodes are there again
    assert set(names) == set([n.name for n in netapi.get_nodes()] + ['ns1'])
Пример #2
0
def test_generate_netapi_fragment(test_nodenet, resourcepath):
    import os
    netapi = micropsi.nodenets[test_nodenet].netapi
    # create a bunch of nodes and link them
    linktypes = ['subsur', 'porret', 'catexp']
    nodes = []
    for t in linktypes:
        p1 = netapi.create_node('Pipe', None, t)
        p2 = netapi.create_node('Pipe', None, t + '2')
        nodes.extend([p1, p2])
        netapi.link_with_reciprocal(p1, p2, t)
    reg = netapi.create_node('Register', None, 'reg')
    netapi.link(reg, 'gen', nodes[0], 'gen')
    ns = netapi.create_nodespace(None, 'ns1')
    nodes.extend([reg, ns])
    # remember their names
    names = [n.name for n in nodes]
    fragment = micropsi.generate_netapi_fragment(test_nodenet, [n.uid for n in nodes])
    micropsi.nodenets[test_nodenet].clear()
    code = "def foo(netapi):\n    " + "\n    ".join(fragment.split('\n'))
    # save the fragment as recipe & run
    with open(os.path.join(resourcepath, 'recipes.py'), 'w+') as fp:
        fp.write(code)
    micropsi.reload_native_modules()
    micropsi.run_recipe(test_nodenet, 'foo', {})
    # assert that all the nodes are there again
    assert set(names) == set([n.name for n in netapi.get_nodes()] + ['ns1'])
Пример #3
0
def test_run_recipe(fixed_nodenet, resourcepath, recipes_def):
    with open(recipes_def, 'w') as fp:
        fp.write("""
def testfoo(netapi, count=23):
    return {'count':count}
""")
    micropsi.reload_native_modules()
    state, result = micropsi.run_recipe(fixed_nodenet, 'testfoo', {'count': 42})
    assert state
    assert result['count'] == 42
Пример #4
0
def test_run_recipe(fixed_nodenet, resourcepath):
    import os
    recipe_file = os.path.join(resourcepath, 'Test', 'recipes.py')
    with open(recipe_file, 'w') as fp:
        fp.write("""
def testfoo(netapi, count=23):
    return {'count':count}
""")
    micropsi.reload_native_modules()
    state, result = micropsi.run_recipe(fixed_nodenet, 'testfoo', {'count': 42})
    assert state
    assert result['count'] == 42
Пример #5
0
def test_run_recipe(fixed_nodenet, resourcepath):
    from os import path, remove
    with open(path.join(resourcepath, 'recipes.py'), 'w') as fp:
        fp.write("""
def testfoo(netapi, count=23):
    return count
""")
    micropsi.reload_native_modules(fixed_nodenet)
    state, result = micropsi.run_recipe(fixed_nodenet, 'testfoo', {'count': 42})
    assert state
    assert result == 42
    remove(path.join(resourcepath, 'recipes.py'))
Пример #6
0
def run_recipe(nodenet_uid, name, parameters):
    return runtime.run_recipe(nodenet_uid, name, parameters)
Пример #7
0
def run_recipe(nodenet_uid, name, parameters):
    """ Run the recipe with the given name """
    return runtime.run_recipe(nodenet_uid, name, parameters)