Best Python code snippet using autotest_python
coverage.py
Source:coverage.py  
...90	91	def doCode(self, node):92		if hasattr(node, 'decorators') and node.decorators:93			self.dispatch(node.decorators)94			self.recordAndDispatch(node.code)95		else:96			self.doSuite(node, node.code)97			98	visitFunction = visitClass = doCode99	def getFirstLine(self, node):100		# Find the first line in the tree node.101		lineno = node.lineno102		for n in node.getChildNodes():103			f = self.getFirstLine(n)104			if lineno and f:105				lineno = min(lineno, f)106			else:107				lineno = lineno or f108		return lineno109	def getLastLine(self, node):110		# Find the first line in the tree node.111		lineno = node.lineno112		for n in node.getChildNodes():113			lineno = max(lineno, self.getLastLine(n))114		return lineno115	116	def doStatement(self, node):117		self.recordLine(self.getFirstLine(node))118	visitAssert = visitAssign = visitAssTuple = visitDiscard = visitPrint = \119		visitPrintnl = visitRaise = visitSubscript = visitDecorators = \120		doStatement121	122	def recordNodeLine(self, node):123		return self.recordLine(node.lineno)124	125	def recordLine(self, lineno):126		# Returns a bool, whether the line is included or excluded.127		if lineno:128			# Multi-line tests introducing suites have to get charged to their129			# keyword.130			if lineno in self.suite_spots:131				lineno = self.suite_spots[lineno][0]132			# If we're inside an exluded suite, record that this line was133			# excluded.134			if self.excluding_suite:135				self.excluded[lineno] = 1136				return 0137			# If this line is excluded, or suite_spots maps this line to138			# another line that is exlcuded, then we're excluded.139			elif self.excluded.has_key(lineno) or \140				 self.suite_spots.has_key(lineno) and \141				 self.excluded.has_key(self.suite_spots[lineno][1]):142				return 0143			# Otherwise, this is an executable line.144			else:145				self.statements[lineno] = 1146				return 1147		return 0148	149	default = recordNodeLine150	151	def recordAndDispatch(self, node):152		self.recordNodeLine(node)153		self.dispatch(node)154	def doSuite(self, intro, body, exclude = 0):155		exsuite = self.excluding_suite156		if exclude or (intro and not self.recordNodeLine(intro)):157			self.excluding_suite = 1158		self.recordAndDispatch(body)159		self.excluding_suite = exsuite160		161	def doPlainWordSuite(self, prevsuite, suite):162		# Finding the exclude lines for else's is tricky, because they aren't163		# present in the compiler parse tree.  Look at the previous suite,164		# and find its last line.  If any line between there and the else's165		# first line are excluded, then we exclude the else.166		lastprev = self.getLastLine(prevsuite)167		firstelse = self.getFirstLine(suite)168		for l in range(lastprev + 1, firstelse):169			if self.suite_spots.has_key(l):170				self.doSuite(None, suite, exclude = self.excluded.has_key(l))171				break172		else:...CovParse.py
Source:CovParse.py  
...55    visitStmt = visitModule = doRecursive56    def doCode(self, node):57        if hasattr(node, 'decorators') and node.decorators:58            self.dispatch(node.decorators)59            self.recordAndDispatch(node.code)60        else:61            self.doSuite(node, node.code)62    visitFunction = visitClass = doCode63    def getFirstLine(self, node):64        # Find the first line in the tree node.65        lineno = node.lineno66        for n in node.getChildNodes():67            f = self.getFirstLine(n)68            if lineno and f:69                lineno = min(lineno, f)70            else:71                lineno = lineno or f72        return lineno73    def getLastLine(self, node):74        # Find the first line in the tree node.75        lineno = node.lineno76        for n in node.getChildNodes():77            lineno = max(lineno, self.getLastLine(n))78        return lineno79    def doStatement(self, node):80        self.recordLine(self.getFirstLine(node))81    visitAssert = visitAssign = visitAssTuple = visitDiscard = visitPrint = \82        visitPrintnl = visitRaise = visitSubscript = visitDecorators = \83        doStatement84    def recordNodeLine(self, node):85        return self.recordLine(node.lineno)86    def recordLine(self, lineno):87        # Returns a bool, whether the line is included or excluded.88        # print("REC", lineno)89        if lineno:90            self.all_statements[lineno] = 191            # Multi-line tests introducing suites have to get charged to their92            # keyword.93            if lineno in self.suite_spots:94                lineno = self.suite_spots[lineno][0]95            # If we're inside an exluded suite, record that this line was96            # excluded.97            if self.excluding_suite:98                # print("EXCLUDE", lineno, self.excluding_suite)99                self.excluded[lineno] = self.excluding_suite100                return self.excluding_suite101            # If this line is excluded, or suite_spots maps this line to102            # another line that is excluded, then we're excluded.103            elif self.excluded.has_key(lineno):104                return self.excluded[lineno]105            elif self.suite_spots.has_key(lineno) and \106                 self.excluded.has_key(self.suite_spots[lineno][1]):107                return self.excluded[self.suite_spots[lineno][1]]108            # Otherwise, this is an executable line.109            else:110                self.statements[lineno] = 1111                return 1112        return 0113    default = recordNodeLine114    def recordAndDispatch(self, node):115        self.recordNodeLine(node)116        self.dispatch(node)117    def doSuite(self, intro, body, exclude=0, qq=0):118        exsuite = self.excluding_suite119        exclTag = None120        # if not exclude and intro:121        if intro:122            # if qq:123            #     print("SUITE", intro.lineno, body.__class__, len(body.nodes))124            exclTag = self.recordNodeLine(intro)125        if exclude:126            self.excluding_suite = exclude127        elif exclTag not in [None, 1, 0]:128            self.excluding_suite = exclTag129        # if qq or self.excluding_suite == 1:130        #     print("EXCL-1", body.lineno, self.excluding_suite, exsuite, exclude, exclTag)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                break...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!!
