How to use __remove method in hypothesis

Best Python code snippet using hypothesis

html_input.py

Source:html_input.py Github

copy

Full Screen

...65 def _getNodeType(self):66 nodeType = NodeType.Text # Default67 nChar = self.__nextChar68 if nChar=="<":69 self.__remove(1)70 nChar = self.__nextChar71 if self.__isAlpha(nChar): # Element72 nodeType = NodeType.StartElement73 elif nChar=="?":74 nodeType = NodeType.PI75 elif nChar=="/": # </76 self.__remove(1)77 if self.__isAlpha(self.__nextChar):78 nodeType = NodeType.EndElement79 self.__pos -= 180 elif nChar=="!":81 if self.__assert("!--"):82 nodeType = NodeType.Comment83 elif self.__assert("![CDATA["):84 nodeType = NodeType.CDATA85 elif self.__assert("!["):86 nodeType = NodeType.MsoDeclaration87 else:88 nodeType = NodeType.Declaration89 self.__pos -= 190 return nodeType91 92 def __getElementNode(self):93 atts = {}94 attList = []95 name = None96 nodeType = NodeType.Unknown97 98 if not self.__assert("<"):99 raise Exception("Expected a '<' character!")100 pos = self.__pos101 self.__remove(1)102 name = self.__getElementName()103 text = None104 # get attributes105 while self.__isNotEOI:106 nChar = self.__nextChar107 if nChar==">":108 self.__remove(1)109 nodeType = NodeType.StartElement110 break111 elif nChar=="<":112 # Error/Exception this is not an element after all it is just text!113 # restore self.__pos and return a textNode114 self.__pos = pos + 1115 nodeType = NodeType.Text116 name = None117 text = "<" + self.__getText()118 attList = []119 break120 elif nChar=="/":121 if self.__assert("/>"):122 self.__remove(2)123 nodeType = NodeType.EmptyElement124 break125 else:126 self.__remove(1) # just ignore it127 elif self.__isAlpha(nChar):128 attName = self.__getAttributeName()129 if self.__assert("="):130 self.__remove(1)131 attValue = self.__getAttributeValue()132 else:133 attValue = attName134 #135 count = 2136 if atts.has_key(attName):137 pass138 att = Attribute(attName, attValue)139 atts[attName] = att140 attList.append(att)141 else:142 self.__remove(1)143 return Node(nodeType, name, text, attList)144 145 def __getEndElementNode(self):146 if not self.__assert("</"):147 raise Exception("Expected '</'!")148 self.__remove(2)149 name = self.__getElementName()150 self.__getUpto(">")151 return Node(NodeType.EndElement, name, None)152 153 def __getPINode(self):154 if not self.__assert("<?"):155 raise Exception("Expected '<?'!")156 self.__remove(2)157 value = self.__getUpto("?>")158 name = value.split()[0]159 return Node(NodeType.PI, name, value)160 161 def __getCommentNode(self):162 if not self.__assert("<!--"):163 raise Exception("Expected '<!--'!")164 self.__remove("<!--")165 return Node(NodeType.Comment, None, self.__getUpto("-->"))166 167 def __getTextNode(self):168 return Node(NodeType.Text, None, self.__getText())169 170 def __getCDataNode(self):171 if not self.__assert("<![CDATA["):172 raise Exception("Expected '<![CDATA['!")173 self.__remove("<![CDATA[")174 data = self.__getUpto("]]>")175 return Node(NodeType.CDATA, None, data)176 177 def __getMsoDeclarationNode(self):178 if not self.__assert("<!["):179 raise Exception("Expected '<!['!")180 self.__remove("<![")181 data = self.__getUpto("]>")182 return Node(NodeType.MsoDeclaration, None, data)183 184 def __getDeclarationNode(self):185 if not self.__assert("<!"):186 raise Exception("Expected '<!'!")187 self.__remove("<!")188 data = self.__getUpto(">")189 return Node(NodeType.Declaration, None, data)190 191 @property192 def __isEOI(self):193 return self.__pos >= self.__len194 195 @property196 def __isNotEOI(self):197 return self.__pos < self.__len198 199 @property200 def __nextChar(self):201 if self.__isEOI:202 return ""203 return self.__data[self.__pos]204 205 @property206 def __isNextAlpha(self):207 if self.__isNotEOI:208 c = self.__nextChar209 if self.__isAlpha(c):210 return True211 return False212 213 def __assert(self, s):214 return self.__data[self.__pos: self.__pos+len(s)]==s215 216 def __getElementName(self):217 name = self.__getName()218 self.__removeWhitespace()219 return name220 221 def __getAttributeName(self):222 name = self.__getName()223 self.__removeWhitespace()224 return name225 226 def __getAttributeValue(self):227 self.__removeWhitespace()228 nChar = self.__nextChar229 if nChar=="'" or nChar=='"':230 self.__remove(1)231 s = self.__getUpto(nChar)232 else:233 s = self.__getUptoWhitespaceOr(">")234 if s.endswith("/"): # backup one235 s = s[:-1]236 self.__pos-=1237 self.__removeWhitespace()238 return s239 240 def __getName(self):241 start = self.__pos242 if self.__isNextAlpha:243 while self.__isNotEOI:244 c = self.__nextChar245 if c.isalnum() or c==":" or c=="." or c=="_" or c=="-":246 self.__remove(1)247 else:248 break249 else:250 return None251 return self.__data[start:self.__pos]252 253 def __getText(self):254 # read upto a <Alpha or </ or <! or <?255 start = self.__pos256 while self.__isNotEOI:257 if self.__nextChar=="<":258 if self._getNodeType()!=NodeType.Text:259 break260 self.__remove(1)261 return self.__data[start:self.__pos]262 263 def __getUptoWhitespaceOr(self, endStr):264 start = self.__pos265 endChar = endStr[0]266 while self.__isNotEOI:267 nChar = self.__nextChar268 if nChar.isspace():269 break270 if nChar==endChar and self.__assert(endStr):271 break272 self.__remove(1)273 return self.__data[start:self.__pos]274 275 def __getUpto(self, endStr):276 start = self.__pos277 c = endStr[0]278 s = None279 while self.__isNotEOI:280 if self.__nextChar==c:281 if self.__assert(endStr):282 break283 self.__remove(1)284 s = self.__data[start:self.__pos]285 self.__remove(endStr)286 return s287 288 def __remove(self, num=1):289 if type(num) in types.StringTypes:290 num = len(num)291 self.__pos += num292 293 def __removeWhitespace(self):294 while self.__nextChar.isspace():295 self.__remove(1)296 297 def __isAlpha(self, char):298 return char.isalpha() or char=="_"299class Node(object):300 def __init__(self, nodeType, name, value, attributes=[]):301 if nodeType == NodeType.Unknown:302 raise Exception("Unknown NodeType")303 self.__nodeType = nodeType304 self.__name = name305 self.__value = value306 self.__attributes = attributes307 self.__script = None308 309 def __getNodeType(self):...

Full Screen

Full Screen

146. LRU Cache.py

Source:146. LRU Cache.py Github

copy

Full Screen

...9 self.cache = {}10 def get(self, key: int) -> int:11 if key in self.cache:12 val = self.cache[key].val13 self.__remove(key)14 self.__add(key, val)15 return val16 return -117 def put(self, key: int, value: int) -> None:18 if key in self.cache:19 self.__remove(key)20 self.__add(key, value)21 def __add(self, key, val):22 if len(self.cache) >= self.limit:23 self.__remove(self.tail.prev.key)24 node = Node(key, val, self.head, self.head.next)25 self.cache[key] = self.head.next = node.next.prev = node #26 def __remove(self, key):27 if key in self.cache:28 node = self.cache[key]29 node.prev.next = node.next30 node.next.prev = node.prev31 del self.cache[key]32class Node:33 def __init__(self, key, val, prev, nxt):34 self.key = key35 self.val = val36 self.prev = prev37 self.next = nxt38# Your LRUCache object will be instantiated and called as such:39# obj = LRUCache(capacity)40# param_1 = obj.get(key)41# obj.put(key,value)42class Node:43 def __init__(self, key, val, prev, nxt):44 self.key = key45 self.val = val46 self.prev = prev47 self.next = nxt48class LRUCache:49 def __init__(self, capacity: int):50 self.capacity = capacity51 self.dic = {}52 self.head = None53 self.tail = None54 def get(self, key: int) -> int:55 if (key not in self.dic):56 return -157 node = self.dic[key]58 self.__remove(node)59 self.put(key, node.val)60 return node.val61 def put(self, key: int, value: int) -> None:62 if (key in self.dic): # remember to check if already exists63 self.__remove(self.dic[key]) # if exists, must remove it first64 if (len(self.dic) >= self.capacity):65 self.__remove(self.head)66 self.__add(key, value)67 def __remove(self, node):68 if (node == self.head): self.head = node.next69 if (node == self.tail): self.tail = node.prev70 if (node.prev): node.prev.next = node.next71 if (node.next): node.next.prev = node.prev72 del self.dic[node.key]73 def __add(self, key, val):74 node = Node(key, val, self.tail, None)75 self.dic[key] = node76 if (self.tail): self.tail.next = node77 self.tail = node78 if (not self.head): self.head = node # remember to assign head79# Your LRUCache object will be instantiated and called as such:80# obj = LRUCache(capacity)81# param_1 = obj.get(key)...

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 hypothesis 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