How to use getNamespacePrefix method in Airtest

Best Python code snippet using Airtest

TestXMLToken.py

Source:TestXMLToken.py Github

copy

Full Screen

...295 token.addNamespace( "http://test8.org/", "test8")296 token.addNamespace( "http://test9.org/", "test9")297 self.assert_( token.getNamespacesLength() == 9 )298 self.assert_( token.getNamespaceIndex( "http://test1.org/") == 0 )299 self.assert_( ( "test2" != token.getNamespacePrefix(1) ) == False )300 self.assert_( ( "test1" != token.getNamespacePrefix( "http://test1.org/") ) == False )301 self.assert_( ( "http://test2.org/" != token.getNamespaceURI(1) ) == False )302 self.assert_( ( "http://test2.org/" != token.getNamespaceURI( "test2") ) == False )303 self.assert_( token.getNamespaceIndex( "http://test1.org/") == 0 )304 self.assert_( token.getNamespaceIndex( "http://test2.org/") == 1 )305 self.assert_( token.getNamespaceIndex( "http://test5.org/") == 4 )306 self.assert_( token.getNamespaceIndex( "http://test9.org/") == 8 )307 self.assert_( token.getNamespaceIndex( "http://testX.org/") == -1 )308 self.assert_( token.hasNamespaceURI( "http://test1.org/") != False )309 self.assert_( token.hasNamespaceURI( "http://test2.org/") != False )310 self.assert_( token.hasNamespaceURI( "http://test5.org/") != False )311 self.assert_( token.hasNamespaceURI( "http://test9.org/") != False )312 self.assert_( token.hasNamespaceURI( "http://testX.org/") == False )313 self.assert_( token.getNamespaceIndexByPrefix( "test1") == 0 )314 self.assert_( token.getNamespaceIndexByPrefix( "test5") == 4 )315 self.assert_( token.getNamespaceIndexByPrefix( "test9") == 8 )316 self.assert_( token.getNamespaceIndexByPrefix( "testX") == -1 )317 self.assert_( token.hasNamespacePrefix( "test1") != False )318 self.assert_( token.hasNamespacePrefix( "test5") != False )319 self.assert_( token.hasNamespacePrefix( "test9") != False )320 self.assert_( token.hasNamespacePrefix( "testX") == False )321 self.assert_( token.hasNamespaceNS( "http://test1.org/", "test1") != False )322 self.assert_( token.hasNamespaceNS( "http://test5.org/", "test5") != False )323 self.assert_( token.hasNamespaceNS( "http://test9.org/", "test9") != False )324 self.assert_( token.hasNamespaceNS( "http://testX.org/", "testX") == False )325 _dummyList = [ token ]; _dummyList[:] = []; del _dummyList326 _dummyList = [ triple ]; _dummyList[:] = []; del _dummyList327 _dummyList = [ attr ]; _dummyList[:] = []; del _dummyList328 pass 329 def test_XMLToken_namespace_remove(self):330 triple = libsbml.XMLTriple("test","","")331 attr = libsbml.XMLAttributes()332 token = libsbml.XMLToken(triple,attr)333 token.addNamespace( "http://test1.org/", "test1")334 token.addNamespace( "http://test2.org/", "test2")335 token.addNamespace( "http://test3.org/", "test3")336 token.addNamespace( "http://test4.org/", "test4")337 token.addNamespace( "http://test5.org/", "test5")338 self.assert_( token.getNamespacesLength() == 5 )339 token.removeNamespace(4)340 self.assert_( token.getNamespacesLength() == 4 )341 token.removeNamespace(3)342 self.assert_( token.getNamespacesLength() == 3 )343 token.removeNamespace(2)344 self.assert_( token.getNamespacesLength() == 2 )345 token.removeNamespace(1)346 self.assert_( token.getNamespacesLength() == 1 )347 token.removeNamespace(0)348 self.assert_( token.getNamespacesLength() == 0 )349 token.addNamespace( "http://test1.org/", "test1")350 token.addNamespace( "http://test2.org/", "test2")351 token.addNamespace( "http://test3.org/", "test3")352 token.addNamespace( "http://test4.org/", "test4")353 token.addNamespace( "http://test5.org/", "test5")354 self.assert_( token.getNamespacesLength() == 5 )355 token.removeNamespace(0)356 self.assert_( token.getNamespacesLength() == 4 )357 token.removeNamespace(0)358 self.assert_( token.getNamespacesLength() == 3 )359 token.removeNamespace(0)360 self.assert_( token.getNamespacesLength() == 2 )361 token.removeNamespace(0)362 self.assert_( token.getNamespacesLength() == 1 )363 token.removeNamespace(0)364 self.assert_( token.getNamespacesLength() == 0 )365 _dummyList = [ token ]; _dummyList[:] = []; del _dummyList366 _dummyList = [ triple ]; _dummyList[:] = []; del _dummyList367 _dummyList = [ attr ]; _dummyList[:] = []; del _dummyList368 pass 369 def test_XMLToken_namespace_remove_by_prefix(self):370 triple = libsbml.XMLTriple("test","","")371 attr = libsbml.XMLAttributes()372 token = libsbml.XMLToken(triple,attr)373 token.addNamespace( "http://test1.org/", "test1")374 token.addNamespace( "http://test2.org/", "test2")375 token.addNamespace( "http://test3.org/", "test3")376 token.addNamespace( "http://test4.org/", "test4")377 token.addNamespace( "http://test5.org/", "test5")378 self.assert_( token.getNamespacesLength() == 5 )379 token.removeNamespace( "test1")380 self.assert_( token.getNamespacesLength() == 4 )381 token.removeNamespace( "test2")382 self.assert_( token.getNamespacesLength() == 3 )383 token.removeNamespace( "test3")384 self.assert_( token.getNamespacesLength() == 2 )385 token.removeNamespace( "test4")386 self.assert_( token.getNamespacesLength() == 1 )387 token.removeNamespace( "test5")388 self.assert_( token.getNamespacesLength() == 0 )389 token.addNamespace( "http://test1.org/", "test1")390 token.addNamespace( "http://test2.org/", "test2")391 token.addNamespace( "http://test3.org/", "test3")392 token.addNamespace( "http://test4.org/", "test4")393 token.addNamespace( "http://test5.org/", "test5")394 self.assert_( token.getNamespacesLength() == 5 )395 token.removeNamespace( "test5")396 self.assert_( token.getNamespacesLength() == 4 )397 token.removeNamespace( "test4")398 self.assert_( token.getNamespacesLength() == 3 )399 token.removeNamespace( "test3")400 self.assert_( token.getNamespacesLength() == 2 )401 token.removeNamespace( "test2")402 self.assert_( token.getNamespacesLength() == 1 )403 token.removeNamespace( "test1")404 self.assert_( token.getNamespacesLength() == 0 )405 token.addNamespace( "http://test1.org/", "test1")406 token.addNamespace( "http://test2.org/", "test2")407 token.addNamespace( "http://test3.org/", "test3")408 token.addNamespace( "http://test4.org/", "test4")409 token.addNamespace( "http://test5.org/", "test5")410 self.assert_( token.getNamespacesLength() == 5 )411 token.removeNamespace( "test3")412 self.assert_( token.getNamespacesLength() == 4 )413 token.removeNamespace( "test1")414 self.assert_( token.getNamespacesLength() == 3 )415 token.removeNamespace( "test4")416 self.assert_( token.getNamespacesLength() == 2 )417 token.removeNamespace( "test5")418 self.assert_( token.getNamespacesLength() == 1 )419 token.removeNamespace( "test2")420 self.assert_( token.getNamespacesLength() == 0 )421 _dummyList = [ token ]; _dummyList[:] = []; del _dummyList422 _dummyList = [ triple ]; _dummyList[:] = []; del _dummyList423 _dummyList = [ attr ]; _dummyList[:] = []; del _dummyList424 pass 425 def test_XMLToken_namespace_set_clear(self):426 triple = libsbml.XMLTriple("test","","")427 attr = libsbml.XMLAttributes()428 token = libsbml.XMLToken(triple,attr)429 ns = libsbml.XMLNamespaces()430 self.assert_( token.getNamespacesLength() == 0 )431 self.assert_( token.isNamespacesEmpty() == True )432 ns.add( "http://test1.org/", "test1")433 ns.add( "http://test2.org/", "test2")434 ns.add( "http://test3.org/", "test3")435 ns.add( "http://test4.org/", "test4")436 ns.add( "http://test5.org/", "test5")437 token.setNamespaces(ns)438 self.assert_( token.getNamespacesLength() == 5 )439 self.assert_( token.isNamespacesEmpty() == False )440 self.assert_( ( "test1" != token.getNamespacePrefix(0) ) == False )441 self.assert_( ( "test2" != token.getNamespacePrefix(1) ) == False )442 self.assert_( ( "test3" != token.getNamespacePrefix(2) ) == False )443 self.assert_( ( "test4" != token.getNamespacePrefix(3) ) == False )444 self.assert_( ( "test5" != token.getNamespacePrefix(4) ) == False )445 self.assert_( ( "http://test1.org/" != token.getNamespaceURI(0) ) == False )446 self.assert_( ( "http://test2.org/" != token.getNamespaceURI(1) ) == False )447 self.assert_( ( "http://test3.org/" != token.getNamespaceURI(2) ) == False )448 self.assert_( ( "http://test4.org/" != token.getNamespaceURI(3) ) == False )449 self.assert_( ( "http://test5.org/" != token.getNamespaceURI(4) ) == False )450 token.clearNamespaces()451 self.assert_( token.getNamespacesLength() == 0 )452 _dummyList = [ ns ]; _dummyList[:] = []; del _dummyList453 _dummyList = [ token ]; _dummyList[:] = []; del _dummyList454 _dummyList = [ triple ]; _dummyList[:] = []; del _dummyList455 _dummyList = [ attr ]; _dummyList[:] = []; del _dummyList456 pass 457def suite():458 suite = unittest.TestSuite()...

Full Screen

Full Screen

populate_ext_sqls.py

Source:populate_ext_sqls.py Github

copy

Full Screen

...21 if prefix in self._nsUriDict:22 return self._nsUriDict[prefix][-1]23 else:24 return None25 def getNamespacePrefix(self, uri):26 if uri in self._prefixDict:27 return self._prefixDict[uri][-1]28 else:29 return None30 31 def _StartElementHandler(self, name, attr):32 # name = namespace_uri + ' ' + tagname33 tag = Tag(self, name)34 attrs = map(lambda x:Attribute(self,tag,x), attr.items())35 attrs = map(lambda x:(x.getName(),x), attrs)36 attrs = dict(attrs)37 ##38 ## Xinclude support39 ##40 if tag.getName() == 'include' and \41 tag.getNamespaceUri() == 'http://www.w3.org/2001/XMLSchema':42 if 'schemaLocation' in attrs:43 p = Expat(self._handlers)44 url = attrs['schemaLocation'].getValue()45 if url[:7] != 'http://':46 url = self._parser.GetBase() + '/' + url47 p.parse(url)48 else:49 self._handlers.StartElementHandler(tag, attrs)50 def _EndElementHandler(self, name):51 tag = Tag(self,name)52 self._handlers.EndElementHandler(tag)53 def _CharacterDataHandler(self, s):54 self._handlers.CharacterDataHandler(s)55 56 def _StartNamespaceDeclHandler(self, prefix, uri):57 #print '+++',self,prefix,uri,self._nsUriDict58 try:59 self._nsUriDict[prefix].append(uri)60 except KeyError:61 self._nsUriDict[prefix] = [uri]62 try:63 self._prefixDict[uri].append(prefix)64 except KeyError:65 self._prefixDict[uri] = [prefix]66 def _EndNamespaceDeclHandler(self, prefix):67 #print '---',self,prefix, self._nsUriDict68 uri = self._nsUriDict[prefix][-1]69 self._nsUriDict[prefix].pop()70 self._prefixDict[uri].pop()71 def parse(self, url):72 # There seems to be no way to change the parser encoding setting73 # once the parser is created. So, you need to check the document74 # encoding before creating the parser.75 f = urllib.urlopen(url)76 l = f.readline()77 while l:78 m = re.match(r"<\?\s*xml\s+(?:[^>]*\s+)?encoding\s*=\s*[\"']([^\"']+)[\"'].*",l)79 if m:80 enc = m.group(1)81 break82 l = f.readline()83 else:84 enc = 'UTF-8'85 f.close()86 # create parser87 f = urllib.urlopen(url)88 parser = xml.parsers.expat.ParserCreate(enc,' ')89 parser.StartElementHandler = self._StartElementHandler90 parser.EndElementHandler = self._EndElementHandler91 parser.CharacterDataHandler = self._CharacterDataHandler92 parser.StartNamespaceDeclHandler = self._StartNamespaceDeclHandler93 parser.EndNamespaceDeclHandler = self._EndNamespaceDeclHandler94 self._parser = parser95 i = url.rfind('/')96 self._parser.SetBase(url[:i])97 self._parser.ParseFile(f)98 99class Tag:100 def __init__(self, expat, s):101 # name = namespace_uri + ' ' + tagname102 self._ns_uri, self._tag = s.split()103 self._ns_prefix = expat.getNamespacePrefix(self._ns_uri)104 def __str__(self):105 if self._ns_prefix:106 return self._ns_prefix + ':' + self._tag107 else:108 return self._tag109 def getNamespacePrefix(self):110 return self._ns_prefix111 def getNamespaceUri(self):112 return self._ns_uri113 def getName(self):114 return self._tag115 116class Attribute:117 def __init__(self, expat, tag, name_val):118 # tag = Tag119 # name_val = (att_name, att_value)120 att,val = name_val121 if ':' in att:122 self._ns_prefix, self._att_name = att.split(':')123 else:124 self._ns_prefix = tag.getNamespacePrefix()125 self._att_name = att126 self._ns_uri = expat.getNamespaceUri(self._ns_prefix)127 self._att_value = val128 def __str__(self):129 if self._ns_prefix:130 return self._ns_prefix + ':' + self._att_name131 else:132 return self._att_name133 def getName(self):134 return self._att_name135 136 def getValue(self):137 return self._att_value138 def getNamespaceUri(self):139 return self._ns_uri140 def getNamespacePrefix(self):141 return self._ns_prefix142class MyHandlers(ExpatHandlers):143 def __init__(self):144 self._sh = []145 self._eh = []146 self._ch = []147 self._pushHandlers(self._Start,self._End,self._Char)148 self._ext = None149 self._ext_tag = None150 self._ext_char = None151 self._ext_transform = {'shortName':'Type',152 'label':'Label',153 'longName':'LongName',154 'versionDate':'VersionDate',...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful