How to use check_release method in avocado

Best Python code snippet using avocado_python Github


Full Screen

1#!/usr/bin/env python2# Copyright (c) 2012 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5import sys6from idl_log import ErrOut, InfoOut, WarnOut7from idl_option import GetOption, Option, ParseOptions8from idl_parser import ParseFiles9GeneratorList = []10Option('out', 'List of output files', default='')11Option('release', 'Which release to generate.', default='')12Option('range', 'Which ranges in the form of MIN,MAX.', default='start,end')13class Generator(object):14 """Base class for generators.15 This class provides a mechanism for adding new generator objects to the IDL16 driver. To use this class override the GenerateRelease and GenerateRange17 members, and instantiate one copy of the class in the same module which18 defines it to register the generator. After the AST is generated, call the19 static Run member which will check every registered generator to see which20 ones have been enabled through command-line options. To enable a generator21 use the switches:22 --<sname> : To enable with defaults23 --<sname>_opt=<XXX,YYY=y> : To enable with generator specific options.24 NOTE: Generators still have access to global options25 """26 def __init__(self, name, sname, desc):27 = name28 self.run_switch = Option(sname, desc)29 self.opt_switch = Option(sname + '_opt', 'Options for %s.' % sname,30 default='')31 GeneratorList.append(self)32 self.errors = 033 self.skip_list = []34 def Error(self, msg):35 ErrOut.Log('Error %s : %s' % (, msg))36 self.errors += 137 def GetRunOptions(self):38 options = {}39 option_list = self.opt_switch.Get()40 if option_list:41 option_list = option_list.split(',')42 for opt in option_list:43 offs = opt.find('=')44 if offs > 0:45 options[opt[:offs]] = opt[offs+1:]46 else:47 options[opt] = True48 return options49 if self.run_switch.Get():50 return options51 return None52 def Generate(self, ast, options):53 self.errors = 054 rangestr = GetOption('range')55 releasestr = GetOption('release')56 print "Found releases: %s" % ast.releases57 # Generate list of files to ignore due to errors58 for filenode in ast.GetListOf('File'):59 # If this file has errors, skip it60 if filenode.GetProperty('ERRORS') > 0:61 self.skip_list.append(filenode)62 continue63 # Check for a range option which over-rides a release option64 if not releasestr and rangestr:65 range_list = rangestr.split(',')66 if len(range_list) != 2:67 self.Error('Failed to generate for %s, incorrect range: "%s"' %68 (, rangestr))69 else:70 vmin = range_list[0]71 vmax = range_list[1]72 # Generate 'start' and 'end' represent first and last found.73 if vmin == 'start':74 vmin = ast.releases[0]75 if vmax == 'end':76 vmax = ast.releases[-1]77 vmin = ast.releases.index(vmin)78 vmax = ast.releases.index(vmax) + 179 releases = ast.releases[vmin:vmax]80 InfoOut.Log('Generate range %s of %s.' % (rangestr, ret = self.GenerateRange(ast, releases, options)82 if ret < 0:83 self.Error('Failed to generate range %s : %s.' %(vmin, vmax))84 else:85 InfoOut.Log('%s wrote %d files.' % (, ret))86 # Otherwise this should be a single release generation87 else:88 if releasestr == 'start':89 releasestr = ast.releases[0]90 if releasestr == 'end':91 releasestr = ast.releases[-1]92 if releasestr > ast.releases[-1]:93 InfoOut.Log('There is no unique release for %s, using last release.' %94 releasestr)95 releasestr = ast.releases[-1]96 if releasestr not in ast.releases:97 self.Error('Release %s not in [%s].' %98 (releasestr, ', '.join(ast.releases)))99 if releasestr:100 InfoOut.Log('Generate release %s of %s.' % (releasestr, ret = self.GenerateRelease(ast, releasestr, options)102 if ret < 0:103 self.Error('Failed to generate release %s.' % releasestr)104 else:105 InfoOut.Log('%s wrote %d files.' % (, ret))106 else:107 self.Error('No range or release specified for %s.' % releasestr)108 return self.errors109 def GenerateRelease(self, ast, release, options):110 __pychecker__ = 'unusednames=ast,release,options'111 self.Error("Undefined release generator.")112 return 0113 def GenerateRange(self, ast, releases, options):114 __pychecker__ = 'unusednames=ast,releases,options'115 self.Error("Undefined range generator.")116 return 0117 @staticmethod118 def Run(ast):119 fail_count = 0120 # Check all registered generators if they should run.121 for gen in GeneratorList:122 options = gen.GetRunOptions()123 if options is not None:124 if gen.Generate(ast, options):125 fail_count += 1126 return fail_count127class GeneratorByFile(Generator):128 """A simplified generator that generates one output file per IDL source file.129 A subclass of Generator for use of generators which have a one to one130 mapping between IDL sources and output files.131 Derived classes should define GenerateFile.132 """133 def GenerateFile(self, filenode, releases, options):134 """Generates an output file from the IDL source.135 Returns true if the generated file is different than the previously136 generated file.137 """138 __pychecker__ = 'unusednames=filenode,releases,options'139 self.Error("Undefined release generator.")140 return 0141 def GenerateRelease(self, ast, release, options):142 return self.GenerateRange(ast, [release], options)143 def GenerateRange(self, ast, releases, options):144 # Get list of out files145 outlist = GetOption('out')146 if outlist: outlist = outlist.split(',')147 skipList = []148 cnt = 0149 for filenode in ast.GetListOf('File'):150 # Ignore files with errors151 if filenode in self.skip_list:152 continue153 # Skip this file if not required154 if outlist and filenode.GetName() not in outlist:155 continue156 # Create the output file and increment out count if there was a delta157 if self.GenerateFile(filenode, releases, options):158 cnt = cnt + 1159 for filenode in skipList:160 errcnt = filenode.GetProperty('ERRORS')161 ErrOut.Log('%s : Skipped because of %d errors.' % (162 filenode.GetName(), errcnt))163 if skipList:164 return -len(skipList)165 if GetOption('diff'):166 return -cnt167 return cnt168check_release = 0169check_range = 0170class GeneratorReleaseTest(Generator):171 def GenerateRelease(self, ast, release, options = {}):172 __pychecker__ = 'unusednames=ast,release,options'173 global check_release174 check_map = {175 'so_long': True,176 'MyOpt': 'XYZ',177 'goodbye': True178 }179 check_release = 1180 for item in check_map:181 check_item = check_map[item]182 option_item = options.get(item, None)183 if check_item != option_item:184 print 'Option %s is %s, expecting %s' % (item, option_item, check_item)185 check_release = 0186 if release != 'M14':187 check_release = 0188 return check_release == 1189 def GenerateRange(self, ast, releases, options):190 __pychecker__ = 'unusednames=ast,releases,options'191 global check_range192 check_range = 1193 return True194def Test():195 __pychecker__ = 'unusednames=args'196 global check_release197 global check_range198 ParseOptions(['--testgen_opt=so_long,MyOpt=XYZ,goodbye'])199 if Generator.Run('AST') != 0:200 print 'Generate release: Failed.\n'201 return -1202 if check_release != 1 or check_range != 0:203 print 'Gererate release: Failed to run.\n'204 return -1205 check_release = 0206 ParseOptions(['--testgen_opt="HELLO"', '--range=M14,M16'])207 if Generator.Run('AST') != 0:208 print 'Generate range: Failed.\n'209 return -1210 if check_release != 0 or check_range != 1:211 print 'Gererate range: Failed to run.\n'212 return -1213 print 'Generator test: Pass'214 return 0215def Main(args):216 if not args: return Test()217 filenames = ParseOptions(args)218 ast = ParseFiles(filenames)219 return Generator.Run(ast)220if __name__ == '__main__':221 GeneratorReleaseTest('Test Gen', 'testgen', 'Generator Class Test.')...

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:


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

Run avocado 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?