Exemplo n.º 1
0
def test_backend_error_condition():
    e = configexc.BackendError('foo', usertypes.Backend.QtWebEngine, {
        'QtWebEngine': 'Qt 5.11',
        'QtWebKit': True
    })
    expected = "The foo setting needs Qt 5.11 with the QtWebEngine backend!"
    assert str(e) == expected
Exemplo n.º 2
0
    def _set_value(self, opt, value):
        """Set the given option to the given value."""
        if not isinstance(objects.backend, objects.NoBackend):
            if objects.backend not in opt.backends:
                raise configexc.BackendError(objects.backend)

        opt.typ.to_py(value)  # for validation
        self._values[opt.name] = opt.typ.from_obj(value)

        self.changed.emit(opt.name)
        log.config.debug("Config option changed: {} = {}".format(
            opt.name, value))
Exemplo n.º 3
0
    def _set_value(self,
                   opt: 'configdata.Option',
                   value: Any,
                   pattern: urlmatch.UrlPattern = None) -> None:
        """Set the given option to the given value."""
        if not isinstance(objects.backend, objects.NoBackend):
            if objects.backend not in opt.backends:
                raise configexc.BackendError(opt.name, objects.backend,
                                             opt.raw_backends)

        opt.typ.to_py(value)  # for validation

        self._values[opt.name].add(opt.typ.from_obj(value), pattern)

        self.changed.emit(opt.name)
        log.config.debug("Config option changed: {} = {}".format(
            opt.name, value))
Exemplo n.º 4
0
    def set(self, layer, sectname, optname, value, validate=True):
        """Set an option.

        Args:
            layer: A layer name as string (conf/temp/default).
            sectname: The name of the section to change.
            optname: The name of the option to change.
            value: The new value.
            validate: Whether to validate the value immediately.
        """
        try:
            value = self._interpolation.before_set(self, sectname, optname,
                                                   value)
        except ValueError as e:
            raise configexc.InterpolationSyntaxError(optname, sectname, str(e))
        try:
            sect = self.sections[sectname]
        except KeyError:
            raise configexc.NoSectionError(sectname)
        mapping = {key: val.value() for key, val in sect.values.items()}

        if validate:
            interpolated = self._interpolation.before_get(
                self, sectname, optname, value, mapping)
            try:
                allowed_backends = sect.values[optname].backends
            except KeyError:
                # Will be handled later in .setv()
                pass
            else:
                backend = usertypes.arg2backend[objreg.get('args').backend]
                if (allowed_backends is not None
                        and backend not in allowed_backends):
                    raise configexc.BackendError(backend)
        else:
            interpolated = None

        try:
            sect.setv(layer, optname, value, interpolated)
        except KeyError:
            raise configexc.NoOptionError(optname, sectname)
        else:
            if self._initialized:
                self._after_set(sectname, optname)
Exemplo n.º 5
0
def test_backend_error(raw_backends):
    e = configexc.BackendError('foo', usertypes.Backend.QtWebKit, raw_backends)
    expected = "The foo setting is not available with the QtWebKit backend!"
    assert str(e) == expected
Exemplo n.º 6
0
def test_backend_error():
    e = configexc.BackendError(usertypes.Backend.QtWebKit)
    assert str(e) == "This setting is not available with the QtWebKit backend!"