def test_oned_as(self): x = np.ones(10) self.sci.push('x', x) assert self.sci.pull('x').shape == x[:, np.newaxis].T.shape sci = Scilab2Py(oned_as='column') sci.push('x', x) assert sci.pull('x').shape == x[:, np.newaxis].shape sci.exit()
def test_logging(self): # create a stringio and a handler to log to it def get_handler(): sobj = StringIO() hdlr = logging.StreamHandler(sobj) hdlr.setLevel(logging.DEBUG) return hdlr hdlr = get_handler() self.sci.logger.addHandler(hdlr) # generate some messages (logged and not logged) self.sci.ones(1, verbose=True) self.sci.logger.setLevel(logging.DEBUG) self.sci.zeros(1) # check the output lines = hdlr.stream.getvalue().strip().split('\n') resp = '\n'.join(lines) assert 'zeros(A__)' in resp print(resp) assert '0.' in resp assert 'loadmatfile ' in resp # now make an object with a desired logger logger = get_log('test') hdlr = get_handler() logger.addHandler(hdlr) logger.setLevel(logging.INFO) sci2 = Scilab2Py(logger=logger) # generate some messages (logged and not logged) sci2.ones(1, verbose=True) sci2.logger.setLevel(logging.DEBUG) sci2.zeros(1) sci2.exit() # check the output lines = hdlr.stream.getvalue().strip().split('\n') resp = '\n'.join(lines) assert 'zeros(A__)' in resp assert '0.' in resp assert 'loadmatfile' in resp
def run(self): """ Create a unique instance of Scilab and verify namespace uniqueness. Raises ====== Scilab2PyError If the thread does not sucessfully demonstrate independence """ scilab = Scilab2Py() # write the same variable name in each thread and read it back scilab.push('name', self.getName()) name = scilab.pull('name') now = datetime.datetime.now() print("{0} got '{1}' at {2}".format(self.getName(), name, now)) scilab.exit() try: assert self.getName() == name except AssertionError: # pragma: no cover raise Scilab2PyError('Thread collision detected') return
def setUp(self): self.sci = Scilab2Py() self.sci.getd(THIS_DIR)
def test_temp_dir(self): with Scilab2Py(temp_dir='.') as sci: thisdir = os.path.dirname(os.path.abspath('.')) assert sci._reader.out_file.startswith(thisdir) assert sci._writer.in_file.startswith(thisdir)
#!/usr/bin/env python import struct import serial from time import sleep import math from pprint import pprint import os os.environ[ "PATH"] += os.pathsep + "/Applications/scilab-5.5.2.app/Contents/MacOS/bin" from scilab2py import Scilab2Py sci = Scilab2Py() #SMORA = 'L' SMORA = 'XL' def set_PID_parameters(Kp, Ki, Kd, Kf, frequency): print "* Sending bytes..." ser.write( struct.pack("<BffffH", 0xFB, float(Kp), float(Ki), float(Kd), float(Kf), frequency)) print "* Waiting for answer..." while 1: data = ser.readline().strip() if 'done' in data: break print "* Done" def retrieve_PID_samples(initSpeed, finalSpeed, duration): print "* Sending bytes..."
def __init__(self): """Create our scilab instance and initialize the data array """ self.scilab = Scilab2Py() self.array = []
def test_call_path(self): with Scilab2Py() as sci: sci.getd(THIS_DIR) DATA = sci.test_datatypes() assert DATA.string.basic == 'spam'
def test_timeout(self): with Scilab2Py(timeout=2) as sci: sci.xpause(2.1e6, timeout=20) test.assert_raises(Scilab2PyError, sci.xpause, 10e6)
def test_using_closed_session(self): with Scilab2Py() as sci: sci.exit() test.assert_raises(Scilab2PyError, sci.eval, 'ones')
def setUpClass(cls): cls.sci = Scilab2Py() cls.sci.getd(THIS_DIR) cls.data = cls.sci.test_datatypes()
def setUpClass(cls): with Scilab2Py() as sci: sci.getd(THIS_DIR) cls.data = sci.test_datatypes()
def setUpClass(cls): cls.sci = Scilab2Py() cls.sci.getd(THIS_DIR)