コード例 #1
0
ファイル: _UnitTest.py プロジェクト: tfredian/mdsplus
 def _doExceptionTest(self,expr,exc):
     if Tests.debug: sys.stderr.write("TCL(%s) # expected exception: %s\n"%(expr,exc.__name__));
     try:
         tcl(expr,True,True,True)
     except Exception as e:
         self.assertEqual(e.__class__,exc)
         return
     self.fail("TCL: '%s' should have signaled an exception"%expr)
コード例 #2
0
    def treeCtx(self):
        from gc import collect
        from time import sleep

        def check(n):
            self.assertEqual(n, len(list(tree._TreeCtx.ctxs.items())[0][1]))

        self.assertEqual(tree._TreeCtx.ctxs,
                         {})  # neither tcl nor tdi has been called yet
        tcl('edit pytree/shot=%d/new' % self.shot)
        check(1)
        Data.execute('$EXPT')
        check(1)
        t = Tree()
        check(2)
        Data.execute('tcl("dir", _out)')
        check(2)
        del (t)
        collect(2)
        sleep(.1)
        check(1)
        Data.execute('_out')
        check(1)
        t = Tree('pytree', self.shot + 1, 'NEW')
        self.assertEqual(len(tree._TreeCtx.ctxs[tree._TreeCtx.local.tctx.ctx]),
                         1)
        self.assertEqual(len(tree._TreeCtx.ctxs[t.ctx.value]), 1)
        Data.execute('tcl("close")')
        self.assertEqual(len(tree._TreeCtx.ctxs[tree._TreeCtx.local.tctx.ctx]),
                         1)
        self.assertEqual(len(tree._TreeCtx.ctxs[t.ctx.value]), 1)
        self.assertEqual(str(t),
                         'Tree("PYTREE",%d,"Edit")' % (self.shot + 1, ))
        self.assertEqual(str(Data.execute('tcl("show db", _out);_out')), "\n")
        del (t)
        collect(2)
        sleep(.01)
        check(1)
        # tcl/tdi context remains until end of session
        t = Tree('pytree', self.shot + 1, 'NEW')
        self.assertEqual(len(tree._TreeCtx.ctxs[tree._TreeCtx.local.tctx.ctx]),
                         1)
        self.assertEqual(len(tree._TreeCtx.ctxs[t.ctx.value]), 1)
        del (t)
        collect(2)
        sleep(.01)
        check(1)
        self.cleanup()
コード例 #3
0
 def dclInterface(self):
     Tree('pytree',-1,'ReadOnly').createPulse(self.shot)
     self.assertEqual(dcl('help set verify',1,1,0)[1],None)
     self.assertEqual(tcl('help set tree',1,1,0)[1],None)
     self.assertEqual(ccl('help set xandq',1,1,0)[1],None)
     self.assertEqual(cts('help addcrate',1,1,0)[1],None)
     """ tcl commands """
     self._doTCLTest('type test','test\n')
     self._doTCLTest('close/all')
     self._doTCLTest('show db','\n')
     self._doTCLTest('set tree pytree/shot=%d'%(self.shot,))
     self._doTCLTest('show db','000  PYTREE        shot: %d [\\PYTREE::TOP]   \n\n'%self.shot)
     self._doTCLTest('edit PYTREE/shot=%d'%(self.shot,))
     self._doTCLTest('add node TCL_NUM/usage=numeric')
     self._doTCLTest('add node TCL_PY_DEV/model=TESTDEVICE')
     self._doTCLTest('do TESTDEVICE:TASK_TEST')
     self._doExceptionTest('do TESTDEVICE:TASK_ERROR',Exc.DevUNKOWN_STATE)
     if not sys.platform.startswith('win'): # Windows does not support timeout yet
         self._doExceptionTest('do TESTDEVICE:TASK_TIMEOUT',Exc.TdiTIMEOUT)
     self._doExceptionTest('close',Exc.TreeWRITEFIRST)
     self._doTCLTest('write')
     self._doTCLTest('close')
     self._doTCLTest('show db','\n')
     """ context """
     self._doTCLTest('set tree pytree')
     pytree = Tree()
     self.assertEqual(str(pytree),'Tree("PYTREE",-1,"Normal")')
     self._doTCLTest('close pytree')
     self.assertEqual(str(pytree),'Tree("PYTREE",-1,"Closed")')
     """ tcl exceptions """
     self._doExceptionTest('close',Exc.TreeNOT_OPEN)
     self._doExceptionTest('dispatch/command/server=xXxXxXx type test',Exc.ServerPATH_DOWN)
     self._doExceptionTest('dispatch/command/server type test',Exc.MdsdclIVVERB)
コード例 #4
0
    def _doTCLTest(self,
                   expr,
                   out=None,
                   err=None,
                   re=False,
                   verify=False,
                   quiet=False):
        def checkre(pattern, string):
            if pattern is None:
                self.assertEqual(string is None, True)
            else:
                self.assertEqual(string is None, False)
                self.assertEqual(
                    match(pattern, str(string)) is None, False,
                    '"%s"\nnot matched by\n"%s"' % (string, pattern))

        if not quiet:
            sys.stderr.write("TCL> %s\n" % (expr, ))
        outo, erro = tcl(expr, True, True, True)
        if verify:
            ver, erro = erro.split('\n', 2)
            self.assertEqual(ver.endswith("%s" % expr), True)
            if len(erro) == 0: erro = None
        if not re:
            self.assertEqual(outo, out)
            self.assertEqual(erro, err)
        else:
            checkre(out, outo)
            checkre(err, erro)
コード例 #5
0
 def _doTCLTest(self,expr,out=None,err=None,re=False):
     def checkre(pattern,string):
         if pattern is None:
             self.assertEqual(string is None,True)
         else:
             self.assertEqual(string is None,False)
             self.assertEqual(match(pattern,str(string)) is None,False,'"%s"\nnot matched by\n"%s"'%(string,pattern))
     if dclTests.debug: sys.stderr.write("TCL(%s)\n"%(expr,));
     outerr = tcl(expr,True,True,True)
     if not re:
         self.assertEqual(outerr,(out,err))
     else:
         checkre(out,outerr[0])
         checkre(err,outerr[1])
コード例 #6
0
 def interface(self):
     with Tree(self.tree,self.shot,'new') as pytree:
         Device.PyDevice('TestDevice').Add(pytree,'TESTDEVICE_I')
         Device.PyDevice('TestDevice').Add(pytree,'TESTDEVICE_S')
         pytree.write()
     pytree.normal()
     self.assertEqual(pytree.TESTDEVICE_S.check_source(),"No source stored in record.")
     pytree.TESTDEVICE_S._update_source()
     self.assertEqual(pytree.TESTDEVICE_S.check_source(),"")
     pytree.close() # needed for windows to release file lock
     self.assertEqual(dcl('help set verify',1,1,0)[1],None)
     self.assertEqual(tcl('help set tree',1,1,0)[1],None)
     self.assertEqual(ccl('help set xandq',1,1,0)[1],None)
     self.assertEqual(cts('help addcrate',1,1,0)[1],None)
     """ tcl commands """
     self._doTCLTest('type test','test\n')
     if self.inThread: Tree.usePrivateCtx(1)
     self._doTCLTest('close/all')
     self._doTCLTest('show db','\n')
     self._doTCLTest('set tree pytree/shot=%d'%(self.shot,))
     self._doTCLTest('show db','000  PYTREE        shot: %d [\\PYTREE::TOP]   \n\n'%self.shot)
     self._doTCLTest('edit PYTREE/shot=%d'%(self.shot,))
     self._doTCLTest('add node TCL_NUM/usage=numeric')
     self._doTCLTest('add node TCL_PY_DEV/model=TESTDEVICE')
     self._doTCLTest('do TESTDEVICE_I:TASK_TEST')
     self._doTCLTest('do TESTDEVICE_S:TASK_TEST')
     self._doTCLTest('do TESTDEVICE_S:ACTIONSERVER:MANUAL')
     self._doExceptionTest('do TESTDEVICE_I:TASK_ERROR1',Exc.DevUNKOWN_STATE) # w/o timeout
     self._doExceptionTest('do TESTDEVICE_S:TASK_ERROR1',Exc.DevUNKOWN_STATE) # w/o timeout
     self._doExceptionTest('do TESTDEVICE_I:TASK_ERROR2',Exc.DevUNKOWN_STATE) # w/  timeout
     self._doExceptionTest('do TESTDEVICE_S:TASK_ERROR2',Exc.DevUNKOWN_STATE) # w/  timeout
     self._doExceptionTest('close',Exc.TreeWRITEFIRST)
     self._doTCLTest('write')
     self._doTCLTest('close')
     self._doTCLTest('show db','\n')
     """ context """
     self._doTCLTest('set tree pytree/shot=%d'%(self.shot,))
     pytree = Tree()
     self.assertEqual(str(pytree),'Tree("PYTREE",%d,"Normal")'%self.shot)
     self._doTCLTest('close pytree/shot=%d'%(self.shot,))
     self.assertEqual(str(pytree),'Tree("?",?,"Closed")')
     if self.inThread: Tree.usePrivateCtx(0)
     """ tcl exceptions """
     self._doExceptionTest('close',Exc.TreeNOT_OPEN)
     self._doExceptionTest('dispatch/command/server=xXxXxXx type test',Exc.ServerPATH_DOWN)
     self._doExceptionTest('dispatch/command/server type test',Exc.MdsdclIVVERB)
コード例 #7
0
 def test():
     Tree('pytree', -1, 'ReadOnly').createPulse(self.shot)
     self.assertEqual(dcl('help set verify', 1, 1, 0)[1], None)
     self.assertEqual(tcl('help set tree', 1, 1, 0)[1], None)
     self.assertEqual(ccl('help set xandq', 1, 1, 0)[1], None)
     self.assertEqual(cts('help addcrate', 1, 1, 0)[1], None)
     """ tcl commands """
     self._doTCLTest('type test', 'test\n')
     if self.inThread: Tree.usePrivateCtx(1)
     self._doTCLTest('close/all')
     self._doTCLTest('show db', '\n')
     self._doTCLTest('set tree pytree/shot=%d' % (self.shot, ))
     self._doTCLTest(
         'show db',
         '000  PYTREE        shot: %d [\\PYTREE::TOP]   \n\n' %
         self.shot)
     self._doTCLTest('edit PYTREE/shot=%d' % (self.shot, ))
     self._doTCLTest('add node TCL_NUM/usage=numeric')
     self._doTCLTest('add node TCL_PY_DEV/model=TESTDEVICE')
     self._doTCLTest('do TESTDEVICE:TASK_TEST')
     self._doExceptionTest('do TESTDEVICE:TASK_ERROR1',
                           Exc.DevUNKOWN_STATE)
     self._doExceptionTest('do TESTDEVICE:TASK_ERROR2',
                           Exc.DevUNKOWN_STATE)
     self._doExceptionTest('close', Exc.TreeWRITEFIRST)
     self._doTCLTest('write')
     self._doTCLTest('close')
     self._doTCLTest('show db', '\n')
     """ context """
     self._doTCLTest('set tree pytree')
     pytree = Tree()
     self.assertEqual(str(pytree), 'Tree("PYTREE",-1,"Normal")')
     self._doTCLTest('close pytree')
     self.assertEqual(str(pytree), 'Tree("PYTREE",-1,"Closed")')
     if self.inThread: Tree.usePrivateCtx(0)
     """ tcl exceptions """
     self._doExceptionTest('close', Exc.TreeNOT_OPEN)
     self._doExceptionTest('dispatch/command/server=xXxXxXx type test',
                           Exc.ServerPATH_DOWN)
     self._doExceptionTest('dispatch/command/server type test',
                           Exc.MdsdclIVVERB)
コード例 #8
0
 def testDispatchCommand(mdsip, command, stdout=None, stderr=None):
     self.assertEqual(
         tcl(
             'dispatch/command/nowait/server=%s %s' %
             (mdsip, command), 1, 1, 1), (None, None))