How to use get_section_values method in autotest

Best Python code snippet using autotest_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...61 62 def has_subsection(self, key):63 return bool(self.get_subsection_names(key))64 65 def get_section_values(self, key):66 """Returns the data for the given section.67 68 The section `key` can consist of a path like `section:subsection`.69 In that case, the returned dict will be a merge of `[section]`70 and `[section:subsection]` values.71 72 Example :73 74 >>> parser = IniParser(raw_data = \"\"\"\\75 ... [section]76 ... value1 = 177 ... value2 = 278 ... [section:subsection]79 ... value2 = 2280 ... value3 = 381 ... \"\"\")82 >>> section = parser.get_section_values('section:subsection')83 >>> section == {'value1': '1', 'value2': '22', 'value3': '3'}84 True85 86 :param string key: the ini-file section name87 """88 89 parser = self.parser90 section, subsection = parse_full_section_name(key)91 section_dict = self._get_section_dict(parser, section)92 subsection_dict = self._get_section_dict(parser, key)93 if subsection_dict is None:94 raise MissingSection('%s:%s' % (section, subsection))95 values = {}96 if section_dict is not None:97 values.update(section_dict)98 values.update(subsection_dict)99 return values100 101 def _get_section_dict(self, parser, section):102 if section is None or not parser.has_section(section):103 return None104 return dict((option, parser.get(section, option)) for option in parser.options(section))105class ParserAccess(object):106 """Mixin for class wanting to play with an ini file parser"""107 _dict = dict108 109 def get_subsection_values(self, basename):110 keys = self.get_subsection_names(basename)111 return dict((key.split(PATH_SEPARATOR)[1], self.get_section_values(key)) for key in keys)112class ConfigSection(ParserAccess):113 """Represents an ini file section."""114 __metaclass__ = DeclarativeOptionMetaclass115 section = None116 required = True117 allow_extra_options = True118 ignore_extra_options = False119 120 def __init__(self, parser, subsection=None):121 self.subsection = subsection122 if subsection is not None:123 self.name = '%s:%s' % (self.section, self.subsection)124 else:125 self.name = self.section126 self.parser = parser127 self._values = None128 def __getitem__(self, key):129 return self.values[key]130 @property131 def values(self):132 if self._values is None:133 self._values = self._get_values()134 return self._values135 def _get_values(self):136 values = self.get_defaults()137 try:138 raw_values = self.parser.get_section_values(self.name)139 except MissingSection:140 if self.required:141 raise142 return values143 values.update(self.clean_values(raw_values))144 return values145 146 def get_defaults(self):147# return self._dict((option.name, option.default) for option in self._options.itervalues())148 return self._dict((k, option.default) for (k, option) in self._options.items())149 150 def clean_values(self, raw_values):151 values = self._dict()152 raw_values = copy(raw_values)...

Full Screen

Full Screen

env_variables.py

Source:env_variables.py Github

copy

Full Screen

1import configparser2import os3class EnvVariables:4 @staticmethod5 def get_section_values(sections):6 valid_path = "demo.properties"7 cf = configparser.SafeConfigParser()8 cf.read(valid_path)9 env_variables = {}10 for section in sections:11 for key in cf.options(section):12 val = cf.get(section, key, vars=os.environ) # use it here13 # print('### [{}] -> {}: {!r}'.format(section, key, val))14 env_variables[key.upper()] = val15 return env_variables16class Headers:17 content_headers = {18 "Content-type": "application/json",19 "Accept": "application/json",20 }21 content_headers_abbyy = {22 "Content-type": "application/json",23 "Accept": "application/json",24 }25class Endpoint:26 sections = ["APIS"]27 env_variables = EnvVariables.get_section_values(sections)28 abbyy_api = env_variables.get("ABBYY_API")29class Auth:30 auth_sections = ["AUTH"]31 auth_variables = EnvVariables.get_section_values(auth_sections)32 abbyy_appid = auth_variables.get("ABBYY_APPID")...

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 autotest 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