config: Flake8 fixes
This commit is contained in:
parent
e98ca4c94c
commit
63003abb2e
@ -24,7 +24,7 @@ sys.path.insert(
|
||||
0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../')))
|
||||
|
||||
|
||||
from mopidy import exceptions, ext
|
||||
from mopidy import ext
|
||||
from mopidy.audio import Audio
|
||||
from mopidy import config as config_lib
|
||||
from mopidy.core import Core
|
||||
@ -136,12 +136,14 @@ def show_config_callback(option, opt, value, parser):
|
||||
overrides = getattr(parser.values, 'overrides', [])
|
||||
|
||||
extensions = ext.load_extensions()
|
||||
raw_config = load_config(files, overrides, extensions)
|
||||
raw_config = config_lib.load(files, overrides, extensions)
|
||||
enabled_extensions = ext.filter_enabled_extensions(raw_config, extensions)
|
||||
config = validate_config(raw_config, config_schemas, enabled_extensions)
|
||||
config = config_lib.validate(
|
||||
raw_config, config_lib.config_schemas, enabled_extensions)
|
||||
|
||||
# TODO: create mopidy.config.format?
|
||||
output = []
|
||||
for section_name, schema in config_schemas.items():
|
||||
for section_name, schema in config_lib.config_schemas.items():
|
||||
options = config.get(section_name, {})
|
||||
if not options:
|
||||
continue
|
||||
|
||||
@ -69,8 +69,7 @@ def _load(files, defaults, overrides):
|
||||
files = [path.expand_path(f) for f in files]
|
||||
sources = ['builtin-defaults'] + files + ['command-line']
|
||||
logger.info('Loading config from: %s', ', '.join(sources))
|
||||
|
||||
for default in defaults: # TODO: remove decoding
|
||||
for default in defaults: # TODO: remove decoding
|
||||
parser.readfp(io.StringIO(default.decode('utf-8')))
|
||||
|
||||
# Load config from a series of config files
|
||||
|
||||
@ -36,13 +36,11 @@ def _levenshtein(a, b):
|
||||
return current[n]
|
||||
|
||||
|
||||
|
||||
|
||||
class ConfigSchema(object):
|
||||
"""Logical group of config values that correspond to a config section.
|
||||
|
||||
Schemas are set up by assigning config keys with config values to
|
||||
instances. Once setup :meth:`convert` can be called with a list of
|
||||
instances. Once setup :meth:`convert` can be called with a list of
|
||||
``(key, value)`` tuples to process. For convienience we also support
|
||||
:meth:`format` method that can used for printing out the converted values.
|
||||
"""
|
||||
|
||||
@ -194,7 +194,7 @@ class ExpandedPath(bytes):
|
||||
|
||||
|
||||
class Path(ConfigValue):
|
||||
"""File system path that will be expanded with mopidy.utils.path.expand_path
|
||||
"""File system path that will be expanded.
|
||||
|
||||
Supports: optional, choices and secret.
|
||||
"""
|
||||
|
||||
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
# TODO: add validate regexp?
|
||||
|
||||
|
||||
def validate_required(value, required):
|
||||
"""Required validation, normally called in config value's validate() on the
|
||||
raw string, _not_ the converted value."""
|
||||
|
||||
@ -4,7 +4,7 @@ import logging
|
||||
import mock
|
||||
|
||||
from mopidy import exceptions
|
||||
from mopidy.config import schemas
|
||||
from mopidy.config import schemas, types
|
||||
|
||||
from tests import unittest
|
||||
|
||||
@ -89,7 +89,7 @@ class ConfigSchemaTest(unittest.TestCase):
|
||||
class ExtensionConfigSchemaTest(unittest.TestCase):
|
||||
def test_schema_includes_enabled(self):
|
||||
schema = schemas.ExtensionConfigSchema()
|
||||
self.assertIsInstance(schema['enabled'], values.Boolean)
|
||||
self.assertIsInstance(schema['enabled'], types.Boolean)
|
||||
|
||||
|
||||
class LogLevelConfigSchemaTest(unittest.TestCase):
|
||||
@ -102,8 +102,9 @@ class LogLevelConfigSchemaTest(unittest.TestCase):
|
||||
|
||||
def test_format(self):
|
||||
schema = schemas.LogLevelConfigSchema()
|
||||
values = {'foo.bar': logging.DEBUG, 'baz': logging.INFO}
|
||||
expected = ['[levels]', 'baz = info', 'foo.bar = debug']
|
||||
result = schema.format('levels', {'foo.bar': logging.DEBUG, 'baz': logging.INFO})
|
||||
result = schema.format('levels', values)
|
||||
self.assertEqual('\n'.join(expected), result)
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ import logging
|
||||
import mock
|
||||
import socket
|
||||
|
||||
from mopidy import exceptions
|
||||
from mopidy.config import types
|
||||
|
||||
from tests import unittest
|
||||
@ -165,7 +164,7 @@ class ListTest(unittest.TestCase):
|
||||
self.assertRegexpMatches(result, r'foo\n\s*bar\n\s*baz')
|
||||
|
||||
|
||||
class BooleanTest(unittest.TestCase):
|
||||
class LogLevelTest(unittest.TestCase):
|
||||
levels = {'critical': logging.CRITICAL,
|
||||
'error': logging.ERROR,
|
||||
'warning': logging.WARNING,
|
||||
|
||||
@ -14,12 +14,14 @@ class ValidateChoiceTest(unittest.TestCase):
|
||||
validators.validate_choice(1, [1, 2, 3])
|
||||
|
||||
def test_empty_choices_fails(self):
|
||||
self.assertRaises(ValueError,validators.validate_choice, 'foo', [])
|
||||
self.assertRaises(ValueError, validators.validate_choice, 'foo', [])
|
||||
|
||||
def test_invalid_value_fails(self):
|
||||
words = ['foo', 'bar', 'baz']
|
||||
self.assertRaises(ValueError, validators.validate_choice, 'foobar', words)
|
||||
self.assertRaises(ValueError, validators.validate_choice, 5, [1, 2, 3])
|
||||
self.assertRaises(
|
||||
ValueError, validators.validate_choice, 'foobar', words)
|
||||
self.assertRaises(
|
||||
ValueError, validators.validate_choice, 5, [1, 2, 3])
|
||||
|
||||
|
||||
class ValidateMinimumTest(unittest.TestCase):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user