How to use _set_settings_values method in autotest

Best Python code snippet using autotest_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...55 self, 'validate_%s' % key.lower(), None)56 if validate_func is not None:57 value = validate_func(value, default)58 return value59 def _set_settings_values(self, source=None):60 """61 Validate and store configuration items specified by `source` (a dict).62 If source is `None`, the function will use default values to fill up63 unset configuration items.64 """65 if source is None:66 for dest_name, (org_name, default_value) in mapping.items():67 if not hasattr(self, dest_name):68 value = default_value() if callable(default_value) \69 else default_value70 setattr(self, dest_name, value)71 return72 for dest_name, (org_name, default_value) in mapping.items():73 value = source.get(org_name, None)74 if value is None:75 value = default_value() if callable(default_value) \76 else default_value77 value = self._validate(dest_name, value, default_value)78 setattr(self, dest_name, value)79 def dump_settings_value(self):80 """81 Return a dict containing gathered configuration items.82 """83 result = {}84 for dest_name, (org_name, _) in mapping.items():85 value = getattr(self, dest_name)86 value = self._validate(dest_name, value, _)87 result[org_name] = value88 return result89 def validate_biohub_plugins(self, value, default):90 """91 BIOHUB_PLUGINS should not contains duplicated items.92 """93 result = []94 for item in unique(value):95 if not is_valid_module_path(item, try_import=True):96 warnings.warn(97 "Module '%s' not found. Skipped." % item,98 BiohubSettingsWarning99 )100 else:101 result.append(item)102 return result103 def validate_redis_uri(self, value, default):104 if not value:105 warnings.warn(106 'No redis configuration provided, redis-based services '107 'will be disabled.', BiohubSettingsWarning)108 return value109 def validate_secret_key(self, value, default):110 if not value:111 warnings.warn(112 'No secret key provided, default value used instead.',113 BiohubSettingsWarning)114 return value115 def validate_biohub_max_tasks(self, value, default):116 assert isinstance(value, int) and value > 0, \117 "'MAX_TASKS' should be positive integer."118 return value119 def validate_biohub_task_max_timeout(self, value, default):120 assert isinstance(value, (int, float)) and value > 0, \121 "'TASK_MAX_TIMEOUT' should be positive float."122 return value123 def validate_upload_dir(self, value, default):124 if value.startswith(tempfile.gettempdir()):125 warnings.warn(126 'Your UPLOAD_DIR is within the temporary directory. All '127 'files will be erased once system reboots.',128 BiohubSettingsWarning)129 return os.path.abspath(value)130 def validate_plugins_dir(self, value, default):131 if value.startswith(tempfile.gettempdir()):132 warnings.warn(133 'Your PLUGINS_DIR is within the temporary directory. All '134 'files will be erased once system reboots.',135 BiohubSettingsWarning)136 try:137 os.makedirs(value)138 except OSError:139 pass140 sys.path.append(value)141 return os.path.abspath(value)142 def validate_email(self, value, default):143 if not isinstance(value, dict):144 raise TypeError("'EMAIL' should be a dict, got type %r." % type(type(value)))145 required = 'HOST HOST_USER HOST_PASSWORD PORT'.split()146 missing = set(required) - set(value)147 if missing:148 warnings.warn(149 'Fields %s not found in EMAIL, which may affect email related services.'150 % ', '.join(missing), BiohubSettingsWarning)151 for field in missing:152 value[field] = ''153 return value154 def validate_throttle(self, value, default):155 if not isinstance(value, dict):156 raise TypeError("'THROTTLE' should be a dict, got type %r." % type(type(value)))157 default_value = default()158 default_value.update(value)159 return default_value160 def __delattr__(self, name):161 """162 Configuration items should be protected.163 """164 if name in valid_settings_keys:165 raise KeyError(166 "Can't delete a configuration item.")167 super(Settings, self).__delattr__(name)168class LazySettings(LazyObject):169 """170 A proxy to settings object. Settings will not be loaded until it is171 accessed.172 """173 def __init__(self):174 self._manager = SettingsManager(Settings())175 super(LazySettings, self).__init__()176 @property177 def configured(self):178 """179 Returns a boolean indicating whether the settings is loaded.180 """181 return self._wrapped is not empty182 def _setup(self):183 self._wrapped = self._manager._settings_object184 self._manager.load()185 def __getattr__(self, name):186 if self._wrapped is empty:187 self._setup()188 val = getattr(self._manager, name, None)189 if val is None:190 val = getattr(self._wrapped, name)191 return val192 def __setattr__(self, name, value):193 if name == '_manager':194 self.__dict__['_manager'] = value195 return196 self.__dict__.pop(name, None)197 super(LazySettings, self).__setattr__(name, value)198 def __delattr__(self, name):199 raise AttributeError('Not allowed to remove a settings attribute.')200class SettingsManager(object):201 def __init__(self, settings_object):202 self._settings_object = settings_object203 self._file_lock = filelock.FileLock(LOCK_FILE_PATH)204 self._store_settings = []205 @property206 def locking(self):207 return self._file_lock.is_locked208 def _resolve_config_path(self, config_path=None):209 """210 Resolves the path of config file.211 If `config_path` is not None, it will be used. Otherwise212 `os.environ['CONFIG_ENVIRON']` will be used. If both of them are None,213 no config file is specified.214 The path to be used will have existence test before returned.215 """216 if config_path is None:217 config_path = os.environ.get(CONFIG_ENVIRON, None)218 if config_path is not None and not os.path.isfile(config_path):219 raise ImproperlyConfigured(220 "Config file '%s' does not exist or is not a file."221 % config_path)222 self.config_file_path = config_path223 return config_path224 def store_settings(self):225 """226 A function for testing, which saves current state of config file.227 Note that the function MUST be balanced by using `restore_settings`.228 """229 if self.config_file_path is None:230 return231 with self._file_lock:232 with open(self.config_file_path, 'r') as fp:233 self._store_settings.append(fp.read())234 def restore_settings(self, write=True):235 """236 A function for testing, which restores the state in the last call of237 `store_settings`.238 """239 poped = self._store_settings.pop()240 if not write:241 return242 if self.config_file_path is None:243 return244 with self._file_lock:245 with open(self.config_file_path, 'w') as fp:246 fp.write(poped)247 def load(self, path=None):248 """249 Load configuration from file specified by `self.config_file_path`.250 The function is thread-safe.251 """252 path = self._resolve_config_path(path)253 locking = self.locking254 with self._file_lock:255 if locking:256 return257 if path is None:258 source = None259 else:260 with open(path, 'r') as fp:261 source = json.load(fp)262 self._settings_object._set_settings_values(source)263 def dump(self, path=None):264 """265 Write configuration back to file.266 The function is thread-safe.267 """268 path = self._resolve_config_path(path)269 if path is None:270 return271 with self._file_lock:272 with open(path, 'w') as fp:273 json.dump(274 self._settings_object.dump_settings_value(),275 fp, indent=4)276settings = LazySettings()...

Full Screen

Full Screen

configuration_view.py

Source:configuration_view.py Github

copy

Full Screen

...12 self._controller = controller13 self.settings = controller.get_settings()14 self._load_window_properties()15 self._load_window_components()16 self._set_settings_values()17 self.show()18 def _load_window_properties(self):19 self.setFixedSize(400, 200)20 self.setWindowTitle("Configuration")21 def _load_window_components(self):22 container = QWidget(self)23 form_layout = QFormLayout()24 container.setLayout(form_layout)25 self.initial_date_pick = QDateEdit(calendarPopup=True)26 form_layout.addRow(QLabel("Initial Date"), self.initial_date_pick)27 self.combo_sentiment_algorithm = QComboBox(self)28 self.combo_sentiment_algorithm.addItems(self._controller.get_analysis_methods())29 form_layout.addRow(QLabel("Sentiment Algorithm"), self.combo_sentiment_algorithm)30 self.save_button = QPushButton("Save")31 self.save_button.clicked.connect(self.save_settings)32 form_layout.addRow(QLabel("Save"), self.save_button)33 def _set_settings_values(self):34 self.initial_date_pick.setDate(35 self.settings.value("initial_date", type=Qt.QDate))36 index = self._controller.get_analysis_methods().index(self._controller.get_analysis_method())37 self.combo_sentiment_algorithm.setCurrentIndex(index)38 def save_settings(self):39 self.settings.setValue("initial_date", self.initial_date_pick.date())40 self.settings.setValue("analysis_algorithm", str(self.combo_sentiment_algorithm.currentText()))41 self._controller.set_settings(self.settings)...

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