How to use _load_defaults method in Slash

Best Python code snippet using slash

test_settings_wrapper.py

Source:test_settings_wrapper.py Github

copy

Full Screen

...11 self.wrapper = SettingsWrapper()12 self.wrapper.my_settings = {}13 def test_no_defaults(self):14 self.wrapper.my_settings = {}15 self.wrapper._load_defaults()16 sets = self.wrapper.settings()17 self.assertEqual(sets, {})18 def test_load_default(self):19 self.wrapper._load_defaults("default_settings.py")20 sets = self.wrapper.settings()21 self.assertEqual(sets, self.defaults)22 def test_no_override(self):23 # test no prior defaults24 self.wrapper.my_settings = {}25 self.wrapper._load_custom()26 sets = self.wrapper.settings()27 self.assertEqual(sets, {})28 self.wrapper._load_defaults("default_settings.py")29 self.wrapper._load_custom()30 sets = self.wrapper.settings()31 self.assertEqual(sets, self.defaults)32 def test_override_default(self):33 self.wrapper._load_defaults("default_settings.py")34 self.wrapper._load_custom("override_defaults.py")35 sets = self.wrapper.settings()36 actual = {37 'NEW_DICT': {38 'other': 'stuff'39 },40 'MY_STRING': 'cool',41 'DICT': {42 'append': 'value',43 'value': 'override'44 },45 'STRING': 'my stuff',46 'NEW_LIST': ['item1']47 }...

Full Screen

Full Screen

settings.py

Source:settings.py Github

copy

Full Screen

...12 return os.path.join(homedir, "waldo_config.ini")13class Settings(object):14 def __init__(self):15 self.config_file = _default_user_config()16 self._load_defaults()17 def __getattr__(self, name):18 if name in defaults:19 return self._data[name]20 else:21 return super(Settings, self).__getattribute__(name)22 def __setattr__(self, name, value):23 if name in defaults:24 self._data[name] = value25 else:26 super(Settings, self).__setattr__(name, value)27 def _get_or_update_config_file(self, config_file):28 if config_file is not None:29 self.config_file = config_file30 return self.config_file31 def _load_defaults(self):32 self._data = defaults.copy()33 def save(self, config_file=None):34 config_file = self._get_or_update_config_file(config_file)35 with open(config_file, 'w') as f:36 json.dump(self._data, f, indent=4, sort_keys=True)37 def load(self, config_file=None, clean=False, autogenerate=False):38 config_file = self._get_or_update_config_file(config_file)39 try:40 with open(config_file) as f:41 newdata = json.load(f)42 except (IOError, OSError) as e:43 if e.errno == errno.ENOENT and autogenerate:44 self._load_defaults()45 self.save()46 return47 else:48 raise49 if clean:50 self._load_defaults()51 self._data.update(newdata)52settings = 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 Slash 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