Best Python code snippet using autotest_python
coverage.py
Source:coverage.py
...159 self.excluding_suite = 1160 self.recordAndDispatch(body)161 self.excluding_suite = exsuite162 163 def doPlainWordSuite(self, prevsuite, suite):164 # Finding the exclude lines for else's is tricky, because they aren't165 # present in the compiler parse tree. Look at the previous suite,166 # and find its last line. If any line between there and the else's167 # first line are excluded, then we exclude the else.168 lastprev = self.getLastLine(prevsuite)169 firstelse = self.getFirstLine(suite)170 for l in range(lastprev+1, firstelse):171 if self.suite_spots.has_key(l):172 self.doSuite(None, suite, exclude=self.excluded.has_key(l))173 break174 else:175 self.doSuite(None, suite)176 177 def doElse(self, prevsuite, node):178 if node.else_:179 self.doPlainWordSuite(prevsuite, node.else_)180 181 def visitFor(self, node):182 self.doSuite(node, node.body)183 self.doElse(node.body, node)184 def visitIf(self, node):185 # The first test has to be handled separately from the rest.186 # The first test is credited to the line with the "if", but the others187 # are credited to the line with the test for the elif.188 self.doSuite(node, node.tests[0][1])189 for t, n in node.tests[1:]:190 self.doSuite(t, n)191 self.doElse(node.tests[-1][1], node)192 def visitWhile(self, node):193 self.doSuite(node, node.body)194 self.doElse(node.body, node)195 def visitTryExcept(self, node):196 self.doSuite(node, node.body)197 for i in range(len(node.handlers)):198 a, b, h = node.handlers[i]199 if not a:200 # It's a plain "except:". Find the previous suite.201 if i > 0:202 prev = node.handlers[i-1][2]203 else:204 prev = node.body205 self.doPlainWordSuite(prev, h)206 else:207 self.doSuite(a, h)208 self.doElse(node.handlers[-1][2], node)209 210 def visitTryFinally(self, node):211 self.doSuite(node, node.body)212 self.doPlainWordSuite(node.body, node.final)213 214 def visitGlobal(self, node):215 # "global" statements don't execute like others (they don't call the216 # trace function), so don't record their line numbers.217 pass218the_coverage = None219class coverage:220 error = "coverage error"221 # Name of the cache file (unless environment variable is set).222 cache_default = ".coverage"223 # Environment variable naming the cache file.224 cache_env = "COVERAGE_FILE"225 # A map from canonical Python source file name to a dictionary in226 # which there's an entry for each line number that has been...
CovParse.py
Source:CovParse.py
...131 self.recordAndDispatch(body)132 self.excluding_suite = exsuite133 # if qq:134 # print("EXCL-2", body.lineno, self.excluding_suite, exsuite)135 def doPlainWordSuite(self, prevsuite, suite):136 # Finding the exclude lines for else's is tricky, because they aren't137 # present in the compiler parse tree. Look at the previous suite,138 # and find its last line. If any line between there and the else's139 # first line are excluded, then we exclude the else.140 lastprev = self.getLastLine(prevsuite)141 firstelse = self.getFirstLine(suite)142 for l in range(lastprev+1, firstelse):143 if self.suite_spots.has_key(l):144 self.doSuite(None, suite, exclude=self.excluded.get(l, 0))145 break146 else:147 self.doSuite(None, suite)148 def doElse(self, prevsuite, node):149 if node.else_:150 self.doPlainWordSuite(prevsuite, node.else_)151 def visitFor(self, node):152 self.doSuite(node, node.body)153 self.doElse(node.body, node)154 def visitIf(self, node):155 # The first test has to be handled separately from the rest.156 # The first test is credited to the line with the "if", but the others157 # are credited to the line with the test for the elif.158 exsuite = self.excluding_suite159 exclTag = self.recordNodeLine(node)160 if exclTag not in [None, 1, 0]:161 self.excluding_suite = exclTag162 # print("IF", node.lineno, self.excluding_suite)163 # print("EXCL-XX", node.lineno, self.excluding_suite, exsuite)164 self.doSuite(node, node.tests[0][1])165 for t, n in node.tests[1:]:166 self.doSuite(t, n, qq=1)167 # print("EXCL-YY", node.lineno, self.excluding_suite, exsuite)168 self.doElse(node.tests[-1][1], node)169 # print("EXCL-ZZ", node.lineno, self.excluding_suite, exsuite)170 self.excluding_suite = exsuite171 def visitWhile(self, node):172 self.doSuite(node, node.body)173 self.doElse(node.body, node)174 def visitTryExcept(self, node):175 self.doSuite(node, node.body)176 for i in range(len(node.handlers)):177 a, b, h = node.handlers[i]178 if not a:179 # It's a plain "except:". Find the previous suite.180 if i > 0:181 prev = node.handlers[i-1][2]182 else:183 prev = node.body184 self.doPlainWordSuite(prev, h)185 else:186 self.doSuite(a, h)187 self.doElse(node.handlers[-1][2], node)188 def visitTryFinally(self, node):189 self.doSuite(node, node.body)190 self.doPlainWordSuite(node.body, node.final)191 def visitGlobal(self, node):192 # "global" statements don't execute like others (they don't call the193 # trace function), so don't record their line numbers.194 pass195def get_suite_spots(tree, spots):196 """ Analyze a parse tree to find suite introducers which span a number197 of lines.198 """199 import symbol, token200 for i in range(1, len(tree)):201 if type(tree[i]) == type(()):202 if tree[i][0] == symbol.suite:203 # Found a suite, look back for the colon and keyword.204 lineno_colon = lineno_word = None...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!