def test_user_prompt(fixed_nodenet, nodetype_def, nodefunc_def): with open(nodetype_def, 'w') as fp: fp.write('{"Testnode": {\ "name": "Testnode",\ "slottypes": ["gen", "foo", "bar"],\ "gatetypes": ["gen", "foo", "bar"],\ "nodefunction_name": "testnodefunc",\ "parameters": ["testparam"],\ "parameter_defaults": {\ "testparam": 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="Test") nativemodule = micropsi.nodenets[fixed_nodenet].get_node(uid) options = [{ 'key': 'foo_parameter', 'label': 'Please give value for "foo"', 'values': [23, 42] }] micropsi.nodenets[fixed_nodenet].netapi.ask_user_for_parameter( nativemodule, "foobar", options) result, data = micropsi.get_current_state(fixed_nodenet, nodenet={'nodespace': 'Root'}) assert 'user_prompt' in data assert data['user_prompt']['msg'] == 'foobar' assert data['user_prompt']['node']['uid'] == uid assert data['user_prompt']['options'] == options # response micropsi.user_prompt_response(fixed_nodenet, uid, {'foo_parameter': 42}, True) assert micropsi.nodenets[fixed_nodenet].get_node(uid).get_parameter( 'foo_parameter') == 42 assert micropsi.nodenets[fixed_nodenet].is_active from micropsi_core.nodenet import nodefunctions tmp = nodefunctions.concept nodefunc = mock.Mock() nodefunctions.concept = nodefunc micropsi.nodenets[fixed_nodenet].step() foo = micropsi.nodenets[fixed_nodenet].get_node('n0001').clone_parameters() foo.update({'foo_parameter': 42}) assert nodefunc.called_with( micropsi.nodenets[fixed_nodenet].netapi, micropsi.nodenets[fixed_nodenet].get_node('n0001'), foo) micropsi.nodenets[fixed_nodenet].get_node('n0001').clear_parameter( 'foo_parameter') assert micropsi.nodenets[fixed_nodenet].get_node('n0001').get_parameter( 'foo_parameter') is None nodefunctions.concept = tmp
def test_user_prompt(fixed_nodenet, nodetype_def, nodefunc_def): with open(nodetype_def, 'w') as fp: fp.write('{"Testnode": {\ "name": "Testnode",\ "slottypes": ["gen", "foo", "bar"],\ "gatetypes": ["gen", "foo", "bar"],\ "nodefunction_name": "testnodefunc",\ "parameters": ["testparam"],\ "parameter_defaults": {\ "testparam": 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="Test") nativemodule = micropsi.nodenets[fixed_nodenet].get_node(uid) options = [{'key': 'foo_parameter', 'label': 'Please give value for "foo"', 'values': [23, 42]}] micropsi.nodenets[fixed_nodenet].netapi.ask_user_for_parameter( nativemodule, "foobar", options ) result, data = micropsi.get_current_state(fixed_nodenet, nodenet={'nodespace': 'Root'}) assert 'user_prompt' in data assert data['user_prompt']['msg'] == 'foobar' assert data['user_prompt']['node']['uid'] == uid assert data['user_prompt']['options'] == options # response micropsi.user_prompt_response(fixed_nodenet, uid, {'foo_parameter': 42}, True) assert micropsi.nodenets[fixed_nodenet].get_node(uid).get_parameter('foo_parameter') == 42 assert micropsi.nodenets[fixed_nodenet].is_active from micropsi_core.nodenet import nodefunctions tmp = nodefunctions.concept nodefunc = mock.Mock() nodefunctions.concept = nodefunc micropsi.nodenets[fixed_nodenet].step() foo = micropsi.nodenets[fixed_nodenet].get_node('n0001').clone_parameters() foo.update({'foo_parameter': 42}) assert nodefunc.called_with(micropsi.nodenets[fixed_nodenet].netapi, micropsi.nodenets[fixed_nodenet].get_node('n0001'), foo) micropsi.nodenets[fixed_nodenet].get_node('n0001').clear_parameter('foo_parameter') assert micropsi.nodenets[fixed_nodenet].get_node('n0001').get_parameter('foo_parameter') is None nodefunctions.concept = tmp
def get_current_state(nodenet_uid, nodenet=None, world=None, monitors=None, dashboard=None): return runtime.get_current_state(nodenet_uid, nodenet=nodenet, world=world, monitors=monitors, dashboard=dashboard)