How to use config_as_dict method in autotest

Best Python code snippet using autotest_python

test_config_model.py

Source:test_config_model.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""pype.config_model."""3import json4from os.path import dirname, join5from pype import config_model6class TestPypeConfigModel: # noqa: D1017 def test_init(self) -> None: # noqa: D1028 config = config_model.Configuration()9 assert config.asdict() == {10 'plugins': [],11 'aliases': [],12 'core_config': None13 }14 def test_loggingconfig(self) -> None: # noqa: D10215 config = config_model.Configuration()16 config.core_config = config_model.ConfigurationCore()17 config.core_config.logging = config_model.ConfigurationCoreLogging()18 logging_as_dict = config.core_config.logging.asdict()19 assert logging_as_dict == {20 'directory': '',21 'enabled': False,22 'level': 'INFO',23 'pattern':24 r'%(asctime)s %(levelname)s %(name)s %(message)s',25 }26 config_as_dict = config.asdict()27 assert config_as_dict == {28 'plugins': [],29 'aliases': [],30 'core_config': {31 'logging': logging_as_dict32 }33 }34 def test_aliasconfig(self) -> None: # noqa: D10235 config = config_model.Configuration()36 config.aliases.append(config_model.ConfigurationAlias(37 'myalias', 'pype config'38 ))39 alias_as_dict = config.aliases[0].asdict()40 assert alias_as_dict == {41 'alias': 'myalias',42 'command': 'pype config'43 }44 config_as_dict = config.asdict()45 assert config_as_dict == {46 'plugins': [],47 'aliases': [48 alias_as_dict49 ],50 'core_config': None51 }52 def test_pluginconfig(self) -> None: # noqa: D10253 config = config_model.Configuration()54 config.plugins.append(config_model.ConfigurationPlugin(55 'p1', '/somewhere', ['bastitee']56 ))57 plugin_as_dict = config.plugins[0].asdict()58 assert plugin_as_dict == {59 'name': 'p1',60 'path': '/somewhere',61 'users': [62 'bastitee'63 ]64 }65 config_as_dict = config.asdict()66 assert config_as_dict == {67 'plugins': [plugin_as_dict],68 'aliases': [],69 'core_config': None70 }71 def test_to_from_json(self) -> None: # noqa: D10272 config = config_model.Configuration()73 config.plugins.append(config_model.ConfigurationPlugin(74 'p1', '/somewhere', ['bastitee']75 ))76 config.aliases.append(config_model.ConfigurationAlias(77 'myalias', 'pype config'78 ))79 config.core_config = config_model.ConfigurationCore()80 config.core_config.logging = config_model.ConfigurationCoreLogging()81 json_str_expected = json.dumps(json.load(82 open(join(dirname(__file__), 'test_config_model.json'))83 ), indent=4)...

Full Screen

Full Screen

interface_mib_utililities.py

Source:interface_mib_utililities.py Github

copy

Full Screen

1#2# Copyright 2021 Splunk Inc.3#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.15#16import logging17from splunk_connect_for_snmp_poller.manager.realtime.interface_mib import InterfaceMib18from splunk_connect_for_snmp_poller.utilities import multi_key_lookup19from ..variables import (20 enricher_additional_varbinds,21 enricher_existing_varbinds,22 enricher_name,23 enricher_oid_family,24)25logger = logging.getLogger(__name__)26def __network_interface_enricher_attributes(config_as_dict, oid_family, varbinds_type):27 # TODO: we just assume here the whole structre of the poller's configuration28 # main file. If such section does not exist we simply do not anything.29 result = multi_key_lookup(30 config_as_dict, (enricher_name, enricher_oid_family, oid_family, varbinds_type)31 )32 return result or []33def extract_network_interface_data_from_additional_config(config_as_dict):34 result = {}35 oid_families = config_as_dict[enricher_name][enricher_oid_family]36 for oid_family in oid_families.keys():37 additional_list = __network_interface_enricher_attributes(38 config_as_dict, oid_family, enricher_additional_varbinds39 )40 result[oid_family] = {}41 for el in additional_list:42 for key, values in el.items():43 result[oid_family][key] = values44 return result45def extract_network_interface_data_from_existing_config(config_as_dict):46 splunk_dimensions = __network_interface_enricher_attributes(47 config_as_dict, "IF-MIB", enricher_existing_varbinds48 )49 result = []50 if splunk_dimensions:51 for splunk_dimension in splunk_dimensions:52 result.append(53 {54 "oid_name": f"{InterfaceMib.IF_MIB_METRIC_PREFIX}{splunk_dimension['id']}",55 "splunk_dimension_name": splunk_dimension["name"],56 }57 )58 logger.debug(f"IF-MIB additional attributes for Splunk: {result}")59 return result60def extract_network_interface_data_from_walk(config_as_dict, if_mib_metric_walk_data):61 result = []62 network_data = InterfaceMib(if_mib_metric_walk_data)63 enricher_fields = extract_network_interface_data_from_existing_config(64 config_as_dict65 )66 for data in enricher_fields:67 splunk_dimension = data["splunk_dimension_name"]68 current_result = network_data.extract_custom_field(data["oid_name"])69 if current_result:70 result.append({f"{splunk_dimension}": current_result})...

Full Screen

Full Screen

ConfigUtils.py

Source:ConfigUtils.py Github

copy

Full Screen

1import os2import logging3from configparser import ConfigParser, ExtendedInterpolation4import yaml5import pathlib6class ConfigUtils():7 def __init__(self, pathToConfiguration): 8 assert pathToConfiguration, "Configuration can't be found"9 suffix = pathlib.Path(pathToConfiguration).suffix10 self.config_as_dict = None11 self.multiple_config = None12 if suffix == '.init':13 self.config_as_dict = self.loadConfigParser(pathToConfiguration) 14 elif suffix =='.yaml':15 self.config_as_dict = self.loadYaml(pathToConfiguration) 16 assert self.config_as_dict, "Configuration initialization failed"17 super().__init__() 18 def extractDataFromConfig(self, configParser: ConfigParser, sectionName):19 section_as_dict = {}20 options = configParser.options(sectionName)21 for option in options:22 section_as_dict[option] = configParser.get(sectionName,option)23 return section_as_dict24 def loadConfigParser(self, pathToConfiguration):25 config_as_dict = {}26 config_parser = ConfigParser(interpolation=ExtendedInterpolation())27 if not config_parser.read(pathToConfiguration):28 logging.error("Config file [{}] not found".format(pathToConfiguration))29 raise FileNotFoundError(pathToConfiguration) 30 sections = config_parser.sections()31 for section in sections:32 config_as_dict[section]=self.extractDataFromConfig(config_parser, section)33 defaults = config_parser.defaults()34 default_dict = {}35 for key in defaults:36 default_dict[key] = defaults[key]37 config_as_dict["default_section"] = default_dict38 return config_as_dict39 40 def loadYaml(self, pathToConfiguration):41 multiple_config = []42 try:43 with open(pathToConfiguration, "r") as fh:44 multiple_config = list(yaml.load_all(fh, Loader=yaml.SafeLoader))45 except yaml.YAMLError as exc:46 return exc47 self.multiple_config = multiple_config48 return self.multiple_config[0]49 def getValue(self, sectionName, propertyName, defaultValue=None):50 if propertyName in self.config_as_dict[sectionName]:51 return self.config_as_dict[sectionName][propertyName]52 else:53 return defaultValue 54 55 def hasMultipleConfiguration(self):56 return self.multiple_config and len(self.multiple_config)>157 def getNumberOfConfiguration(self):58 return len(self.multiple_config)59 def setActiveConfiguration(self, index):60 assert index < self.getNumberOfConfiguration(), "No configuration for the index->"+str(index)...

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