Пример #1
0
 def testSetHandler(self):
     api = iApi()
     assert len(api._apiHandlers) == 0
     NS = "namespace"
     def myHandler(): pass
     api.setHandler(NS, myHandler)
     assert NS in api._apiHandlers
     assert len(api._apiHandlers) == 1
Пример #2
0
 def testGetHandlerWhenNoneSet(self):
     api = iApi()
     assert len(api._apiHandlers) == 0
     NS = "namespace"
     try:
         api.getHandler(NS)
     except UnsupportedApiError, e:
         assert e.ns() == NS
Пример #3
0
 def testSetInvalidTransportDataReceiveListener(self):
     api = iApi()
     myListener = object()
     try:
         api.transportDataReceiveListener = myListener
     except ApiParamError, e:
         assert e.item == myListener
         assert iIpcTransportDataReceiveListener in e.allowedTypes
Пример #4
0
 def testGethandler(self):
     api = iApi()
     assert len(api._apiHandlers) == 0
     NS = "namespace"
     def myHandler(): pass
     api.setHandler(NS, myHandler)
     assert len(api._apiHandlers) == 1
     handler = api.getHandler(NS)
     assert handler == myHandler
Пример #5
0
 def testInvalidIpc(self):
     ipc = object()
     api = iApi()
     try:
         api.ipc = ipc
     except ApiParamError, e:
         assert e.item == ipc
         assert iIpcTransport in e.allowedTypes
         assert len(e.allowedTypes) == 1
Пример #6
0
 def testSetInvalidHandler(self):
     api = iApi()
     assert len(api._apiHandlers) == 0
     def myHandler(): pass
     try:
         api.setHandler(None, myHandler)
     except ApiParamError, e:
         assert e.item == None
         assert basestring in e.allowedTypes
         assert len(e.allowedTypes) == 1
Пример #7
0
 def testGetCatchallHandlerAsFallback(self):
     api = iApi()
     assert len(api._apiHandlers) == 0
     NS = iApi.CATCHALL
     def myHandler(): pass
     api.setHandler(NS, myHandler)
     assert len(api._apiHandlers) == 1
     dNS = "some.namespace"
     handler = api.getHandler(dNS)
     assert handler == myHandler
Пример #8
0
 def testSyncFuncRaisesNoResponseRequired(self):
     api = iApi(ipc=self.myIpc)
     tId = 1
     def func(*args, **kwargs):
         raise NoResponseRequired(tId)
     sync = True
     try:
         api._handleStandardCall(tId, sync, func)
     except NoResponseRequired, _e:
         assert True
Пример #9
0
 def testGetHandlerNsIsNone(self):
     api = iApi()
     assert len(api._apiHandlers) == 0
     NS = None
     def myHandler(): pass
     try:
         api.getHandler(NS)
     except ApiParamError, e:
         assert e.item == NS
         assert basestring in e.allowedTypes
         assert len(e.allowedTypes) == 1
Пример #10
0
 def testGetHandlerWithCatchallHandlerAsFallback(self):
     api = iApi()
     assert len(api._apiHandlers) == 0
     NS = iApi.CATCHALL
     def myHandler(): pass
     def myOtherHandler(): pass
     api.setHandler(NS, myHandler)
     assert len(api._apiHandlers) == 1
     eNS = "hello.world!"
     api.setHandler(eNS, myOtherHandler)
     assert len(api._apiHandlers) == 2
     handler = api.getHandler(eNS)
     assert handler == myOtherHandler
Пример #11
0
 def testSyncFuncRaisesCustomException(self):
     api = iApi(ipc=self.myIpc)
     eResult = CustomException(123)
     def func(*args, **kwargs):
         self.funcData["args"] = args
         self.funcData["kwargs"] = kwargs
         raise eResult
     tId = 1
     sync = True
     try:
         api._handleStandardCall(tId, sync, func, *self.args, **self.kwargs)
     except CustomException, e:
         assert e == eResult
Пример #12
0
 def testSyncFuncReturnsCustomData(self):
     api = iApi(ipc=self.myIpc)
     eResult = 123
     def func(*args, **kwargs):
         self.funcData["args"] = args
         self.funcData["kwargs"] = kwargs
         return eResult
     tId = 1
     sync = True
     r = api._handleStandardCall(tId, sync, func, *self.args, **self.kwargs)
     assert isinstance(r, iApiTransportResponse)
     assert r.response() == eResult
     assert self.funcData["args"] == self.args
     assert self.funcData["kwargs"] == self.kwargs
Пример #13
0
 def _checkNChunks(self, count):
     api = iApi(ipc=self.myIpc)
     eResult = CustomException(123)
     def func(*args, **kwargs):
         self.funcData["args"] = args
         self.funcData["kwargs"] = kwargs
         raise eResult
     tId = 123
     chunks = []
     for i in range(1, count + 1):
         chunks.append([i for i in range(1, i + 1)])
     combinerMethod = ("hello", "world!")
     try:
         api._returnChunks(tId, chunks, combinerMethod, lambda x, index: MyResult(x[index], index))
     except NoResponseRequired, _e:
         assert True
Пример #14
0
 def testAsyncFuncReturnsCustomData(self):
     api = iApi(ipc=self.myIpc)
     eResult = 123
     def func(*args, **kwargs):
         self.funcData["args"] = args
         self.funcData["kwargs"] = kwargs
         return eResult
     tId = 1
     sync = False
     api._handleStandardCall(tId, sync, func, *self.args, **self.kwargs)
     assert self.myIpc.dataSentLock.acquire(timeout=1)
     assert len(self.myIpc.dataSent) == 1
     assert self.myIpc.dataSent[0][0] == tId
     d = self.myIpc.dataSent[0][1]
     assert isinstance(d, ApiTransportResponse)
     assert d.response() == eResult
     assert self.funcData["args"] == self.args
     assert self.funcData["kwargs"] == self.kwargs
Пример #15
0
 def testSetTransportStateChangeListener(self):
     api = iApi()
     myListener = MyTransportListener()
     api.transportStateChangeListener = myListener
     assert api.transportStateChangeListener == myListener
Пример #16
0
 def testSetTransportDataReceiveListener(self):
     api = iApi()
     myListener = MyTransportListener()
     api.transportDataReceiveListener = myListener
     assert api.transportDataReceiveListener == myListener
Пример #17
0
 def testValidIpc(self):
     ipc = MyTransport()
     api = iApi()
     api.ipc = ipc
     assert api.ipc == ipc
Пример #18
0
 def setUp(self):
     self.myIpc = MyTransport()
     self.args = (345, "hello", "world!")
     self.kwargs = {"i.am":"an.arg"}
     self.funcData = {}
     self.myApi = iApi(ipc=self.myIpc)
Пример #19
0
 def testGetEventsToHandle(self, api=iApi()):
     api = iApi()
     events = api.getEventsToHandle()
     assert isinstance(events, list)
     assert len(events) == 0