How to use _change_dialect method in Gherkin-python

Best Python code snippet using gherkin-python

parser.py

Source:parser.py Github

copy

Full Screen

...19 """Gherkin 3 token matcher that always uses the given language."""20 def __init__(self, dialect_name='en'):21 self.actual_dialect_name = dialect_name22 super().__init__(dialect_name=dialect_name)23 def _change_dialect(self, dialect_name, location=None):24 """Force the dialect name given in the constructor."""25 super()._change_dialect(self.actual_dialect_name, location=location)26def cell_values(row):27 """Extract cell values from a table header or row."""28 return tuple(cell['value'] for cell in row['cells'])29class Node(object):30 """31 A base parse node.32 """33 def __init__(self, parsed, filename=None):34 """Construct the node from Gherkin parse results."""35 self.line = parsed['location']['line']36 self.col = parsed['location']['column']37 self.filename = filename38 @property39 def feature(self):...

Full Screen

Full Screen

token_matcher.py

Source:token_matcher.py Github

copy

Full Screen

...4class TokenMatcher(object):5 LANGUAGE_RE = re.compile(r"^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$")6 def __init__(self, dialect_name='en'):7 self._default_dialect_name = dialect_name8 self._change_dialect(dialect_name)9 self.reset()10 def reset(self):11 if self.dialect_name != self._default_dialect_name:12 self._change_dialect(self._default_dialect_name)13 self._indent_to_remove = 014 self._active_doc_string_separator = None15 def match_FeatureLine(self, token):16 return self._match_title_line(token, 'FeatureLine', self.dialect.feature_keywords)17 def match_ScenarioLine(self, token):18 return self._match_title_line(token, 'ScenarioLine', self.dialect.scenario_keywords)19 def match_ScenarioOutlineLine(self, token):20 return self._match_title_line(token, 'ScenarioOutlineLine',21 self.dialect.scenario_outline_keywords)22 def match_BackgroundLine(self, token):23 return self._match_title_line(token, 'BackgroundLine', self.dialect.background_keywords)24 def match_ExamplesLine(self, token):25 return self._match_title_line(token, 'ExamplesLine', self.dialect.examples_keywords)26 def match_TableRow(self, token):27 if not token.line.startswith('|'):28 return False29 # TODO: indent30 self._set_token_matched(token, 'TableRow', items=token.line.table_cells)31 return True32 def match_StepLine(self, token):33 keywords = (self.dialect.given_keywords +34 self.dialect.when_keywords +35 self.dialect.then_keywords +36 self.dialect.and_keywords +37 self.dialect.but_keywords)38 for keyword in (k for k in keywords if token.line.startswith(k)):39 title = token.line.get_rest_trimmed(len(keyword))40 self._set_token_matched(token, 'StepLine', title, keyword)41 return True42 return False43 def match_Comment(self, token):44 if not token.line.startswith('#'):45 return False46 text = token.line._line_text # take the entire line, including leading space47 self._set_token_matched(token, 'Comment', text, indent=0)48 return True49 def match_Empty(self, token):50 if not token.line.is_empty():51 return False52 self._set_token_matched(token, 'Empty', indent=0)53 return True54 def match_Language(self, token):55 match = self.LANGUAGE_RE.match(token.line.get_line_text())56 if not match:57 return False58 dialect_name = match.group(1)59 self._set_token_matched(token, 'Language', dialect_name)60 self._change_dialect(dialect_name, token.location)61 return True62 def match_TagLine(self, token):63 if not token.line.startswith('@'):64 return False65 self._set_token_matched(token, 'TagLine', items=token.line.tags)66 return True67 def match_DocStringSeparator(self, token):68 if not self._active_doc_string_separator:69 # open70 return (self._match_DocStringSeparator(token, '"""', True) or71 self._match_DocStringSeparator(token, '```', True))72 else:73 # close74 return self._match_DocStringSeparator(token, self._active_doc_string_separator, False)75 def _match_DocStringSeparator(self, token, separator, is_open):76 if not token.line.startswith(separator):77 return False78 content_type = None79 if is_open:80 content_type = token.line.get_rest_trimmed(len(separator))81 self._active_doc_string_separator = separator82 self._indent_to_remove = token.line.indent83 else:84 self._active_doc_string_separator = None85 self._indent_to_remove = 086 # TODO: Use the separator as keyword. That's needed for pretty printing.87 self._set_token_matched(token, 'DocStringSeparator', content_type)88 return True89 def match_Other(self, token):90 # take the entire line, except removing DocString indents91 text = token.line.get_line_text(self._indent_to_remove)92 self._set_token_matched(token, 'Other', self._unescaped_docstring(text), indent=0)93 return True94 def match_EOF(self, token):95 if not token.eof():96 return False97 self._set_token_matched(token, 'EOF')98 return True99 def _match_title_line(self, token, token_type, keywords):100 for keyword in (k for k in keywords if token.line.startswith_title_keyword(k)):101 title = token.line.get_rest_trimmed(len(keyword) + len(':'))102 self._set_token_matched(token, token_type, title, keyword)103 return True104 return False105 def _set_token_matched(self, token, matched_type, text=None,106 keyword=None, indent=None, items=None):107 if items is None:108 items = []109 token.matched_type = matched_type110 # text == '' should not result in None111 token.matched_text = text.rstrip('\r\n') if text is not None else None112 token.matched_keyword = keyword113 if indent is not None:114 token.matched_indent = indent115 else:116 token.matched_indent = token.line.indent if token.line else 0117 token.matched_items = items118 token.location['column'] = token.matched_indent + 1119 token.matched_gherkin_dialect = self.dialect_name120 def _change_dialect(self, dialect_name, location=None):121 dialect = Dialect.for_name(dialect_name)122 if not dialect:123 raise NoSuchLanguageException(dialect_name, location)124 self.dialect_name = dialect_name125 self.dialect = dialect126 def _unescaped_docstring(self, text):...

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:

YouTube

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

Run Gherkin-python 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?

Helpful

NotHelpful