Best Python code snippet using autotest_python
preconfigs.py
Source:preconfigs.py
1import os2class PreconfigManager(object):3 _preconfigs = {}4 _is_init = False5 def _get_preconfig_path(self, suffix):6 """\7 Get the absolute path to a prefix directory or file.8 suffix: list of suffixes after the 'preconfigs' directory to navigate to9 E.g., ['metrics', 'abc'] gives the path to10 <tko>/preconfigs/metrics/abc11 """12 rel_path = os.path.join(os.path.dirname(__file__), 'preconfigs',13 *suffix)14 return os.path.abspath(rel_path)15 def _init_preconfigs(self):16 """\17 Read the names of all the preconfigs from disk and store them in the18 _preconfigs dictionary.19 """20 if not self._is_init:21 # Read the data22 self._preconfigs['metrics'] = dict.fromkeys(23 os.listdir(self._get_preconfig_path(['metrics'])))24 self._preconfigs['qual'] = dict.fromkeys(25 os.listdir(self._get_preconfig_path(['qual'])))26 self._is_init = True27 def _read_preconfig(self, name, type):28 """\29 Populate the _preconfigs dictionary entry for the preconfig described30 by the given parameters. If the preconfig has already been loaded,31 do nothing.32 name: specific name of the preconfig33 type: 'metrics' or 'qual'34 """35 if self._preconfigs[type][name] is not None:36 return37 self._preconfigs[type][name] = {}38 path = self._get_preconfig_path([type, name])39 config = open(path)40 try:41 for line in config:42 parts = line.split(':')43 self._preconfigs[type][name][parts[0]] = parts[1].strip()44 finally:45 config.close()46 def get_preconfig(self, name, type):47 self._init_preconfigs()48 self._read_preconfig(name, type)49 return self._preconfigs[type][name]50 def all_preconfigs(self):51 self._init_preconfigs()52 return dict(self._preconfigs)...
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!!