def load_nodenet(nodenet_uid, nodespace='Root', include_links=True): result, uid = runtime.load_nodenet(nodenet_uid) if result: data = runtime.get_nodenet_data(nodenet_uid, nodespace, -1, include_links) data['nodetypes'] = runtime.get_available_node_types(nodenet_uid) data['recipes'] = runtime.get_available_recipes() return True, data else: return False, uid
def load_nodenet(nodenet_uid, nodespace='Root', coordinates={}): result, uid = runtime.load_nodenet(nodenet_uid) if result: data = runtime.get_nodenet_data(nodenet_uid, nodespace, coordinates) data['nodetypes'] = runtime.get_available_node_types(nodenet_uid) data['recipes'] = runtime.get_available_recipes() return True, data else: return False, uid
def test_get_recipes(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() recipes = micropsi.get_available_recipes() assert 'testfoo' in recipes assert len(recipes['testfoo']['parameters']) == 1 assert recipes['testfoo']['parameters'][0]['name'] == 'count' assert recipes['testfoo']['parameters'][0]['default'] == 23
def test_get_recipes(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) recipes = micropsi.get_available_recipes() assert 'testfoo' in recipes assert len(recipes['testfoo']['parameters']) == 1 assert recipes['testfoo']['parameters'][0]['name'] == 'count' assert recipes['testfoo']['parameters'][0]['default'] == 23 remove(path.join(resourcepath, 'recipes.py'))
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'
def get_available_recipes(): return True, runtime.get_available_recipes()
def get_available_recipes(): """ Return a dict of available recipes """ return True, runtime.get_available_recipes()