Best Python code snippet using gherkin-python
views.py
Source:views.py  
...820            col_idx = headers.index(col_name)821        except ValueError:822            return None823        return {'col_idx': col_idx, 'desc': sort.get('desc', False)}824    def reject_nones(xs):825        return [x for x in xs if x is not None]826    return reject_nones(parse_sorting(s) for s in sorting)827def dev_only_ckan_check_permissions(request):828    if settings.PRODUCTION:829        raise Http404('View does not exist in production')830    # Uncomment to simulate user not logged in to CKAN831    # from django.http import HttpResponseForbidden832    # return HttpResponseForbidden()833    # organisations = [834    #     'anu-abc-upload', 'bpa-sepsis', 'australian-microbiome', 'bpa-project-documentation', 'bpa-barcode',835    #     'bioplatforms-australia', 'bpa-base', 'bpa-great-barrier-reef', 'incoming-data', 'bpa-marine-microbes',836    #     'bpa-melanoma', 'bpa-omg', 'bpa-stemcells', 'bpa-wheat-cultivars', 'bpa-wheat-pathogens-genomes',837    #     'bpa-wheat-pathogens-transcript']838    organisations = ['australian-microbiome']839    data = json.dumps({840        'email': settings.CKAN_DEVELOPMENT_USER_EMAIL,...ast_builder.py
Source:ast_builder.py  
...67            if node.get_single('DataTable'):68                step_argument = node.get_single('DataTable')69            elif node.get_single('DocString'):70                step_argument = node.get_single('DocString')71            return self.reject_nones({72                'type': node.rule_type,73                'location': self.get_location(step_line),74                'keyword': step_line.matched_keyword,75                'text': step_line.matched_text,76                'argument': step_argument77            })78        elif node.rule_type == 'DocString':79            separator_token = node.get_tokens('DocStringSeparator')[0]80            content_type = (separator_token.matched_text if len(separator_token.matched_text) > 081                            else None)82            line_tokens = node.get_tokens('Other')83            content = '\n'.join([t.matched_text for t in line_tokens])84            return self.reject_nones({85                'type': node.rule_type,86                'location': self.get_location(separator_token),87                'contentType': content_type,88                'content': content89            })90        elif node.rule_type == 'DataTable':91            rows = self.get_table_rows(node)92            return self.reject_nones({93                'type': node.rule_type,94                'location': rows[0]['location'],95                'rows': rows,96            })97        elif node.rule_type == 'Background':98            background_line = node.get_token('BackgroundLine')99            description = self.get_description(node)100            steps = self.get_steps(node)101            return self.reject_nones({102                'type': node.rule_type,103                'location': self.get_location(background_line),104                'keyword': background_line.matched_keyword,105                'name': background_line.matched_text,106                'description': description,107                'steps': steps108            })109        elif node.rule_type == 'Scenario_Definition':110            tags = self.get_tags(node)111            scenario_node = node.get_single('Scenario')112            if scenario_node:113                scenario_line = scenario_node.get_token('ScenarioLine')114                description = self.get_description(scenario_node)115                steps = self.get_steps(scenario_node)116                return self.reject_nones({117                    'type': scenario_node.rule_type,118                    'tags': tags,119                    'location': self.get_location(scenario_line),120                    'keyword': scenario_line.matched_keyword,121                    'name': scenario_line.matched_text,122                    'description': description,123                    'steps': steps124                })125            else:126                scenario_outline_node = node.get_single('ScenarioOutline')127                if not scenario_outline_node:128                    raise RuntimeError('Internal grammar error')129                scenario_outline_line = scenario_outline_node.get_token('ScenarioOutlineLine')130                description = self.get_description(scenario_outline_node)131                steps = self.get_steps(scenario_outline_node)132                examples = scenario_outline_node.get_items('Examples_Definition')133                return self.reject_nones({134                    'type': scenario_outline_node.rule_type,135                    'tags': tags,136                    'location': self.get_location(scenario_outline_line),137                    'keyword': scenario_outline_line.matched_keyword,138                    'name': scenario_outline_line.matched_text,139                    'description': description,140                    'steps': steps,141                    'examples': examples142                })143        elif node.rule_type == 'Examples_Definition':144            tags = self.get_tags(node)145            examples_node = node.get_single('Examples')146            examples_line = examples_node.get_token('ExamplesLine')147            description = self.get_description(examples_node)148            examples_table = examples_node.get_single('Examples_Table')149            return self.reject_nones({150                'type': examples_node.rule_type,151                'tags': tags,152                'location': self.get_location(examples_line),153                'keyword': examples_line.matched_keyword,154                'name': examples_line.matched_text,155                'description': description,156                'tableHeader': examples_table['tableHeader'] if examples_table else None,157                'tableBody': examples_table['tableBody'] if examples_table else None158            })159        elif node.rule_type == 'Examples_Table':160            rows = self.get_table_rows(node)161            return self.reject_nones({162                'tableHeader': rows[0],163                'tableBody': rows[1:]164            })165        elif node.rule_type == 'Description':166            line_tokens = node.get_tokens('Other')167            # Trim trailing empty lines168            last_non_empty = next(i for i, j in reversed(list(enumerate(line_tokens)))169                                  if j.matched_text)170            description = '\n'.join([token.matched_text for token in171                                     line_tokens[:last_non_empty + 1]])172            return description173        elif node.rule_type == 'Feature':174            header = node.get_single('Feature_Header')175            if not header:176                return177            tags = self.get_tags(header)178            feature_line = header.get_token('FeatureLine')179            if not feature_line:180                return181            children = []182            background = node.get_single('Background')183            if (background):184                children.append(background)185            children = children + node.get_items('Scenario_Definition')186            description = self.get_description(header)187            language = feature_line.matched_gherkin_dialect188            return self.reject_nones({189                'type': node.rule_type,190                'tags': tags,191                'location': self.get_location(feature_line),192                'language': language,193                'keyword': feature_line.matched_keyword,194                'name': feature_line.matched_text,195                'description': description,196                'children': children197            })198        elif node.rule_type == 'GherkinDocument':199            feature = node.get_single('Feature')200            return self.reject_nones({201                'type': node.rule_type,202                'feature': feature,203                'comments': self.comments204            })205        else:206            return node207    def reject_nones(self, values):...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!!
