Пример #1
0
 def setUp(self):
     self.settings = SettingsProxy(default_settings_module)
     self.settings.local.clear()
Пример #2
0
class SettingsProxyTest(unittest.TestCase):
    def setUp(self):
        self.settings = SettingsProxy(default_settings_module)
        self.settings.local.clear()

    def test_set_and_get_attr(self):
        self.settings.TEST = 'test'
        self.assertEqual(self.settings.TEST, 'test')

    def test_getattr_raises_error_on_missing_setting(self):
        try:
            _ = self.settings.TEST
            self.fail(u'Should raise exception')
        except SettingsError as e:
            self.assertEqual(u'Setting "TEST" is not set.', e.message)

    def test_getattr_raises_error_on_empty_setting(self):
        self.settings.TEST = u''
        try:
            _ = self.settings.TEST
            self.fail(u'Should raise exception')
        except SettingsError as e:
            self.assertEqual(u'Setting "TEST" is empty.', e.message)

    def test_getattr_does_not_raise_error_if_setting_is_false(self):
        self.settings.TEST = False
        self.assertEqual(False, self.settings.TEST)

    def test_getattr_does_not_raise_error_if_setting_is_none(self):
        self.settings.TEST = None
        self.assertEqual(None, self.settings.TEST)

    def test_getattr_does_not_raise_error_if_setting_is_zero(self):
        self.settings.TEST = 0
        self.assertEqual(0, self.settings.TEST)

    def test_setattr_updates_runtime_settings(self):
        self.settings.TEST = 'test'
        self.assert_('TEST' in self.settings.runtime)

    def test_setattr_updates_runtime_with_value(self):
        self.settings.TEST = 'test'
        self.assertEqual(self.settings.runtime['TEST'], 'test')

    def test_runtime_value_included_in_current(self):
        self.settings.TEST = 'test'
        self.assertEqual(self.settings.current['TEST'], 'test')

    def test_value_ending_in_path_is_expanded(self):
        self.settings.TEST_PATH = '~/test'
        actual = self.settings.TEST_PATH
        expected = os.path.expanduser('~/test')
        self.assertEqual(actual, expected)

    def test_value_ending_in_path_is_absolute(self):
        self.settings.TEST_PATH = './test'
        actual = self.settings.TEST_PATH
        expected = os.path.abspath('./test')
        self.assertEqual(actual, expected)

    def test_value_ending_in_file_is_expanded(self):
        self.settings.TEST_FILE = '~/test'
        actual = self.settings.TEST_FILE
        expected = os.path.expanduser('~/test')
        self.assertEqual(actual, expected)

    def test_value_ending_in_file_is_absolute(self):
        self.settings.TEST_FILE = './test'
        actual = self.settings.TEST_FILE
        expected = os.path.abspath('./test')
        self.assertEqual(actual, expected)

    def test_value_not_ending_in_path_or_file_is_not_expanded(self):
        self.settings.TEST = '~/test'
        actual = self.settings.TEST
        self.assertEqual(actual, '~/test')

    def test_value_not_ending_in_path_or_file_is_not_absolute(self):
        self.settings.TEST = './test'
        actual = self.settings.TEST
        self.assertEqual(actual, './test')

    def test_interactive_input_of_missing_defaults(self):
        self.settings.default['TEST'] = ''
        interactive_input = 'input'
        self.settings._read_from_stdin = lambda _: interactive_input
        self.settings.validate(interactive=True)
        self.assertEqual(interactive_input, self.settings.TEST)

    def test_interactive_input_not_needed_when_setting_is_set_locally(self):
        self.settings.default['TEST'] = ''
        self.settings.local['TEST'] = 'test'
        self.settings._read_from_stdin = lambda _: self.fail(
            'Should not read from stdin')
        self.settings.validate(interactive=True)
Пример #3
0
    return platform.platform()

def get_python():
    implementation = platform.python_implementation()
    version = platform.python_version()
    return u' '.join([implementation, version])

class MopidyException(Exception):
    def __init__(self, message, *args, **kwargs):
        super(MopidyException, self).__init__(message, *args, **kwargs)
        self._message = message

    @property
    def message(self):
        """Reimplement message field that was deprecated in Python 2.6"""
        return self._message

    @message.setter
    def message(self, message):
        self._message = message

class SettingsError(MopidyException):
    pass

class OptionalDependencyError(MopidyException):
    pass

from mopidy import settings as default_settings_module
from mopidy.utils.settings import SettingsProxy
settings = SettingsProxy(default_settings_module)
Пример #4
0
 def setUp(self):
     self.settings = SettingsProxy(default_settings_module)
     self.settings.local.clear()
Пример #5
0
class SettingsProxyTest(unittest.TestCase):
    def setUp(self):
        self.settings = SettingsProxy(default_settings_module)
        self.settings.local.clear()

    def test_set_and_get_attr(self):
        self.settings.TEST = 'test'
        self.assertEqual(self.settings.TEST, 'test')

    def test_getattr_raises_error_on_missing_setting(self):
        try:
            _ = self.settings.TEST
            self.fail(u'Should raise exception')
        except SettingsError as e:
            self.assertEqual(u'Setting "TEST" is not set.', e.message)

    def test_getattr_raises_error_on_empty_setting(self):
        self.settings.TEST = u''
        try:
            _ = self.settings.TEST
            self.fail(u'Should raise exception')
        except SettingsError as e:
            self.assertEqual(u'Setting "TEST" is empty.', e.message)

    def test_getattr_does_not_raise_error_if_setting_is_false(self):
        self.settings.TEST = False
        self.assertEqual(False, self.settings.TEST)

    def test_getattr_does_not_raise_error_if_setting_is_none(self):
        self.settings.TEST = None
        self.assertEqual(None, self.settings.TEST)

    def test_getattr_does_not_raise_error_if_setting_is_zero(self):
        self.settings.TEST = 0
        self.assertEqual(0, self.settings.TEST)

    def test_setattr_updates_runtime_settings(self):
        self.settings.TEST = 'test'
        self.assert_('TEST' in self.settings.runtime)

    def test_setattr_updates_runtime_with_value(self):
        self.settings.TEST = 'test'
        self.assertEqual(self.settings.runtime['TEST'], 'test')

    def test_runtime_value_included_in_current(self):
        self.settings.TEST = 'test'
        self.assertEqual(self.settings.current['TEST'], 'test')

    def test_value_ending_in_path_is_expanded(self):
        self.settings.TEST_PATH = '~/test'
        actual = self.settings.TEST_PATH
        expected = os.path.expanduser('~/test')
        self.assertEqual(actual, expected)

    def test_value_ending_in_path_is_absolute(self):
        self.settings.TEST_PATH = './test'
        actual = self.settings.TEST_PATH
        expected = os.path.abspath('./test')
        self.assertEqual(actual, expected)

    def test_value_ending_in_file_is_expanded(self):
        self.settings.TEST_FILE = '~/test'
        actual = self.settings.TEST_FILE
        expected = os.path.expanduser('~/test')
        self.assertEqual(actual, expected)

    def test_value_ending_in_file_is_absolute(self):
        self.settings.TEST_FILE = './test'
        actual = self.settings.TEST_FILE
        expected = os.path.abspath('./test')
        self.assertEqual(actual, expected)

    def test_value_not_ending_in_path_or_file_is_not_expanded(self):
        self.settings.TEST = '~/test'
        actual = self.settings.TEST
        self.assertEqual(actual, '~/test')

    def test_value_not_ending_in_path_or_file_is_not_absolute(self):
        self.settings.TEST = './test'
        actual = self.settings.TEST
        self.assertEqual(actual, './test')

    def test_value_ending_in_file_can_be_none(self):
        self.settings.TEST_FILE = None
        self.assertEqual(self.settings.TEST_FILE, None)

    def test_value_ending_in_path_can_be_none(self):
        self.settings.TEST_PATH = None
        self.assertEqual(self.settings.TEST_PATH, None)

    def test_interactive_input_of_missing_defaults(self):
        self.settings.default['TEST'] = ''
        interactive_input = 'input'
        self.settings._read_from_stdin = lambda _: interactive_input
        self.settings.validate(interactive=True)
        self.assertEqual(interactive_input, self.settings.TEST)

    def test_interactive_input_not_needed_when_setting_is_set_locally(self):
        self.settings.default['TEST'] = ''
        self.settings.local['TEST'] = 'test'
        self.settings._read_from_stdin = lambda _: self.fail(
            'Should not read from stdin')
        self.settings.validate(interactive=True)
Пример #6
0
 def setUp(self):
     self.settings = SettingsProxy(default_settings_module)