def test_load_json_with_default_no_perms(json_file, json_obj): json_file.write(json.dumps(json_obj)) json_file.chmod(200) with pytest.raises(EnvironmentError) as excinfo: util.load_json(str(json_file), default='default') assert excinfo.value.filename == str(json_file) assert excinfo.value.errno == errno.EACCES
def load(cls, touchpad_manager, filename=None): """ Load the configuration for the given ``touchpad_manager`` from disc. If no ``filename`` is given, the configuration is loaded from the default configuration file as returned by :func:`get_management_config_file_path`. Otherwise the configuration is loaded from the given file. If the file doesn't exist, the default config as given by :attr:`defaults` is loaded. After the configuration is loaded, it is applied to the given ``touchpad_manager``. ``touchpad_manager`` is a :class:`~synaptiks.management.TouchpadManager` object. ``filename`` is either ``None`` or a string containing the path to a file. Return a :class:`ManagerConfiguration` object. Raise :exc:`~exceptions.EnvironmentError`, if the file could not be loaded, but *not* in case of a non-existing file. """ if not filename: filename = get_management_config_file_path() config = cls(touchpad_manager) # use defaults for all non-existing settings loaded_config = dict(cls._DEFAULTS) loaded_config.update(load_json(filename, default={})) config.update(loaded_config) return config
def load(cls, touchpad, filename=None): """ Load the configuration for the given ``touchpad`` from disc. If no ``filename`` is given, the configuration is loaded from the default configuration file as returned by :func:`get_touchpad_config_file_path`. Otherwise the configuration is loaded from the given file. If the file doesn't exist, an empty configuration is loaded. After the configuration is loaded, it is applied to the given ``touchpad``. ``touchpad`` is a :class:`~synaptiks.touchpad.Touchpad` object. ``filename`` is either ``None`` or a string containing the path to a file. Return a :class:`TouchpadConfiguration` object. Raise :exc:`~exceptions.EnvironmentError`, if the file could not be loaded, but *not* in case of a non-existing file. """ if not filename: filename = get_touchpad_config_file_path() config = cls(touchpad) config.update(load_json(filename, default={})) return config
def get_touchpad_defaults(filename=None): """ Get the default touchpad settings as :func:`dict` *without* applying it to the touchpad. """ if not filename: filename = get_touchpad_defaults_file_path() return load_json(filename, default={})
def test_load_json_no_default(json_file, json_obj): json_file.write(json.dumps(json_obj)) assert util.load_json(str(json_file)) == json_obj
def test_load_json_non_existing_no_default(json_file): with pytest.raises(EnvironmentError) as excinfo: util.load_json(str(json_file)) assert excinfo.value.filename == str(json_file) assert excinfo.value.errno == errno.ENOENT
def test_load_json_default_used(json_file): assert util.load_json(str(json_file), default='default') == 'default'
def test_load_json_default_ignored(json_file, json_obj): json_file.write(json.dumps(json_obj)) assert util.load_json(str(json_file), default='default') == json_obj