示例#1
0
def test_remove_and_reload_native_module(fixed_nodenet, resourcepath):
    import os
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "gatetypes": ["gen", "foo", "bar"],\
            "symbol": "t",\
            "gate_defaults":{\
              "foo": {\
                "amplification": 13\
              }\
            }}}')
    with open(nodefunc_file, 'w') as fp:
        fp.write("def testnodefunc(netapi, node=None, **prams):\r\n    return 17")

    micropsi.reload_native_modules()
    res, uid = micropsi.add_node(fixed_nodenet, "Testnode", [10, 10, 10], name="Testnode")
    os.remove(nodetype_file)
    os.remove(nodefunc_file)
    micropsi.reload_native_modules()
    assert 'Testnode' not in micropsi.get_available_native_module_types(fixed_nodenet)
示例#2
0
def test_native_module_and_recipe_categories(fixed_nodenet, resourcepath):
    import os
    os.mkdir(os.path.join(resourcepath, 'Test', 'Test2'))
    nodetype_file = os.path.join(resourcepath, 'Test', 'nodetypes.json')
    nodefunc_file = os.path.join(resourcepath, 'Test', 'nodefunctions.py')
    recipe_file = os.path.join(resourcepath, 'Test', 'Test2', 'recipes.py')
    with open(nodetype_file, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "gatetypes": ["gen", "foo", "bar"]\
            }}')
    with open(nodefunc_file, 'w') as fp:
        fp.write("def testnodefunc(netapi, node=None, **prams):\r\n    return 17")
    with open(recipe_file, 'w') as fp:
        fp.write("def testrecipe(netapi):\r\n    pass")
    micropsi.reload_native_modules()
    res = micropsi.get_available_native_module_types(fixed_nodenet)
    assert res['Testnode']['category'] == 'Test'
    res = micropsi.get_available_recipes()
    assert res['testrecipe']['category'] == 'Test/Test2'
示例#3
0
def test_remove_and_reload_native_module(fixed_nodenet, resourcepath, nodetype_def, nodefunc_def):
    from os import remove
    with open(nodetype_def, 'w') as fp:
        fp.write('{"Testnode": {\
            "name": "Testnode",\
            "slottypes": ["gen", "foo", "bar"],\
            "nodefunction_name": "testnodefunc",\
            "gatetypes": ["gen", "foo", "bar"],\
            "symbol": "t",\
            "gate_defaults":{\
              "foo": {\
                "amplification": 13\
              }\
            }}}')
    with open(nodefunc_def, 'w') as fp:
        fp.write("def testnodefunc(netapi, node=None, **prams):\r\n    return 17")

    micropsi.reload_native_modules()
    res, uid = micropsi.add_node(fixed_nodenet, "Testnode", [10, 10], name="Testnode")
    remove(nodetype_def)
    remove(nodefunc_def)
    micropsi.reload_native_modules()
    assert micropsi.get_available_native_module_types(fixed_nodenet) == {}
示例#4
0
def get_available_native_module_types(nodenet_uid):
    return True, runtime.get_available_native_module_types(nodenet_uid)
示例#5
0
def get_available_native_module_types(nodenet_uid):
    """ Return a dict of available native module types"""
    return True, runtime.get_available_native_module_types(nodenet_uid)