How to use settings_type method in lisa

Best Python code snippet using lisa_python

pc_config.py

Source:pc_config.py Github

copy

Full Screen

1import json2'''3Configuration module of pocketcosmos. Defaults Configuration and stuff live4here.5'''6SETTING_TYPES = ['bool', 'number', 'select']7class ConfigType(object):8 '''Each settings item in PocketCosmos is an instance of this class providing9 a container to store settings information and do some (simple) validation.10 '''11 def __init__(self, name, settings_type, label, defaultvalue, min_value=None,12 max_value=None, values=None, show=True, seqnum=None):13 assert settings_type in SETTING_TYPES, 'invalid setting_type'14 self.name = name15 self.settings_type = settings_type16 self.label = label17 self.defaultvalue = defaultvalue18 self.min_value = min_value19 self.max_value = max_value20 self.values = values21 self.show = show22 self.seqnum = seqnum23 # do some validation to sleep better24 if self.settings_type == 'number':25 valid = (self.min_value is not None) and (self.max_value is not None)26 assert valid, 'number type needs min/max for slider borders!'27 assert self.defaultvalue >= self.min_value, 'default lower than min'28 assert self.defaultvalue <= self.max_value, 'default higher than max'29 elif self.settings_type == 'select':30 valid = self.values is not None31 assert valid, 'select type needs values to select from!'32 assert self.defaultvalue in self.values, 'default not in values!'33 elif self.settings_type == 'bool':34 valid = isinstance(self.defaultvalue, bool)35 assert valid, 'bool default must be a bool!'36 self.value = defaultvalue37 def validate(self, value):38 '''simple input validation called from model when value is set'''39 if self.settings_type == 'number':40 assert value >= self.min_value, '%s lower than min in %s' % (value, self.name)41 assert value <= self.max_value, '%s higher than max %s' % (value, self.name)42 elif self.settings_type == 'select':43 assert value in self.values, 'not in values!'44 elif self.settings_type == 'bool':45 valid = isinstance(value, bool)46 assert valid, 'bool default must be a bool!'47class ConfigModel(object):48 '''container holding all settings items of PocketCosmos app, used by49 ConfigController. Feels like a dict when used by implementing __setitem__,50 __getitem__ and __iter__51 '''52 def __init__(self):53 self.config = {54 # Minimum mass START55 'min_moon_mass': ConfigType(56 name='min_moon_mass',57 settings_type='number',58 label='Minimum moon mass',59 defaultvalue=9,60 min_value=6,61 max_value=11,62 seqnum=8063 ),64 'min_planet_mass': ConfigType(65 name='min_planet_mass',66 settings_type='number',67 label='Minimum planet mass',68 defaultvalue=15,69 min_value=10,70 max_value=20,71 seqnum=9072 ),73 'min_gasgiant_mass': ConfigType(74 name='min_gasgiant_mass',75 settings_type='number',76 label='Minimum gasgiant mass',77 defaultvalue=50,78 min_value=40,79 max_value=100,80 seqnum=10081 ),82 'min_sun_mass': ConfigType(83 name='min_sun_mass',84 settings_type='number',85 label='Minimum sun mass',86 defaultvalue=50000,87 min_value=40000,88 max_value=60000,89 seqnum=11090 ),91 'min_bigsun_mass': ConfigType(92 name='min_bigsun_mass',93 settings_type='number',94 label='Minimum bigsun mass',95 defaultvalue=100000,96 min_value=80000,97 max_value=120000,98 seqnum=12099 ),100 'min_giantsun_mass': ConfigType(101 name='min_giantsun_mass',102 settings_type='number',103 label='Minimum giantsun mass',104 defaultvalue=250000,105 min_value=200000,106 max_value=400000,107 seqnum=130108 ),109 'min_blackhole_mass': ConfigType(110 name='min_blackhole_mass',111 settings_type='number',112 label='Minimum blackhole mass',113 defaultvalue=600000,114 min_value=500000,115 max_value=700000,116 seqnum=140117 ),118 'min_blackhole_mass': ConfigType(119 name='min_blackhole_mass',120 settings_type='number',121 label='Minimum blackhole mass',122 defaultvalue=600000,123 min_value=500000,124 max_value=700000,125 seqnum=150126 ),127 # Minimum mass END128 # Density START129 'moon_density': ConfigType(130 name='moon_density',131 settings_type='number',132 label='Moon density',133 defaultvalue=.1,134 min_value=.05,135 max_value=.15,136 seqnum=160137 ),138 'planet_density': ConfigType(139 name='planet_density',140 settings_type='number',141 label='Planet density',142 defaultvalue=.1,143 min_value=.05,144 max_value=.15,145 seqnum=170146 ),147 'gasgiant_density': ConfigType(148 name='gasgiant_density',149 settings_type='number',150 label='Gasgiant density',151 defaultvalue=.1,152 min_value=.05,153 max_value=.15,154 seqnum=180155 ),156 'sun_density': ConfigType(157 name='sun_density',158 settings_type='number',159 label='Sun density',160 defaultvalue=.5,161 min_value=.2,162 max_value=1,163 seqnum=190164 ),165 'bigsun_density': ConfigType(166 name='bigsun_density',167 settings_type='number',168 label='Big sun density',169 defaultvalue=2,170 min_value=1,171 max_value=4,172 seqnum=200173 ),174 'giantsun_density': ConfigType(175 name='giantsun_density',176 settings_type='number',177 label='Giant sun density',178 defaultvalue=4,179 min_value=3,180 max_value=6,181 seqnum=210182 ),183 'blackhole_density': ConfigType(184 name='blackhole_density',185 settings_type='number',186 label='Blackhole density',187 defaultvalue=100,188 min_value=50,189 max_value=500,190 seqnum=220191 ),192 # Density END193 # Game setting START194 'background': ConfigType(195 name='background',196 settings_type='bool',197 label='Show background',198 defaultvalue=True,199 seqnum=70200 ),201 'traces': ConfigType(202 name='traces',203 settings_type='bool',204 label='Show traces',205 defaultvalue=False,206 show=False,207 seqnum=71208 ),209 'show_tutorial': ConfigType(210 name='show_tutorial',211 settings_type='bool',212 label='Show tutorial',213 defaultvalue=False,214 show=False,215 seqnum=60216 ),217 'multi_shot_min': ConfigType(218 name='multi_shot_min',219 settings_type='number',220 label='Minimum bodies multishot',221 defaultvalue=10,222 min_value=5,223 max_value=50,224 seqnum=40225 ),226 'multi_shot_max': ConfigType(227 name='multi_shot_max',228 settings_type='number',229 label='Maximum bodies multishot',230 defaultvalue=50,231 min_value=45,232 max_value=100,233 seqnum=50234 ),235 'engine': ConfigType(236 name='engine',237 settings_type='select',238 label='Engine to use for gravity calculations',239 defaultvalue='crk4engine',240 values=['crk4engine', 'cplanet', 'pythonrk4'],241 seqnum=10242 ),243 'ticks_ahead': ConfigType(244 name='ticks_ahead',245 settings_type='number',246 label='Ticks to calculate into future when showing orbits',247 defaultvalue=500,248 min_value=100,249 max_value=1000,250 seqnum=20251 ),252 'ticks_history': ConfigType(253 name='ticks_history',254 settings_type='number',255 label='Number of ticks stored in history',256 defaultvalue=50,257 min_value=10,258 max_value=500,259 seqnum=21260 ),261 'music_volume': ConfigType(262 name='music_volume',263 settings_type='number',264 label='Music volume',265 defaultvalue=0.5,266 min_value=0.0,267 max_value=1.0,268 seqnum=30269 ),270 }271 def __iter__(self):272 return iter(self.config.keys())273 def __getitem__(self, key):274 return self.config[key]275 def __setitem__(self, key, value):276 if key in self.config:277 configitem = self.config[key]278 configitem.validate(value)279 configitem.value = value280 else:281 raise KeyError('Key not found in config: %s' % key)282class ConfigController(object):283 '''app will talk to this object, which feels like a dict when used284 '''285 def __init__(self, path):286 self.path = path287 self.model = ConfigModel()288 self.load()289 def __getitem__(self, key):290 return self.model[key].value291 def __setitem__(self, key, value):292 self.model[key] = value293 def __iter__(self):294 return iter(self.model.config.keys())295 def load(self):296 try:297 with open(self.path, 'r') as settingsfile:298 json_d = settingsfile.readline()299 settings = json.loads(json_d)300 for key, value in settings.items():301 # self.model[key].value = value302 self.model[key] = value303 except IOError:304 print('Unable to open settings file. Using defaults.')305 except Exception:306 raise307 def save(self):308 '''safe current model state into json file'''309 save_dict = {key: self.model[key].value for key in self.model}310 save_json = json.dumps(save_dict)311 with open(self.path, 'w') as settingsfile:312 settingsfile.write(save_json)313 def showconfig(self):314 '''Debug function to display config'''315 import pprint316 save_dict = {key: self.model[key].value for key in self.model}317 pprint.pprint(save_dict)318if __name__ == '__main__':319 '''simple test for new config machine'''320 controller = ConfigController('another_settings.json')321 controller.showconfig()322 for key in controller:323 print(key, controller[key])...

Full Screen

Full Screen

plugin_settings.py

Source:plugin_settings.py Github

copy

Full Screen

1from logging import getLogger2from . import constants, registry, utils3log = getLogger(__name__)4def add_plugins(settings_path, project_type, settings_type):5 """6 Updates the module at the given ``settings_path`` with all Plugin7 Settings appropriate for the given project_type and settings_type.8 """9 settings_module = utils.import_module(settings_path)10 for plugin_settings in _iter_plugins(project_type, settings_type):11 settings_func = getattr(plugin_settings, constants.PLUGIN_APP_SETTINGS_FUNC_NAME)12 settings_func(settings_module)13def _iter_plugins(project_type, settings_type):14 """15 Yields Plugin Settings modules that are registered for the given16 project_type and settings_type.17 """18 for app_config in registry.get_app_configs(project_type):19 settings_config = _get_config(app_config, project_type, settings_type)20 if settings_config is None:21 log.debug(22 u'Plugin Apps [Settings]: Did NOT find %s for %s and %s',23 app_config.name,24 project_type,25 settings_type,26 )27 continue28 plugin_settings_path = utils.get_module_path(app_config, settings_config, constants.PluginSettings)29 log.debug(u'Plugin Apps [Settings]: Found %s for %s and %s', app_config.name, project_type, settings_type)30 yield utils.import_module(plugin_settings_path)31def _get_config(app_config, project_type, settings_type):32 plugin_config = getattr(app_config, constants.PLUGIN_APP_CLASS_ATTRIBUTE_NAME, {})33 settings_config = plugin_config.get(constants.PluginSettings.CONFIG, {})34 project_type_settings = settings_config.get(project_type, {})...

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