How to use the confuse.ConfigValueError function in confuse

To help you get started, we’ve selected a few confuse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beetbox / confuse / test / test_validation.py View on Github external
def test_as_choice_error(self):
        config = _root({'foo': 'bar'})
        with self.assertRaises(confuse.ConfigValueError):
            config['foo'].as_choice(['foo', 'baz'])
github beetbox / confuse / test / test_valid.py View on Github external
def test_validate_no_choice_in_list(self):
        config = _root({'foo': None})
        with self.assertRaises(confuse.ConfigValueError):
            config['foo'].get(confuse.OneOf([
                confuse.String(),
                confuse.Integer(),
            ]))
github beetbox / beets / test / test_types_plugin.py View on Github external
def test_unknown_type_error(self):
        self.config['types'] = {'flex': 'unkown type'}
        with self.assertRaises(ConfigValueError):
            self.run_command(u'ls')
github beetbox / beets / beetsplug / fetchart.py View on Github external
# allow both pixel and percentage-based margin specifications
        self.enforce_ratio = self.config['enforce_ratio'].get(
            confuse.OneOf([bool,
                           confuse.String(pattern=self.PAT_PX),
                           confuse.String(pattern=self.PAT_PERCENT)]))
        self.margin_px = None
        self.margin_percent = None
        if type(self.enforce_ratio) is six.text_type:
            if self.enforce_ratio[-1] == u'%':
                self.margin_percent = float(self.enforce_ratio[:-1]) / 100
            elif self.enforce_ratio[-2:] == u'px':
                self.margin_px = int(self.enforce_ratio[:-2])
            else:
                # shouldn't happen
                raise confuse.ConfigValueError()
            self.enforce_ratio = True

        cover_names = self.config['cover_names'].as_str_seq()
        self.cover_names = list(map(util.bytestring_path, cover_names))
        self.cautious = self.config['cautious'].get(bool)
        self.store_source = self.config['store_source'].get(bool)

        self.src_removed = (config['import']['delete'].get(bool) or
                            config['import']['move'].get(bool))

        if self.config['auto']:
            # Enable two import hooks when fetching is enabled.
            self.import_stages = [self.fetch_art]
            self.register_listener('import_task_files', self.assign_art)

        available_sources = list(SOURCES_ALL)
github beetbox / beets / beetsplug / metasync / __init__.py View on Github external
# Avoid needlessly instantiating meta sources (can be expensive)
        if not items:
            self._log.info(u'No items found matching query')
            return

        # Instantiate the meta sources
        for player in sources:
            try:
                cls = META_SOURCES[player]
            except KeyError:
                self._log.error(u'Unknown metadata source \'{0}\''.format(
                    player))

            try:
                meta_source_instances[player] = cls(self.config, self._log)
            except (ImportError, ConfigValueError) as e:
                self._log.error(u'Failed to instantiate metadata source '
                                u'\'{0}\': {1}'.format(player, e))

        # Avoid needlessly iterating over items
        if not meta_source_instances:
            self._log.error(u'No valid metadata sources found')
            return

        # Sync the items with all of the meta sources
        for item in items:
            for meta_source in meta_source_instances.values():
                meta_source.sync_from_source(item)

            changed = ui.show_model_changes(item)

            if changed and not pretend:
github beetbox / beets / beetsplug / types.py View on Github external
def _types(self):
        if not self.config.exists():
            return {}

        mytypes = {}
        for key, value in self.config.items():
            if value.get() == 'int':
                mytypes[key] = types.INTEGER
            elif value.get() == 'float':
                mytypes[key] = types.FLOAT
            elif value.get() == 'bool':
                mytypes[key] = types.BOOLEAN
            elif value.get() == 'date':
                mytypes[key] = library.DateType()
            else:
                raise ConfigValueError(
                    u"unknown type '{0}' for the '{1}' field"
                    .format(value, key))
        return mytypes