def testMaskedMethod(self): # Check masked attributes: for ns in [{"b":1}, {"aa":2}, {"a":3}]: try: NamespaceWrapperController.create(ns, TestingNamespaceWrapper, waitOnEvent=False) except MaskedAttributeError, _e: assert True else: assert False
def testMaskedMethod(self): # Check masked attributes: for ns in [{"b": 1}, {"aa": 2}, {"a": 3}]: try: NamespaceWrapperController.create(ns, TestingNamespaceWrapper, waitOnEvent=False) except MaskedAttributeError, _e: assert True else: assert False
def testInsertApi(self, method=None, eResult="test-ccc", waitOnEvent=False): if method==None: def ccc(): print eResult return eResult method = ccc self.ns = {"cc":method} self.nsc = NamespaceWrapperController.create(self.ns, TestingNamespaceWrapper, waitOnEvent=waitOnEvent) wrapper = self.nsc.getWrapper() # Positive case: result = wrapper.cc() assert result==eResult # Insert duplicate apis: eResultDD = "test-dd" eResultEE = "test-ee" def dd(): msg = eResultDD print msg return msg def ee(): msg = eResultEE print msg return msg newApi = {"dd":dd, "ee":ee, "cc":method} try: self.nsc.insertApi(newApi) except DuplicateApiError, e: names = e.names() assert len(names)==1 assert "cc" in names
def doLoad(): for what in whats: result = None apid = ApiHelper.loadApiType(what, apids=self._comparitor.apids, root=self._projectRoot) try: api = apid.api() NS = apid.ns() alreadyLoadedInSameNamespace = True found = True try: if NS in self._namespaceWrapperControllers.keys(): raise DuplicateApiNamespaceError([(NS, apid.apiType())]) if NS in self._apiInstances.keys(): raise DuplicateApiNamespaceError([(NS, apid.apiType())]) if NS in self._namespace["__builtins__"].keys(): raise DuplicateApiNamespaceError([(NS, apid.apiType())]) except DuplicateApiNamespaceError, _e: # Duplicate found, however is the apid the same? alreadyLoadedInSameNamespace = False for apid_ in self._comparitor.apids: if apid==apid_: # Yes, no error, do nothing - module already loaded! alreadyLoadedInSameNamespace = True break if alreadyLoadedInSameNamespace==False: # Another api is using the same namespace. if mode==-1: # Should auto-blat with new namespace! found = True elif mode==2: # Api already loaded with same namespace. found = False elif mode==0: # Should auto-blat! self._freshenNamespace(api, apid) self._debugger.debug("API: Freshened '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what}) continue elif mode==1: # Determine new methods and inject them using the NamespaceWrapperController: self._updateNamespace(api, apid) self._debugger.debug("API: Updated '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what}) continue else: raise else: # Same api is using the same namespace. found = False if found==True: theApi = api(self._control, self._display, self._srcPath, self._debugger) self._apiInstances[NS] = theApi self._namespaceWrapperControllers[NS] = NamespaceWrapperController.create(apid, theApi.namespace(), waitOnEvent=self._getWaitOnEvent, debugger=self._debugger) wrapper = self._namespaceWrapperControllers[NS].getWrapper() self._comparitor.apids.append(apid) self._namespace["__builtins__"][NS] = wrapper self._debugger.debug("API: Loaded '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what}) else: self._debugger.debug("API: Already loaded '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what}) except Exception, result: raise
def testUnmaskedMethod(self, waitOnEvent=False, method=None, eResult="test-bbb", timeout=None): if method==None: def bbb(): print "bbb" return eResult method = bbb self.ns = {"bb":method} self.nsc = NamespaceWrapperController.create(self.ns, TestingNamespaceWrapper, waitOnEvent=waitOnEvent) self.nsw = self.nsc.getWrapper() if waitOnEvent==True: threading.Timer(timeout, self.nsc.run).start() result = self.nsw.bb() print "result: ", result assert result==eResult
def testInsertApi(self, method=None, eResult="test-ccc", waitOnEvent=False): if method == None: def ccc(): print eResult return eResult method = ccc self.ns = {"cc": method} self.nsc = NamespaceWrapperController.create(self.ns, TestingNamespaceWrapper, waitOnEvent=waitOnEvent) wrapper = self.nsc.getWrapper() # Positive case: result = wrapper.cc() assert result == eResult # Insert duplicate apis: eResultDD = "test-dd" eResultEE = "test-ee" def dd(): msg = eResultDD print msg return msg def ee(): msg = eResultEE print msg return msg newApi = {"dd": dd, "ee": ee, "cc": method} try: self.nsc.insertApi(newApi) except DuplicateApiError, e: names = e.names() assert len(names) == 1 assert "cc" in names
def testUnmaskedMethod(self, waitOnEvent=False, method=None, eResult="test-bbb", timeout=None): if method == None: def bbb(): print "bbb" return eResult method = bbb self.ns = {"bb": method} self.nsc = NamespaceWrapperController.create(self.ns, TestingNamespaceWrapper, waitOnEvent=waitOnEvent) self.nsw = self.nsc.getWrapper() if waitOnEvent == True: threading.Timer(timeout, self.nsc.run).start() result = self.nsw.bb() print "result: ", result assert result == eResult