def do_send_recv(language='python', fmt='%f\\n%d', msg=[float(1.0), np.int32(2)], input_interface='YggInput', output_interface='YggOutput'): r"""Function to perform simple send/receive between two comms using a language interface that calls the Python interface. Args: language (str, optional): Language that should be mimicked for the interface test. Defaults to 'python'. fmt (str, optional): Format string to use for the test. Defaults to '%f\\n%d'. msg (object, optional): Message object that should be used for the test. Defaults to [float(1.0), int(2)]. input_interface (str, optional): Name of the interface function/class that should be used for the test. Defaults to 'YggInput'. output_interface (str, optional): Name of the interface function/class that should be used for the test. Defaults to 'YggOutput'. """ name = 'test_%s' % language # Set converter based on language driver ldrv = import_component('model', language) converter = ldrv.python2language # Create and start drivers to transport messages iodrv = ConnectionDriver.ConnectionDriver(name, inputs=[{ 'partner_model': 'model1', 'allow_multiple_comms': True }], outputs=[{ 'partner_model': 'model2', 'allow_multiple_comms': True }]) iodrv.start() os.environ.update(iodrv.icomm.opp_comms) os.environ.update(iodrv.ocomm.opp_comms) # Connect and utilize interface under disguise as target language try: with ModelEnv(language=language, YGG_THREADING='True'): # Ensure start-up by waiting for signon message i = YggInterface.YggInit(input_interface, (name, fmt)) i.drain_server_signon_messages() # Output o = YggInterface.YggInit(output_interface, (name, fmt)) o.send(*msg) o.send_eof() o.close(linger=True) # Input assert (i.recv() == (True, converter(msg))) assert (i.recv() == (False, converter(constants.YGG_MSG_EOF))) finally: iodrv.terminate()
def do_send_recv(language='python', fmt='%f\\n%d', msg=[float(1.0), int(2)], input_interface='YggInput', output_interface='YggOutput'): r"""Function to perform simple send/receive between two comms using a language interface that calls the Python interface. Args: language (str, optional): Language that should be mimicked for the interface test. Defaults to 'python'. fmt (str, optional): Format string to use for the test. Defaults to '%f\\n%d'. msg (object, optional): Message object that should be used for the test. Defaults to [float(1.0), int(2)]. input_interface (str, optional): Name of the interface function/class that should be used for the test. Defaults to 'YggInput'. output_interface (str, optional): Name of the interface function/class that should be used for the test. Defaults to 'YggOutput'. """ name = 'test_%s' % language # Set converter based on language driver ldrv = import_component('model', language) converter = ldrv.python2language if converter is None: def converter(x): return x # Create and start drivers to transport messages odrv = OutputDriver.OutputDriver(name, 'link') odrv.start() os.environ.update(odrv.env) idrv = InputDriver.InputDriver(name, 'link', comm_env=odrv.comm_env) idrv.start() os.environ.update(idrv.env) # Connect and utilize interface under disguise as target language try: with ModelEnv(language=language): # Output o = YggInterface.YggInit(output_interface, (name, fmt)) o.send(*msg) o.send_eof() o.close() # Input i = YggInterface.YggInit(input_interface, (name, fmt)) assert_equal(i.recv(), (True, converter(msg))) assert_equal(i.recv(), (False, converter(YGG_MSG_EOF))) finally: odrv.terminate() idrv.terminate()
def test_YggInit_variables(): r"""Test Matlab interface for variables.""" assert (YggInterface.YggInit('YGG_MSG_MAX') == YGG_MSG_MAX) assert (YggInterface.YggInit('YGG_MSG_EOF') == constants.YGG_MSG_EOF) assert (YggInterface.YggInit('YGG_MSG_EOF') == YggInterface.YggInit( 'CIS_MSG_EOF')) assert (YggInterface.YggInit('YGG_MSG_EOF') == YggInterface.YggInit( 'PSI_MSG_EOF'))
def test_YggInit_variables(): r"""Test Matlab interface for variables.""" assert_equal(YggInterface.YggInit('YGG_MSG_MAX'), YGG_MSG_MAX) assert_equal(YggInterface.YggInit('YGG_MSG_EOF'), YGG_MSG_EOF) assert_equal(YggInterface.YggInit('YGG_MSG_EOF'), YggInterface.YggInit('CIS_MSG_EOF')) assert_equal(YggInterface.YggInit('YGG_MSG_EOF'), YggInterface.YggInit('PSI_MSG_EOF'))
def test_init(): r"""Test error on init.""" with pytest.raises(Exception): YggInterface.YggInput('error') with pytest.raises(Exception): YggInterface.YggOutput('error')
def test_bufMsgSize(): r"""Test buf message size.""" assert (YggInterface.bufMsgSize() == constants.YGG_MSG_BUF)
def test_eof_msg(): r"""Test eof message signal.""" assert (YggInterface.eof_msg() == constants.YGG_MSG_EOF)
def test_maxMsgSize(): r"""Test max message size.""" assert (YggInterface.maxMsgSize() == YGG_MSG_MAX)
def test_bufMsgSize(): r"""Test buf message size.""" assert_equal(YggInterface.bufMsgSize(), YGG_MSG_BUF)
def test_eof_msg(): r"""Test eof message signal.""" assert_equal(YggInterface.eof_msg(), YGG_MSG_EOF)