def testPythonExternal(self):
     self.task = taskdict['python']['class']
     taskKwargs = {'pythonfile':os.path.join(testdir, 'tstPythonGlobal.py'),
                   'import':True, 'type':'python', 'notify':False}
     userargs = 'jkl mno:pqr'
     tm = TaskManager(self.task, 1, None, -1, taskid='T1', userargs=userargs, **taskKwargs)
     tm.returnHandler = self.returnHandler
     topic = Topic('onPlaybackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     self.clear_q()
     tm.start(topic, **runKwargs)
     try:
         tr = self.q.get(timeout=1)
     except Queue.Empty:
         raise AssertionError(_('Timed out waiting for return'))
     if tr.iserror is True:
         log(loglevel=xbmc.LOGERROR, msg=_('testPythonExternal returned with an error: %s') % tr.msg)
     if isAndroid:
         raise AssertionError(_('Cannot fully test pythonExternal on Android'))
     try:
         retArgs = sys.modules['__builtin__'].__dict__['testReturn']
     except KeyError:
         retArgs = sys.modules['builtins'].__dict__['testReturn']
     finally:
         try:
             sys.modules['__builtin__'].__dict__.pop('testReturn', None)
         except KeyError:
             sys.modules['builtins'].__dict__.pop('testReturn', None)
     if ' '.join(retArgs[0]) != userargs:
         raise AssertionError(_('Python external test failed'))
Ejemplo n.º 2
0
 def testBuiltin(self):
     start_debug = is_xbmc_debug()
     self.task = taskdict['builtin']['class']
     taskKwargs = {
         'builtin': 'ToggleDebug',
         'type': 'builtin',
         'notify': False
     }
     userargs = ''
     tm = TaskManager(self.task,
                      1,
                      None,
                      -1,
                      taskid='T1',
                      userargs=userargs,
                      **taskKwargs)
     topic = Topic('onPlayBackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     self.clear_q()
     tm.start(topic, **runKwargs)
     time.sleep(3)
     debug = is_xbmc_debug()
     tm.start(topic, **runKwargs)
     if debug == start_debug:
         raise AssertionError(_('Builtin test failed'))
 def testScriptShell(self):
     self.task = taskdict['script']['class']
     if sys.platform.startswith('win'):
         testfile = 'tstScript.bat'
     else:
         testfile = 'tstScript.sh'
     taskKwargs = {'scriptfile':'"%s"' % os.path.join(testdir, testfile),
                   'use_shell':True, 'type':'script', 'waitForCompletion': True, 'notify':False}
     userargs = 'abc def:ghi'
     self.task.validate(taskKwargs)
     tm = TaskManager(self.task, 1, None, -1, taskid='T1', userargs=userargs, **taskKwargs)
     tm.returnHandler = self.returnHandler
     topic = Topic('onPlaybackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     self.clear_q()
     tm.start(topic, **runKwargs)
     try:
         tr = self.q.get(timeout=2)
     except Queue.Empty:
         raise AssertionError(_('Timed out waiting for return'))
     else:
         if tr.iserror is True:
             log(loglevel=xbmc.LOGERROR, msg=_('testScriptShell returned with an error: %s') % tr.msg)
             raise AssertionError(_('Script with shell test failed'))
         else:
             retArgs = re.findall(r'Process returned data: \[(.+)\]', tr.msg)[0]
             if retArgs != userargs:
                 raise AssertionError(_('Script with shell test failed'))
 def testPythonExternal(self):
     self.task = taskdict['python']['class']
     taskKwargs = {'pythonfile':os.path.join(testdir, 'tstPythonGlobal.py'),
                   'import':True, 'type':'python', 'notify':False}
     userargs = 'jkl mno:pqr'
     tm = TaskManager(self.task, 1, None, -1, taskid='T1', userargs=userargs, **taskKwargs)
     tm.returnHandler = self.returnHandler
     topic = Topic('onPlaybackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     self.clear_q()
     tm.start(topic, **runKwargs)
     try:
         tr = self.q.get(timeout=1)
     except Queue.Empty:
         raise AssertionError(_('Timed out waiting for return'))
     if tr.iserror is True:
         log(loglevel=xbmc.LOGERROR, msg=_('testPythonExternal returned with an error: %s') % tr.msg)
     if isAndroid:
         raise AssertionError(_('Cannot fully test pythonExternal on Android'))
     try:
         retArgs = sys.modules['__builtin__'].__dict__['testReturn']
     except KeyError:
         retArgs = sys.modules['builtins'].__dict__['testReturn']
     finally:
         try:
             sys.modules['__builtin__'].__dict__.pop('testReturn', None)
         except KeyError:
             sys.modules['builtins'].__dict__.pop('testReturn', None)
     if ' '.join(retArgs[0]) != userargs:
         raise AssertionError(_('Python external test failed'))
 def testScriptShell(self):
     self.task = taskdict['script']['class']
     if sys.platform.startswith('win'):
         testfile = 'tstScript.bat'
     else:
         testfile = 'tstScript.sh'
     taskKwargs = {'scriptfile':'"%s"' % os.path.join(testdir, testfile),
                   'use_shell':True, 'type':'script', 'waitForCompletion': True, 'notify':False}
     userargs = 'abc def:ghi'
     self.task.validate(taskKwargs)
     tm = TaskManager(self.task, 1, None, -1, taskid='T1', userargs=userargs, **taskKwargs)
     tm.returnHandler = self.returnHandler
     topic = Topic('onPlaybackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     self.clear_q()
     tm.start(topic, **runKwargs)
     try:
         tr = self.q.get(timeout=2)
     except Queue.Empty:
         raise AssertionError(_('Timed out waiting for return'))
     else:
         if tr.iserror is True:
             log(loglevel=xbmc.LOGERROR, msg=_('testScriptShell returned with an error: %s') % tr.msg)
             raise AssertionError(_('Script with shell test failed'))
         else:
             retArgs = re.findall(r'Process returned data: \[(.+)\]', tr.msg)[0]
             if retArgs != userargs:
                 raise AssertionError(_('Script with shell test failed'))
 def testScriptNoShell(self):
     self.task = taskdict['script']['class']
     outfile = os.path.join(testdir, 'scriptoutput.txt')
     try:
         os.remove(outfile)
     except OSError:
         pass
     if sys.platform.startswith('win'):
         testfile = 'tstScript.bat'
     else:
         testfile = 'tstScript.sh'
     taskKwargs = {
         'scriptfile': '"%s"' % os.path.join(testdir, testfile),
         'use_shell': False,
         'type': 'script',
         'waitForCompletion': True,
         'notify': False
     }
     self.task.validate(taskKwargs)
     userargs = 'abc def:ghi'
     tm = TaskManager(self.task,
                      1,
                      None,
                      -1,
                      taskid='T1',
                      userargs=userargs,
                      **taskKwargs)
     tm.returnHandler = self.returnHandler
     topic = Topic('onPlaybackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     tm.start(topic, **runKwargs)
     try:
         tr = self.q.get(timeout=2)
     except Queue.Empty:
         raise AssertionError(_('Timed out waiting for return'))
     else:
         if tr.iserror is True:
             log(loglevel=xbmc.LOGERROR,
                 msg=_('testScriptNoShell returned with an error: %s') %
                 tr.msg)
         try:
             with open(outfile, 'r') as f:
                 retArgs = f.readline()
         except OSError:
             retArgs = ''
         try:
             os.remove(outfile)
         except OSError:
             pass
         if retArgs.strip('\n') != userargs:
             raise AssertionError(_('Script without shell test failed'))
 def testBuiltin(self):
     start_debug = is_xbmc_debug()
     self.task = taskdict['builtin']['class']
     taskKwargs = {'builtin':'ToggleDebug', 'type':'builtin', 'notify':False}
     userargs = ''
     tm = TaskManager(self.task,1, None, -1, taskid='T1', userargs=userargs, **taskKwargs)
     topic = Topic('onPlayBackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     tm.start(topic, **runKwargs)
     time.sleep(1)
     debug = is_xbmc_debug()
     tm.start(topic, **runKwargs)
     if debug == start_debug:
         raise AssertionError(_('Builtin test failed'))
Ejemplo n.º 8
0
 def testHttp(self):
     serverEnabled, serverPort, serverUser, serverPassword = getWebserverInfo(
     )
     if serverEnabled:
         self.task = taskdict['http']['class']
         taskKwargs = {
             'http': 'http://localhost:%s/jsonrpc' % str(serverPort),
             'user': serverUser,
             'pass': serverPassword,
             'type': 'http',
             'request-type': 'GET',
             'notify': False
         }
         userargs = '?request={"jsonrpc":%__"2.0"%_%__"id": 1%_%__"method":"Application.Setmute"%_%__"params":{"mute":"toggle"}}'
         tm = TaskManager(self.task,
                          1,
                          None,
                          -1,
                          taskid='T1',
                          userargs=userargs,
                          **taskKwargs)
         tm.returnHandler = self.returnHandler
         topic = Topic('onPlaybackStarted')
         runKwargs = events['onPlayBackStarted']['expArgs']
         self.clear_q()
         tm.start(topic, **runKwargs)
         try:
             tr = self.q.get(timeout=1)
         except Queue.Empty:
             raise Queue.Empty(_('testHttp never returned'))
         else:
             tm.start(topic, **runKwargs)  # Toggle Mute again
         if tr.iserror is True:
             log(loglevel=xbmc.LOGERROR,
                 msg=_('testHttp returned with an error: %s') % tr.msg)
         if '{"id":1,"jsonrpc":"2.0","result":' not in tr.msg:
             raise AssertionError(_('Http test failed'))
     else:
         raise AssertionError(
             'Http test cannot be run because webserver not enabled')
 def testScriptNoShell(self):
     self.task = taskdict['script']['class']
     outfile = os.path.join(testdir, 'scriptoutput.txt')
     try:
         os.remove(outfile)
     except OSError:
         pass
     if sys.platform.startswith('win'):
         testfile = 'tstScript.bat'
     else:
         testfile = 'tstScript.sh'
     taskKwargs = {'scriptfile':'"%s"' % os.path.join(testdir, testfile),
                   'use_shell':False, 'type':'script', 'waitForCompletion': True, 'notify':False}
     self.task.validate(taskKwargs)
     userargs = 'abc def:ghi'
     tm = TaskManager(self.task, 1, None, -1, taskid='T1', userargs=userargs, **taskKwargs)
     tm.returnHandler = self.returnHandler
     topic = Topic('onPlaybackStarted')
     runKwargs = events['onPlayBackStarted']['expArgs']
     tm.start(topic, **runKwargs)
     try:
         tr = self.q.get(timeout=2)
     except Queue.Empty:
         raise AssertionError(_('Timed out waiting for return'))
     else:
         if tr.iserror is True:
             log(loglevel=xbmc.LOGERROR, msg=_('testScriptNoShell returned with an error: %s') % tr.msg)
         try:
             with open(outfile, 'r') as f:
                 retArgs = f.readline()
         except OSError:
             retArgs = ''
         try:
             os.remove(outfile)
         except OSError:
             pass
         if retArgs.strip('\n') != userargs:
             raise AssertionError(_('Script without shell test failed'))
 def testHttp(self):
     serverEnabled, serverPort, serverUser, serverPassword = getWebserverInfo()
     if serverEnabled:
         self.task = taskdict['http']['class']
         taskKwargs = {'http':'http://localhost:%s/jsonrpc' % str(serverPort), 'user':serverUser, 'pass':serverPassword, 'type':'http', 'notify':False}
         userargs = '?request={"jsonrpc": "2.0", "id": 1, "method":"Application.Setmute", "params":{"mute":"toggle"}}'
         tm = TaskManager(self.task, 1, None, -1, taskid='T1', userargs=userargs, **taskKwargs)
         tm.returnHandler = self.returnHandler
         topic = Topic('onPlaybackStarted')
         runKwargs = events['onPlayBackStarted']['expArgs']
         tm.start(topic, **runKwargs)
         try:
             tr = self.q.get(timeout=1)
         except Queue.Empty:
             raise Queue.Empty(_('testHttp never returned'))
         else:
             tm.start(topic, **runKwargs)  # Toggle Mute again
         if tr.iserror is True:
             log(loglevel=xbmc.LOGERROR, msg=_('testHttp returned with an error: %s') % tr.msg)
         if tr.msg.startswith('{"id":1,"jsonrpc":"2.0","result":') is False:
             raise AssertionError(_('Http test failed'))
     else:
         raise AssertionError('Http test cannot be run because webserver not enabled')