def tdiPythonInterface(self): self._doTdiTest("Py('a=None')",1) self._doTdiTest("Py('a=None','a')",None) self._doTdiTest("Py('a=123','a')",123) self._doTdiTest("Py('import MDSplus;a=MDSplus.Uint8(-1)','a')",m.Uint8(255)) self._doTdiTest("pyfun('Uint8','MDSplus',-1)",m.Uint8(255)) self._doTdiTest("pyfun('Uint8',*,-1)",m.Uint8(255)) self._doTdiTest("pyfun('str',*,123)",m.String("123")) self._doTdiTest('_l=list(*,1,2,3)', m.List([1,2,3])) self._doTdiTest('_l=list(_l,4,5)', m.List([1,2,3,4,5])) self._doTdiTest('apdrm(_l,1,3)', m.List([1,3,5])) self._doTdiTest('_d=dict(*,1,"1",2,"2")', m.Dictionary([1,'1',2,'2'])) self._doTdiTest('_d=dict(_d,3,"3")', m.Dictionary([1,'1',2,'2',3,"3"])) self._doTdiTest('apdrm(_d,2)', m.Dictionary([1,'1',3,"3"]))
def data(self): self.assertEqual(m.Data(0x80000000).__class__, m.Int64) self.assertEqual(m.Data(0x7fffffff).__class__, m.Int32) if m.version.ispy2: self.assertEqual(m.Data(long(1)).__class__, m.Int64) a = m.ADD(m.Int32(1), m.Int32(2)) self.assertEqual(m.MULTIPLY(a, a).decompile(), "(1 + 2) * (1 + 2)") self.assertEqual(m.Data(2).compare(2), True) self.assertEqual(m.Data(2).compare(1), False) self.assertEqual( m.Dictionary([1, 'a', 2, 'b']).data().tolist(), { 1: 'a', 2: 'b' }) self.assertEqual( m.List([1, 'a', 2, 'b']).data().tolist(), [1, 'a', 2, 'b']) a = m.Apd() e = m.Data(1) e.tree = 'dummy_e' f = m.Data(2) f.tree = 'dummy_f' self.assertEqual(a.tree, None) a.append(e) # a should use tree of e self.assertEqual(a.tree, e.tree) self.assertEqual(a[0].tree, e.tree) a.append(f) # a should keep tree of e self.assertEqual(a.tree, e.tree) self.assertEqual(a[1].tree, f.tree) self._doUnaryArray(m.Int32(range(10)), m.Int32Array(range(10)), 'Int32(range(10))')
def tdi(self): from MDSplus import mdsExceptions as Exc """Test Exceptions""" self._doExceptionTest('abort()', Exc.TdiABORT) self._doExceptionTest('{,}', Exc.TdiSYNTAX) self._doExceptionTest('abs()', Exc.TdiMISS_ARG) self._doExceptionTest('abs("")', Exc.TdiINVDTYDSC) self._doExceptionTest('abs(1,2)', Exc.TdiEXTRA_ARG) self._doExceptionTest('"', Exc.TdiUNBALANCE) """Test $Missing/NoData/None""" self._doTdiTest('', None) """ comparison """ self._doTdiTest('-1O > 1O', False) self._doTdiTest('-1O > -2O', True) """Test abs""" self._doThreeTest('abs(cmplx(3.0,4.0))', m.ABS(m.Complex64(3. + 4.j)), m.Float32(5.)) """Test abs1""" self._doThreeTest('abs1(cmplx(3.0,4.0))', m.ABS1(m.Complex64(3. + 4.j)), m.Float32(7.)) """Test abssq""" self._doThreeTest('abssq(cmplx(3.0,4.0))', m.ABSSQ(m.Complex64(3. + 4.j)), m.Float32(25.)) """Test accumulate""" self._doThreeTestArray('accumulate([1,2,3])', m.ACCUMULATE(m.makeArray([1, 2, 3])), m.Int32Array([1, 3, 6])) self._doThreeTestArray( 'accumulate([[1,3,5],[2,4,6]])', m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]])), m.Int32Array([[1, 4, 9], [11, 15, 21]])) self._doThreeTestArray( 'accumulate([[1,3,5],[2,4,6]],0)', m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]]), 0), m.Int32Array([[1, 4, 9], [2, 6, 12]])) self._doThreeTestArray( 'accumulate([[1,3,5],[2,4,6]],1)', m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]]), 1), m.Int32Array([[1, 3, 5], [3, 7, 11]])) """Test achar""" self._doThreeTest('achar(88)', m.ACHAR(88), m.String('X')) """Test ADJUSTL""" self._doThreeTest('adjustl(" WORD")', m.ADJUSTL(" WORD"), m.String("WORD ")) """Test ADJUSTR""" self._doThreeTest('adjustr("WORD ")', m.ADJUSTR("WORD "), m.String(" WORD")) """Test AIMAG""" self._doThreeTest('AIMAG(CMPLX(2.0,3.0))', m.AIMAG(m.CMPLX(2., 3.)), m.Float32(3.0)) """Test AINT""" self._doThreeTest('aint(2.783)', m.AINT(2.783), m.Float32(2.0)) self._doThreeTest('aint(-2.783)', m.AINT(-2.783), m.Float32(-2.0)) """Test NE (operates on flattened array, i.e. first 3 values are compared)""" A, B = array([1, 3, 5], int32), array([[0, 3, 5], [0, 0, 0], [0, 4, 8]], int32) self._doThreeTestArray( '_A=[1,3,5],_B=[[0,3,5],[0,0,0],[0,4,8]],_A ne _B', m.NE(A, B), m.Uint8Array([1, 0, 0])) """Test NE (operates on flattened array, i.e. first 3 values are compared)""" self._doThreeTestArray('_A eq _B', m.EQ(A, B), m.Uint8Array([0, 1, 1])) """Test ALL and ANY""" self._doThreeTest('all([$TRUE,$FALSE,$TRUE])', m.ALL(array([m.dTRUE(), m.dFALSE(), m.dTRUE()])), m.Uint8(0)) self._doThreeTest('any([$TRUE,$FALSE,$TRUE])', m.ANY(array([m.dTRUE(), m.dFALSE(), m.dTRUE()])), m.Uint8(1)) A = 0 self._doThreeTest('_A=0,all(_A eq _B)', m.ALL(m.EQ(A, B)), False) self._doThreeTest('any(_A ne _B)', m.ANY(m.NE(A, B)), True) self._doThreeTestArray('all(_A ne _B,0)', m.ALL(m.NE(A, B), 0), m.Uint8Array([0, 0, 0])) self._doThreeTestArray('any(_A ne _B,0)', m.ANY(m.NE(A, B), 0), m.Uint8Array([1, 0, 1])) self._doThreeTestArray('all(_A eq _B,1)', m.ALL(m.EQ(A, B), 1), m.Uint8Array([1, 0, 0])) self._doThreeTestArray('any(_A ne _B,1)', m.ANY(m.NE(A, B), 1), m.Uint8Array([0, 1, 1])) """Test allocated""" self.assertEqual(m.DEALLOCATE('*') >= 2, True) # deallocates _A and _B and more? self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(0)) self._doTdiTest('_xyz=0,allocated("_xyz")', m.Uint8(1)) self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(1)) self.assertEqual(m.DEALLOCATE('*'), m.Uint8(1)) self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(0)) """Test AND""" A, B = array([0, 0, 1, 1]), array([0, 1, 0, 1]) self._doThreeTestArray('_A=[0,0,1,1],_B=[0,1,0,1],_A && _B', m.AND(A, B), m.Uint8Array([0, 0, 0, 1])) """Test AND_NOT""" self._doThreeTestArray('_A AND_NOT _B', m.AND_NOT(A, B), m.Uint8Array([0, 0, 1, 0])) """Test ANINT""" self._doThreeTest('ANINT(2.783)', m.ANINT(2.783), m.Float32(3.0)) """Test ARG""" self._doTdiTest( 'execute("abs(arg(cmplx(3.0,4.0)) - .9272952) < .000001")', m.Uint8(1)) """Test ARGD""" self._doTdiTest( 'execute("abs(argd(cmplx(3.0,4.0)) - 53.1301) < .000001")', m.Uint8(1)) """Test arg_of""" self._doThreeTest( 'arg_of(pub->foo:B(42,43))', m.ARG_OF(m.Call('pub', 'foo', 42, 43).setRType(m.Uint8)), m.Int32(42)) self._doThreeTest( 'arg_of(pub->foo:P(42,43),1)', m.ARG_OF(m.Call('pub', 'foo', 42, 43).setRType(m.Pointer), 1), m.Int32(43)) self._doThreeTest('arg_of(1+3,1)', m.ARG_OF(m.ADD(1, 3), 1), m.Int32(3)) """Test Array""" self._doThreeTestArray('array(10)', m.ARRAY(10), m.Float32Array([0] * 10)) self._doThreeTestArray('array(10,0)', m.ARRAY(10, 0), m.Int32Array([0] * 10)) self._doThreeTestArray('array(10,0BU)', m.ARRAY(10, m.Uint8(0)), m.Uint8Array([0] * 10)) self._doThreeTestArray('zero(100)', m.ZERO(100), m.Float32Array([0] * 100)) self._doTdiTest('_l=list(*,1,2,3)', m.List([1, 2, 3])) self._doTdiTest('_l=list(_l,4,5)', m.List([1, 2, 3, 4, 5])) self._doTdiTest('_d=dict(*,1,"1",2,"2")', m.Dictionary([1, '1', 2, '2'])) self._doTdiTest('_d=dict(_d,3,"3")', m.Dictionary([1, '1', 2, '2', 3, "3"]))