def processSrc(self, src): """ processes the src and sets the values of display, icon and ok attributes """ if src is None: self.display, self.icon, self.ok = "", Qt.QIcon(), True return src = str(src).strip() # empty if src == "": self.display, self.icon, self.ok = "", Qt.QIcon(), True return # for taurus attributes if taurus.isValidName(src, etypes=[TaurusElementType.Attribute]): self.display, self.icon, self.ok = ( src, Qt.QIcon("logos:taurus.png"), True, ) return # if not caught before, it is unsupported self.display, self.icon, self.ok = ( src, Qt.QIcon.fromTheme("dialog-warning"), False, )
def isValid(self, name=None, expected=True, elementType=None, strict=True, skip=False, skipmsg='Test explicitly disabled'): '''Helper method to test validity or invalidity of taurus URIs''' if skip: self.skipTest(skipmsg) if elementType is None: elementName = '<any>' else: elementName = TaurusElementType.whatis(elementType) elementType = [elementType] manager = taurus.Manager() scheme = manager.getScheme(name) supportedSchemes = manager.getPlugins().keys() if scheme not in supportedSchemes: self.skipTest('"%s" scheme not supported' % scheme) returned = taurus.isValidName(name, etypes=elementType, strict=strict) msg = ( 'isValidName returns %s (expected %s for name=%s and etype=%s)' % (returned, expected, name, elementName)) self.assertEqual(returned, expected, msg)
def processSrc(self, src): '''returns src,display,icon,ok''' src = unicode(src) # empty if src == '': return '', '', Qt.QIcon(), True # for formulas if src.startswith('='): #@todo: evaluate/validate the expression return src, src[1:].strip(), Qt.QIcon.fromTheme( 'accessories-calculator'), True # for attributes if isValidName(src, etypes=[TaurusElementType.Attribute]): return src, src, Qt.QIcon.fromTheme('network-server'), True # If nothing matches... return src, src, Qt.QIcon.fromTheme('dialog-warning'), False
def isValid(self, name=None, expected=True, elementType=None, strict=True, skip=False, skipmsg='Test explicitly disabled'): '''Helper method to test validity or invalidity of taurus URIs''' if skip: self.skipTest(skipmsg) if elementType is None: elementName = '<any>' else: elementName = TaurusElementType.whatis(elementType) elementType = [elementType] manager = taurus.Manager() scheme = manager.getScheme(name) supportedSchemes = manager.getPlugins().keys() if scheme not in supportedSchemes: self.skipTest('"%s" scheme not supported' % scheme) returned = taurus.isValidName(name, etypes=elementType, strict=strict) msg = ('isValidName returns %s (expected %s for name=%s and etype=%s)' % (returned, expected, name, elementName)) self.assertEqual(returned, expected, msg)
def isValid(self, name, matchLevel=None, strict=None): '''reimplemented from :class:`TaurusAttributeNameValidator` to do extra check on references validity (recursive) ''' # Standard implementation if matchLevel is not None: groups = self._isValidAtLevel(name, matchLevel=matchLevel) else: groups = self.getUriGroups(name, strict=strict) if groups is None: return False # now check the references for ref in groups['_evalrefs']: if not isValidName(ref, etypes=(TaurusElementType.Attribute,), strict=strict): debug('"%s" is invalid because ref "%s" is not a ' + 'valid attribute', name, ref) return False return True
def isValid(self, name, matchLevel=None, strict=None): '''reimplemented from :class:`TaurusAttributeNameValidator` to do extra check on references validity (recursive) ''' # Standard implementation if matchLevel is not None: groups = self._isValidAtLevel(name, matchLevel=matchLevel) else: groups = self.getUriGroups(name, strict=strict) if groups is None: return False # now check the references for ref in groups['_evalrefs']: if not isValidName(ref, etypes=(TaurusElementType.Attribute, ), strict=strict): debug( '"%s" is invalid because ref "%s" is not a ' + 'valid attribute', name, ref) return False return True
def test_unsupported(self): '''Testing that an unsupported scheme validates as False''' returned = taurus.isValidName('_unsupported_://foo') msg = ('Validating unsupported schemes must return False (got %s)' % returned) self.assertFalse(returned, msg)