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