Best Python code snippet using lemoncheesecake
tokens.py
Source:tokens.py
1# Copyright 2008-2015 Nokia Networks2# Copyright 2016- Robot Framework Foundation3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15from robot.utils import py2to316from robot.variables import VariableIterator17@py2to318class Token(object):19 """Token representing piece of Robot Framework data.20 Each token has type, value, line number, column offset and end column21 offset in :attr:`type`, :attr:`value`, :attr:`lineno`, :attr:`col_offset`22 and :attr:`end_col_offset` attributes, respectively. Tokens representing23 error also have their error message in :attr:`error` attribute.24 Token types are declared as class attributes.25 """26 SETTING_HEADER = 'SETTING_HEADER'27 VARIABLE_HEADER = 'VARIABLE_HEADER'28 TESTCASE_HEADER = 'TESTCASE_HEADER'29 KEYWORD_HEADER = 'KEYWORD_HEADER'30 COMMENT_HEADER = 'COMMENT_HEADER'31 TESTCASE_NAME = 'TESTCASE_NAME'32 KEYWORD_NAME = 'KEYWORD_NAME'33 DOCUMENTATION = 'DOCUMENTATION'34 SUITE_SETUP = 'SUITE_SETUP'35 SUITE_TEARDOWN = 'SUITE_TEARDOWN'36 METADATA = 'METADATA'37 TEST_SETUP = 'TEST_SETUP'38 TEST_TEARDOWN = 'TEST_TEARDOWN'39 TEST_TEMPLATE = 'TEST_TEMPLATE'40 TEST_TIMEOUT = 'TEST_TIMEOUT'41 FORCE_TAGS = 'FORCE_TAGS'42 DEFAULT_TAGS = 'DEFAULT_TAGS'43 LIBRARY = 'LIBRARY'44 RESOURCE = 'RESOURCE'45 VARIABLES = 'VARIABLES'46 SETUP = 'SETUP'47 TEARDOWN = 'TEARDOWN'48 TEMPLATE = 'TEMPLATE'49 TIMEOUT = 'TIMEOUT'50 TAGS = 'TAGS'51 ARGUMENTS = 'ARGUMENTS'52 RETURN = 'RETURN'53 NAME = 'NAME'54 VARIABLE = 'VARIABLE'55 ARGUMENT = 'ARGUMENT'56 ASSIGN = 'ASSIGN'57 KEYWORD = 'KEYWORD'58 WITH_NAME = 'WITH_NAME'59 FOR = 'FOR'60 FOR_SEPARATOR = 'FOR_SEPARATOR'61 OLD_FOR_INDENT = 'OLD_FOR_INDENT'62 END = 'END'63 SEPARATOR = 'SEPARATOR'64 COMMENT = 'COMMENT'65 CONTINUATION = 'CONTINUATION'66 EOL = 'EOL'67 EOS = 'EOS'68 ERROR = 'ERROR'69 FATAL_ERROR = 'FATAL_ERROR'70 NON_DATA_TOKENS = (71 SEPARATOR,72 COMMENT,73 CONTINUATION,74 EOL,75 EOS76 )77 SETTING_TOKENS = (78 DOCUMENTATION,79 SUITE_SETUP,80 SUITE_TEARDOWN,81 METADATA,82 TEST_SETUP,83 TEST_TEARDOWN,84 TEST_TEMPLATE,85 TEST_TIMEOUT,86 FORCE_TAGS,87 DEFAULT_TAGS,88 LIBRARY,89 RESOURCE,90 VARIABLES,91 SETUP,92 TEARDOWN,93 TEMPLATE,94 TIMEOUT,95 TAGS,96 ARGUMENTS,97 RETURN98 )99 HEADER_TOKENS = (100 SETTING_HEADER,101 VARIABLE_HEADER,102 TESTCASE_HEADER,103 KEYWORD_HEADER,104 COMMENT_HEADER105 )106 ALLOW_VARIABLES = (107 NAME,108 ARGUMENT,109 TESTCASE_NAME,110 KEYWORD_NAME111 )112 __slots__ = ['type', 'value', 'lineno', 'col_offset', 'error']113 def __init__(self, type=None, value='', lineno=-1, col_offset=-1, error=None):114 self.type = type115 self.value = value116 self.lineno = lineno117 self.col_offset = col_offset118 self.error = error119 @property120 def end_col_offset(self):121 if self.col_offset == -1:122 return -1123 return self.col_offset + len(self.value)124 def set_error(self, error, fatal=False):125 self.type = Token.ERROR if not fatal else Token.FATAL_ERROR126 self.error = error127 def tokenize_variables(self):128 """Tokenizes possible variables in token value.129 Yields the token itself if the token does not allow variables (see130 :attr:`Token.ALLOW_VARIABLES`) or its value does not contain131 variables. Otherwise yields variable tokens as well as tokens132 before, after, or between variables so that they have the same133 type as the original token.134 """135 if self.type not in Token.ALLOW_VARIABLES:136 return self._tokenize_no_variables()137 variables = VariableIterator(self.value)138 if not variables:139 return self._tokenize_no_variables()140 return self._tokenize_variables(variables)141 def _tokenize_no_variables(self):142 yield self143 def _tokenize_variables(self, variables):144 lineno = self.lineno145 col_offset = self.col_offset146 remaining = ''147 for before, variable, remaining in variables:148 if before:149 yield Token(self.type, before, lineno, col_offset)150 col_offset += len(before)151 yield Token(Token.VARIABLE, variable, lineno, col_offset)152 col_offset += len(variable)153 if remaining:154 yield Token(self.type, remaining, lineno, col_offset)155 def __unicode__(self):156 return self.value157 def __repr__(self):158 error = '' if not self.error else ', %r' % self.error159 return 'Token(%s, %r, %s, %s%s)' % (self.type, self.value,160 self.lineno, self.col_offset,161 error)162 def __eq__(self, other):163 if not isinstance(other, Token):164 return False165 return (self.type == other.type and166 self.value == other.value and167 self.lineno == other.lineno and168 self.col_offset == other.col_offset and169 self.error == other.error)170 def __ne__(self, other):171 return not self == other172class EOS(Token):173 """Token representing end of statement."""174 __slots__ = []175 def __init__(self, lineno=-1, col_offset=-1):176 Token.__init__(self, Token.EOS, '', lineno, col_offset)177 @classmethod178 def from_token(cls, token):...
html_util.py
Source:html_util.py
1from io import StringIO2from fitnesse.context import SuiteResponder, PageCrawlerImpl, PageData, PathParser, WikiPage, WikiPagePath3class HtmlUtil:4 @staticmethod5 def testable_html(page_data: PageData, include_suite_setup: bool, page_crawler: PageCrawlerImpl, path_parser: PathParser) -> str:6 wiki_page: WikiPage = page_data.get_wiki_page()7 string_io: StringIO = StringIO()8 if page_data.has_attribute("Test"):9 if include_suite_setup:10 suite_setup: WikiPage = page_crawler.get_inherited_page(SuiteResponder.SUITE_SETUP_NAME, wiki_page)11 if suite_setup is not None:12 page_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(suite_setup)13 page_path_name: str = path_parser.render(page_path)14 string_io.writelines(["!include -setup .", page_path_name, "\n"])15 setup: WikiPage = page_crawler.get_inherited_page("SetUp", wiki_page)16 if setup is not None:17 setup_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(setup)18 setup_path_name: str = path_parser.render(setup_path)19 string_io.writelines(["!include -setup .", setup_path_name, "\n"])20 string_io.writelines([page_data.get_content()])21 if page_data.has_attribute("Test"):22 teardown: WikiPage = page_crawler.get_inherited_page("TearDown", wiki_page)23 if teardown is not None:24 tear_down_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(teardown)25 tear_down_path_name: str = path_parser.render(tear_down_path)26 string_io.writelines(["!include -teardown .", tear_down_path_name, "\n"])27 if include_suite_setup:28 suite_teardown: WikiPage = page_crawler.get_inherited_page(SuiteResponder.SUITE_TEARDOWN_NAME, wiki_page)29 if suite_teardown is not None:30 page_path: WikiPagePath = wiki_page.get_page_crawler().get_full_path(suite_teardown)31 page_path_name: str = path_parser.render(page_path)32 string_io.writelines(["!include -teardown .", page_path_name, "\n"])33 page_data.set_content(string_io.getvalue())...
__st__.py
Source:__st__.py
...10 INFO('suite_setup')11 open_browser()12 mgr_login()13# åå§æ¸
é¤14def suite_teardown():15 INFO('suite_teardown')16 webDriver = GSTORE['webDriver']...
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!!