Best Python code snippet using localstack_python
complay.py
Source:complay.py  
...85        self.group_collections = { }86        self.current_collections = None87    def format_location(self):88        return '%s:%d:%d' % (self.locator.getSystemId(), self.locator.getLineNumber(), self.locator.getColumnNumber())89    def handle_error(self, msg):90        self.errors += 191        sys.stderr.write('error: %s: %s\n' % (self.format_location(), msg))92    def check_int_attribute(self, name, attrs, key, default):93        if key not in attrs:94            return default95        val = attrs[key]96        if self.VARPATTERN.match(val):97            return None98        base = 1099        offs = 0100        if (len(val) >= 1) and ('$' == val[0]):101            base = 16102            offs = 1103        elif (len(val) >= 2) and ('0' == val[0]) and (('x' == val[1]) or ('X' == val[1])):104            base = 16105            offs = 2106        elif (len(val) >= 1) and ('#' == val[0]):107            offs = 1108        try:109            return int(val[offs:], base)110        except:111            self.handle_error('Element %s attribute %s "%s" is not an integer' % (name, key, val))112            return None113    def check_float_attribute(self, name, attrs, key, default):114        if key not in attrs:115            return default116        val = attrs[key]117        if self.VARPATTERN.match(val):118            return None119        try:120            return float(val)121        except:122            self.handle_error('Element %s attribute %s "%s" is not a floating point number' % (name, key, val))123            return None124    def check_numeric_attribute(self, name, attrs, key, default):125        if key not in attrs:126            return default127        val = attrs[key]128        if self.VARPATTERN.match(val):129            return None130        base = 0131        offs = 0132        try:133            if (len(val) >= 1) and ('$' == val[0]):134                base = 16135                offs = 1136            elif (len(val) >= 2) and ('0' == val[0]) and (('x' == val[1]) or ('X' == val[1])):137                base = 16138                offs = 2139            elif (len(val) >= 1) and ('#' == val[0]):140                base = 10141                offs = 1142            elif self.FLOATCHARS.match(val):143                return float(val)144            return int(val[offs:], base)145        except:146            self.handle_error('Element %s attribute %s "%s" is not a number' % (name, key, val))147            return None148    def check_parameter(self, attrs):149        if 'name' not in attrs:150            self.handle_error('Element param missing attribute name')151        else:152            name = attrs['name']153        self.check_numeric_attribute('param', attrs, 'increment', None)154        lshift = self.check_int_attribute('param', attrs, 'lshift', None)155        if (lshift is not None) and (0 > lshift):156            self.handle_error('Element param attribute lshift "%s" is negative' % (attrs['lshift'], ))157        rshift = self.check_int_attribute('param', attrs, 'rshift', None)158        if (rshift is not None) and (0 > rshift):159            self.handle_error('Element param attribute rshift "%s" is negative' % (attrs['rshift'], ))160        if self.repeat_depth and self.repeat_depth[-1]:161            if 'start' in attrs:162                if 'value' in attrs:163                    self.handle_error('Element param has both start and value attributes')164                if 'name' in attrs:165                    if name not in self.variable_scopes[-1]:166                        self.variable_scopes[-1][name] = True167                    elif not self.VARPATTERN.match(name):168                        self.handle_error('Generator parameter "%s" redefined' % (name, ))169            else:170                if 'value' not in attrs:171                    self.handle_error('Element param missing attribute value')172                if ('increment' in attrs) or ('lshift' in attrs) or ('rshift' in attrs):173                    self.handle_error('Element param has increment/lshift/rshift attribute(s) without start attribute')174                if 'name' in attrs:175                    if not self.variable_scopes[-1].get(name, False):176                        self.variable_scopes[-1][name] = False177                    elif not self.VARPATTERN.match(name):178                        self.handle_error('Generator parameter "%s" redefined' % (name, ))179        else:180            if ('start' in attrs) or ('increment' in attrs) or ('lshift' in attrs) or ('rshift' in attrs):181                self.handle_error('Element param with start/increment/lshift/rshift attribute(s) not in repeat scope')182            if 'value' not in attrs:183                self.handle_error('Element param missing attribute value')184            if 'name' in attrs:185                self.variable_scopes[-1][attrs['name']] = False186    def check_bounds(self, attrs):187        left = self.check_float_attribute('bounds', attrs, 'left', 0.0)188        top = self.check_float_attribute('bounds', attrs, 'top', 0.0)189        right = self.check_float_attribute('bounds', attrs, 'right', 1.0)190        bottom = self.check_float_attribute('bounds', attrs, 'bottom', 1.0)191        self.check_float_attribute('bounds', attrs, 'x', 0.0)192        self.check_float_attribute('bounds', attrs, 'y', 0.0)193        self.check_float_attribute('bounds', attrs, 'xc', 0.0)194        self.check_float_attribute('bounds', attrs, 'yc', 0.0)195        width = self.check_float_attribute('bounds', attrs, 'width', 1.0)196        height = self.check_float_attribute('bounds', attrs, 'height', 1.0)197        if (left is not None) and (right is not None) and (left > right):198            self.handle_error('Element bounds attribute left "%s" is greater than attribute right "%s"' % (199                    attrs.get('left', 0.0),200                    attrs.get('right', 1.0)))201        if (top is not None) and (bottom is not None) and (top > bottom):202            self.handle_error('Element bounds attribute top "%s" is greater than attribute bottom "%s"' % (203                    attrs.get('top', 0.0),204                    attrs.get('bottom', 1.0)))205        if (width is not None) and (0.0 > width):206            self.handle_error('Element bounds attribute width "%s" is negative' % (attrs['width'], ))207        if (height is not None) and (0.0 > height):208            self.handle_error('Element bounds attribute height "%s" is negative' % (attrs['height'], ))209        if (('left' in attrs) and (('x' in attrs) or ('xc' in attrs))) or (('x' in attrs) and ('xc' in attrs)):210            self.handle_error('Element bounds has multiple horizontal origin attributes (left/x/xc)')211        if (('left' in attrs) and ('width' in attrs)) or ((('x' in attrs) or ('xc' in attrs)) and ('right' in attrs)):212            self.handle_error('Element bounds has both left/right and x/xc/width attributes')213        if (('top' in attrs) and (('y' in attrs) or ('yc' in attrs))) or (('y' in attrs) and ('yc' in attrs)):214            self.handle_error('Element bounds has multiple vertical origin attributes (top/y/yc)')215        if (('top' in attrs) and ('height' in attrs)) or ((('y' in attrs) or ('yc' in attrs)) and ('bottom' in attrs)):216            self.handle_error('Element bounds has both top/bottom and y/yc/height attributes')217    def check_orientation(self, attrs):218        if self.have_orientation[-1]:219            self.handle_error('Duplicate element orientation')220        else:221            self.have_orientation[-1] = True222        if self.check_int_attribute('orientation', attrs, 'rotate', 0) not in self.ORIENTATIONS:223            self.handle_error('Element orientation attribute rotate "%s" is unsupported' % (attrs['rotate'], ))224        for name in ('swapxy', 'flipx', 'flipy'):225            if (attrs.get(name, 'no') not in self.YESNO) and (not self.VARPATTERN.match(attrs[name])):226                self.handle_error('Element orientation attribute %s "%s" is not "yes" or "no"' % (name, attrs[name]))227    def check_color(self, attrs):228        self.check_color_channel(attrs, 'red')229        self.check_color_channel(attrs, 'green')230        self.check_color_channel(attrs, 'blue')231        self.check_color_channel(attrs, 'alpha')232    def check_color_channel(self, attrs, name):233        channel = self.check_float_attribute('color', attrs, name, None)234        if (channel is not None) and ((0.0 > channel) or (1.0 < channel)):235            self.handle_error('Element color attribute %s "%s" outside valid range 0.0-1.0' % (name, attrs[name]))236    def check_tag(self, tag, element, attr):237        if '' == tag:238            self.handle_error('Element %s attribute %s is empty' % (element, attr))239        else:240            if tag.find('^') >= 0:241                self.handle_error('Element %s attribute %s "%s" contains parent device reference' % (element, attr, tag))242            if ':' == tag[-1]:243                self.handle_error('Element %s attribute %s "%s" ends with separator' % (element, attr, tag))244            if tag.find('::') >= 0:245                self.handle_error('Element %s attribute %s "%s" contains double separator' % (element, attr, tag))246    def check_component(self, name, attrs):247        statemask = self.check_int_attribute(name, attrs, 'statemask', None)248        stateval = self.check_int_attribute(name, attrs, 'state', None)249        if stateval is not None:250            if 0 > stateval:251                self.handle_error('Element %s attribute state "%s" is negative' % (name, attrs['state']))252            if (statemask is not None) and (stateval & ~statemask):253                self.handle_error('Element %s attribute state "%s" has bits set that are clear in attribute statemask "%s"' % (name, attrs['state'], attrs['statemask']))254        if 'image' == name:255            self.handlers.append((self.imageComponentStartHandler, self.imageComponentEndHandler))256        else:257            self.handlers.append((self.componentStartHandler, self.componentEndHandler))258        self.have_bounds.append({ })259        self.have_color.append({ })260    def check_view_item(self, name, attrs):261        if 'id' in attrs:262            if not attrs['id']:263                self.handle_error('Element %s attribute id is empty' % (name, ))264            elif not self.VARPATTERN.match(attrs['id']):265                if attrs['id'] in self.item_ids:266                    self.handle_error('Element %s has duplicate id "%s" (previous %s)' % (name, attrs['id'], self.item_ids[attrs['id']]))267                else:268                    self.item_ids[attrs['id']] = self.format_location()269                if self.repeat_depth[-1]:270                    self.handle_error('Element %s attribute id "%s" in repeat contains no parameter references' % (name, attrs['id']))271        if ('blend' in attrs) and (attrs['blend'] not in self.BLENDMODES) and not self.VARPATTERN.match(attrs['blend']):272            self.handle_error('Element %s attribute blend "%s" is unsupported' % (name, attrs['blend']))273        if 'inputtag' in attrs:274            if 'inputmask' not in attrs:275                self.handle_error('Element %s has inputtag attribute without inputmask attribute' % (name, ))276            self.check_tag(attrs['inputtag'], name, 'inputtag')277        elif 'inputmask' in attrs:278            self.handle_error('Element %s has inputmask attribute without inputtag attribute' % (name, ))279        inputraw = None280        if 'inputraw' in attrs:281            if (attrs['inputraw'] not in self.YESNO) and (not self.VARPATTERN.match(attrs['inputraw'])):282                self.handle_error('Element %s attribute inputraw "%s" is not "yes" or "no"' % (name, attrs['inputraw']))283            else:284                inputraw = 'yes' == attrs['inputraw']285            if 'inputmask' not in attrs:286                self.handle_error('Element %s has inputraw attribute without inputmask attribute' % (name, ))287            if 'inputtag' not in attrs:288                self.handle_error('Element %s has inputraw attribute without inputtag attribute' % (name, ))289        inputmask = self.check_int_attribute(name, attrs, 'inputmask', None)290        if (inputmask is not None) and (not inputmask):291            if (inputraw is None) or (not inputraw):292                self.handle_error('Element %s attribute inputmask "%s" is zero' % (name, attrs['inputmask']))293    def startViewItem(self, name):294        self.handlers.append((self.viewItemStartHandler, self.viewItemEndHandler))295        self.have_bounds.append(None if 'group' == name else { })296        self.have_orientation.append(False)297        self.have_color.append(None if 'group' == name else { })298        self.have_xscroll.append(None if ('group' == name) or ('screen' == name) else False)299        self.have_yscroll.append(None if ('group' == name) or ('screen' == name) else False)300    def rootStartHandler(self, name, attrs):301        if 'mamelayout' != name:302            self.ignored_depth = 1303            self.handle_error('Expected root element mamelayout but found %s' % (name, ))304        else:305            if 'version' not in attrs:306                self.handle_error('Element mamelayout missing attribute version')307            else:308                try:309                    int(attrs['version'])310                except:311                    self.handle_error('Element mamelayout attribute version "%s" is not an integer' % (attrs['version'], ))312            self.have_script = None313            self.variable_scopes.append({ })314            self.repeat_depth.append(0)315            self.handlers.append((self.layoutStartHandler, self.layoutEndHandler))316    def rootEndHandler(self, name, attrs):317        pass # should be unreachable318    def layoutStartHandler(self, name, attrs):319        if 'element' == name:320            if 'name' not in attrs:321                self.handle_error('Element element missing attribute name')322            else:323                generated_name = self.VARPATTERN.match(attrs['name'])324                if generated_name:325                    self.generated_element_names = True326                if attrs['name'] not in self.elements:327                    self.elements[attrs['name']] = self.format_location()328                elif not generated_name:329                    self.handle_error('Element element has duplicate name (previous %s)' % (self.elements[attrs['name']], ))330            defstate = self.check_int_attribute(name, attrs, 'defstate', None)331            if (defstate is not None) and (0 > defstate):332                self.handle_error('Element element attribute defstate "%s" is negative' % (attrs['defstate'], ))333            self.handlers.append((self.elementStartHandler, self.elementEndHandler))334        elif 'group' == name:335            self.current_collections = { }336            if 'name' not in attrs:337                self.handle_error('Element group missing attribute name')338            else:339                generated_name = self.VARPATTERN.match(attrs['name'])340                if generated_name:341                    self.generated_group_names = True342                if attrs['name'] not in self.groups:343                    self.groups[attrs['name']] = self.format_location()344                    if not generated_name:345                        self.group_collections[attrs['name']] = self.current_collections346                elif not generated_name:347                    self.handle_error('Element group has duplicate name (previous %s)' % (self.groups[attrs['name']], ))348            self.handlers.append((self.groupViewStartHandler, self.groupViewEndHandler))349            self.variable_scopes.append({ })350            self.item_ids = { }351            self.repeat_depth.append(0)352            self.have_bounds.append(None)353        elif ('view' == name) and (not self.repeat_depth[-1]):354            self.current_collections = { }355            if 'name' not in attrs:356                self.handle_error('Element view missing attribute name')357            else:358                if attrs['name'] not in self.views:359                    self.views[attrs['name']] = self.format_location()360                elif not self.VARPATTERN.match(attrs['name']):361                    self.handle_error('Element view has duplicate name "%s" (previous %s)' % (attrs['name'], self.views[attrs['name']]))362            self.handlers.append((self.groupViewStartHandler, self.groupViewEndHandler))363            self.variable_scopes.append({ })364            self.item_ids = { }365            self.repeat_depth.append(0)366            self.have_bounds.append(None)367        elif 'repeat' == name:368            if 'count' not in attrs:369                self.handle_error('Element repeat missing attribute count')370            else:371                count = self.check_int_attribute(name, attrs, 'count', None)372                if (count is not None) and (0 >= count):373                    self.handle_error('Element repeat attribute count "%s" is not positive' % (attrs['count'], ))374            self.variable_scopes.append({ })375            self.repeat_depth[-1] += 1376        elif 'param' == name:377            self.check_parameter(attrs)378            self.ignored_depth = 1379        elif ('script' == name) and (not self.repeat_depth[-1]):380            if self.have_script is None:381                self.have_script = self.format_location()382            else:383                self.handle_error('Duplicate script element (previous %s)' % (self.have_script, ))384            self.ignored_depth = 1385        else:386            self.handle_error('Encountered unexpected element %s' % (name, ))387            self.ignored_depth = 1388    def layoutEndHandler(self, name):389        self.variable_scopes.pop()390        if self.repeat_depth[-1]:391            self.repeat_depth[-1] -= 1392        else:393            if not self.generated_element_names:394                for element in self.referenced_elements:395                    if (element not in self.elements) and (not self.VARPATTERN.match(element)):396                        self.handle_error('Element "%s" not found (first referenced at %s)' % (element, self.referenced_elements[element]))397            if not self.generated_group_names:398                for group in self.referenced_groups:399                    if (group not in self.groups) and (not self.VARPATTERN.match(group)):400                        self.handle_error('Group "%s" not found (first referenced at %s)' % (group, self.referenced_groups[group]))401            if not self.views:402                self.handle_error('No view elements found')403            del self.have_script404            self.handlers.pop()405    def elementStartHandler(self, name, attrs):406        if name in self.SHAPES:407            self.check_component(name, attrs)408        elif 'text' == name:409            if 'string' not in attrs:410                self.handle_error('Element text missing attribute string')411            align = self.check_int_attribute(name, attrs, 'align', None)412            if (align is not None) and ((0 > align) or (2 < align)):413                self.handle_error('Element text attribute align "%s" not in valid range 0-2' % (attrs['align'], ))414            self.check_component(name, attrs)415        elif 'simplecounter' == name:416            maxstate = self.check_int_attribute(name, attrs, 'maxstate', None)417            if (maxstate is not None) and (0 > maxstate):418                self.handle_error('Element simplecounter attribute maxstate "%s" is negative' % (attrs['maxstate'], ))419            digits = self.check_int_attribute(name, attrs, 'digits', None)420            if (digits is not None) and (0 >= digits):421                self.handle_error('Element simplecounter attribute digits "%s" is not positive' % (attrs['digits'], ))422            align = self.check_int_attribute(name, attrs, 'align', None)423            if (align is not None) and ((0 > align) or (2 < align)):424                self.handle_error('Element simplecounter attribute align "%s" not in valid range 0-2' % (attrs['align'], ))425            self.check_component(name, attrs)426        elif 'image' == name:427            self.have_file = 'file' in attrs428            self.have_data = None429            self.check_component(name, attrs)430        elif 'reel' == name:431            # TODO: validate symbollist and improve validation of other attributes432            self.check_int_attribute(name, attrs, 'stateoffset', None)433            numsymbolsvisible = self.check_int_attribute(name, attrs, 'numsymbolsvisible', None)434            if (numsymbolsvisible is not None) and (0 >= numsymbolsvisible):435                self.handle_error('Element reel attribute numsymbolsvisible "%s" not positive' % (attrs['numsymbolsvisible'], ))436            reelreversed = self.check_int_attribute(name, attrs, 'reelreversed', None)437            if (reelreversed is not None) and ((0 > reelreversed) or (1 < reelreversed)):438                self.handle_error('Element reel attribute reelreversed "%s" not in valid range 0-1' % (attrs['reelreversed'], ))439            beltreel = self.check_int_attribute(name, attrs, 'beltreel', None)440            if (beltreel is not None) and ((0 > beltreel) or (1 < beltreel)):441                self.handle_error('Element reel attribute beltreel "%s" not in valid range 0-1' % (attrs['beltreel'], ))442            self.check_component(name, attrs)443        else:444            self.handle_error('Encountered unexpected element %s' % (name, ))445            self.ignored_depth = 1446    def elementEndHandler(self, name):447        self.handlers.pop()448    def componentStartHandler(self, name, attrs):449        if 'bounds' == name:450            state = self.check_int_attribute(name, attrs, 'state', 0)451            if state is not None:452                if 0 > state:453                    self.handle_error('Element bounds attribute state "%s" is negative' % (attrs['state'], ))454                if state in self.have_bounds[-1]:455                    self.handle_error('Duplicate bounds for state %d (previous %s)' % (state, self.have_bounds[-1][state]))456                else:457                    self.have_bounds[-1][state] = self.format_location()458            self.check_bounds(attrs)459        elif 'color' == name:460            state = self.check_int_attribute(name, attrs, 'state', 0)461            if state is not None:462                if 0 > state:463                    self.handle_error('Element color attribute state "%s" is negative' % (attrs['state'], ))464                if state in self.have_color[-1]:465                    self.handle_error('Duplicate color for state %d (previous %s)' % (state, self.have_color[-1][state]))466                else:467                    self.have_color[-1][state] = self.format_location()468            self.check_color(attrs)469        self.ignored_depth = 1470    def componentEndHandler(self, name):471        self.have_bounds.pop()472        self.have_color.pop()473        self.handlers.pop()474    def imageComponentStartHandler(self, name, attrs):475        if 'data' == name:476            if self.have_data is not None:477                self.handle_error('Element image has multiple data child elements (previous %s)' % (self.have_data))478            else:479                self.have_data = self.format_location()480                if self.have_file:481                    self.handle_error('Element image has attribute file and child element data')482            self.ignored_depth = 1483        else:484            self.componentStartHandler(name, attrs)485    def imageComponentEndHandler(self, name):486        if (not self.have_file) and (self.have_data is None):487            self.handle_error('Element image missing attribute file or child element data')488        del self.have_file489        del self.have_data490        self.componentEndHandler(name)491    def groupViewStartHandler(self, name, attrs):492        if 'element' == name:493            if 'ref' not in attrs:494                self.handle_error('Element %s missing attribute ref' % (name, ))495            elif attrs['ref'] not in self.referenced_elements:496                self.referenced_elements[attrs['ref']] = self.format_location()497            self.check_view_item(name, attrs)498            self.startViewItem(name)499        elif 'screen' == name:500            if 'index' in attrs:501                index = self.check_int_attribute(name, attrs, 'index', None)502                if (index is not None) and (0 > index):503                    self.handle_error('Element screen attribute index "%s" is negative' % (attrs['index'], ))504                if 'tag' in attrs:505                    self.handle_error('Element screen has both index and tag attributes')506            if 'tag' in attrs:507                tag = attrs['tag']508                self.check_tag(tag, name, 'tag')509                if self.BADTAGPATTERN.search(tag):510                    self.handle_error('Element screen attribute tag "%s" contains invalid characters' % (tag, ))511            self.check_view_item(name, attrs)512            self.startViewItem(name)513        elif 'group' == name:514            if 'ref' not in attrs:515                self.handle_error('Element group missing attribute ref')516            else:517                if attrs['ref'] not in self.referenced_groups:518                    self.referenced_groups[attrs['ref']] = self.format_location()519                if (not self.VARPATTERN.match(attrs['ref'])) and (attrs['ref'] in self.group_collections):520                    for n, l in self.group_collections[attrs['ref']].items():521                        if n not in self.current_collections:522                            self.current_collections[n] = l523                        else:524                            self.handle_error('Element group instantiates collection with duplicate name "%s" from %s (previous %s)' % (n, l, self.current_collections[n]))525            self.startViewItem(name)526        elif 'repeat' == name:527            if 'count' not in attrs:528                self.handle_error('Element repeat missing attribute count')529            else:530                count = self.check_int_attribute(name, attrs, 'count', None)531                if (count is not None) and (0 >= count):532                    self.handle_error('Element repeat attribute count "%s" is negative' % (attrs['count'], ))533            self.variable_scopes.append({ })534            self.repeat_depth[-1] += 1535        elif 'collection' == name:536            if 'name' not in attrs:537                self.handle_error('Element collection missing attribute name')538            elif not self.VARPATTERN.match(attrs['name']):539                if attrs['name'] not in self.current_collections:540                    self.current_collections[attrs['name']] = self.format_location()541                else:542                    self.handle_error('Element collection has duplicate name (previous %s)' % (self.current_collections[attrs['name']], ))543            if attrs.get('visible', 'yes') not in self.YESNO:544                self.handle_error('Element collection attribute visible "%s" is not "yes" or "no"' % (attrs['visible'], ))545            self.variable_scopes.append({ })546            self.collection_depth += 1547        elif 'param' == name:548            self.check_parameter(attrs)549            self.ignored_depth = 1550        elif 'bounds' == name:551            if self.have_bounds[-1] is not None:552                self.handle_error('Duplicate element bounds (previous %s)' % (self.have_bounds[-1], ))553            else:554                self.have_bounds[-1] = self.format_location()555            self.check_bounds(attrs)556            if self.repeat_depth[-1]:557                self.handle_error('Element bounds inside repeat')558            elif self.collection_depth:559                self.handle_error('Element bounds inside collection')560            self.ignored_depth = 1561        else:562            self.handle_error('Encountered unexpected element %s' % (name, ))563            self.ignored_depth = 1564    def groupViewEndHandler(self, name):565        self.variable_scopes.pop()566        if 'collection' == name:567            self.collection_depth -= 1568        elif self.repeat_depth[-1]:569            self.repeat_depth[-1] -= 1570        else:571            del self.item_ids572            self.current_collections = None573            self.repeat_depth.pop()574            self.have_bounds.pop()575            self.handlers.pop()576    def viewItemStartHandler(self, name, attrs):577        if 'animate' == name:578            if isinstance(self.have_bounds[-1], dict):579                if 'inputtag' in attrs:580                    if 'name' in attrs:581                        self.handle_error('Element animate has both attribute inputtag and attribute name')582                    self.check_tag(attrs['inputtag'], name, 'inputtag')583                elif 'name' not in attrs:584                    self.handle_error('Element animate has neither attribute inputtag nor attribute name')585                self.check_int_attribute(name, attrs, 'mask', None)586            else:587                self.handle_error('Encountered unexpected element %s' % (name, ))588        elif 'bounds' == name:589            if self.have_bounds[-1] is None:590                self.have_bounds[-1] = self.format_location()591            elif isinstance(self.have_bounds[-1], dict):592                state = self.check_int_attribute(name, attrs, 'state', 0)593                if state is not None:594                    if 0 > state:595                        self.handle_error('Element bounds attribute state "%s" is negative' % (attrs['state'], ))596                    if state in self.have_bounds[-1]:597                        self.handle_error('Duplicate bounds for state %d (previous %s)' % (state, self.have_bounds[-1][state]))598                    else:599                        self.have_bounds[-1][state] = self.format_location()600            else:601                self.handle_error('Duplicate element bounds (previous %s)' % (self.have_bounds[-1], ))602            self.check_bounds(attrs)603        elif 'orientation' == name:604            self.check_orientation(attrs)605        elif 'color' == name:606            if self.have_color[-1] is None:607                self.have_color[-1] = self.format_location()608            elif isinstance(self.have_color[-1], dict):609                state = self.check_int_attribute(name, attrs, 'state', 0)610                if state is not None:611                    if 0 > state:612                        self.handle_error('Element color attribute state "%s" is negative' % (attrs['state'], ))613                    if state in self.have_color[-1]:614                        self.handle_error('Duplicate color for state %d (previous %s)' % (state, self.have_color[-1][state]))615                    else:616                        self.have_color[-1][state] = self.format_location()617            else:618                self.handle_error('Duplicate element color (previous %s)' % (self.have_color[-1], ))619            self.check_color(attrs)620        elif ('xscroll' == name) or ('yscroll' == name):621            have_scroll = self.have_xscroll if 'xscroll' == name else self.have_yscroll622            if have_scroll[-1] is None:623                self.handle_error('Encountered unexpected element %s' % (name, ))624            elif have_scroll[-1]:625                self.handle_error('Duplicate element %s' % (name, ))626            else:627                have_scroll[-1] = self.format_location()628                self.check_float_attribute(name, attrs, 'size', 1.0)629                if (attrs.get('wrap', 'no') not in self.YESNO) and (not self.VARPATTERN.match(attrs['wrap'])):630                    self.handle_error('Element %s attribute wrap "%s" is not "yes" or "no"' % (name, attrs['wrap']))631                if 'inputtag' in attrs:632                    if 'name' in attrs:633                        self.handle_error('Element %s has both attribute inputtag and attribute name' % (name, ))634                    self.check_tag(attrs['inputtag'], name, 'inputtag')635                self.check_int_attribute(name, attrs, 'mask', None)636                self.check_int_attribute(name, attrs, 'min', None)637                self.check_int_attribute(name, attrs, 'max', None)638        else:639            self.handle_error('Encountered unexpected element %s' % (name, ))640        self.ignored_depth = 1641    def viewItemEndHandler(self, name):642        self.have_bounds.pop()643        self.have_orientation.pop()644        self.have_color.pop()645        self.have_xscroll.pop()646        self.have_yscroll.pop()647        self.handlers.pop()648    def setDocumentLocator(self, locator):649        self.locator = locator650        super().setDocumentLocator(locator)651    def startDocument(self):652        self.handlers = [(self.rootStartHandler, self.rootEndHandler)]653        self.ignored_depth = 0...test_handlebpmnerror.py
Source:test_handlebpmnerror.py  
...24def test_handlebpmnerror_calls_requests(mock, engine_url):25    handle_error = pycamunda.externaltask.HandleBPMNError(26        url=engine_url, worker_id='1', id_='anId', error_code='anErrorCode'27    )28    handle_error()29    assert mock.called30    assert mock.call_args[1]['method'].upper() == 'POST'31@unittest.mock.patch('requests.Session.request', raise_requests_exception_mock)32def test_handlebpmnerror_raises_pycamunda_exception(engine_url):33    handle_error = pycamunda.externaltask.HandleBPMNError(34        url=engine_url, worker_id='1', id_='anId', error_code='anErrorCode'35    )36    with pytest.raises(pycamunda.PyCamundaException):37        handle_error()38@unittest.mock.patch('requests.Session.request', not_ok_response_mock)39@unittest.mock.patch('pycamunda.base._raise_for_status')40def test_handlebpmnerror_raises_for_status(mock, engine_url):41    handle_error = pycamunda.externaltask.HandleBPMNError(42        url=engine_url, worker_id='1', id_='anId', error_code='anErrorCode'43    )44    handle_error()45    assert mock.called46@unittest.mock.patch('requests.Session.request', unittest.mock.MagicMock())47def test_handlebpmnerror_returns_none(engine_url):48    handle_error = pycamunda.externaltask.HandleBPMNError(49        url=engine_url, worker_id='1', id_='anId', error_code='anErrorCode'50    )51    result = handle_error()...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!!
