mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Remove old config value style
This commit is contained in:
parent
95e81f5383
commit
6f95870a48
3 changed files with 38 additions and 61 deletions
|
|
@ -16,6 +16,8 @@ Version 0.4.1
|
|||
|
||||
- All ``create`` arguments from all storages are gone. Vdirsyncer now asks if
|
||||
it should try to create collections.
|
||||
- The old config values ``True``, ``False``, ``on``, ``off`` and ``None`` are
|
||||
now invalid.
|
||||
|
||||
Version 0.4.0
|
||||
=============
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ def test_load_config(monkeypatch):
|
|||
type = filesystem
|
||||
path = /tmp/contacts/
|
||||
fileext = .vcf
|
||||
yesno = off
|
||||
yesno = false
|
||||
number = 42
|
||||
|
||||
[storage bob_b]
|
||||
|
|
@ -489,45 +489,31 @@ def test_create_collections(tmpdir, runner):
|
|||
set('abc')
|
||||
|
||||
|
||||
def test_parse_config_value():
|
||||
x = cli.utils.parse_config_value
|
||||
with pytest.raises(ValueError):
|
||||
x('123 # comment!')
|
||||
def test_parse_config_value(capsys):
|
||||
invalid = object()
|
||||
|
||||
assert x('"123 # comment!"') == '123 # comment!'
|
||||
assert x('True') is True
|
||||
assert x('False') is False
|
||||
assert x('Yes') is True
|
||||
assert x('3.14') == 3.14
|
||||
assert x('') == ''
|
||||
assert x('""') == ''
|
||||
def x(s):
|
||||
try:
|
||||
rv = cli.utils.parse_config_value(s)
|
||||
except ValueError:
|
||||
return invalid
|
||||
else:
|
||||
warnings = capsys.readouterr()[1]
|
||||
return rv, len(warnings.splitlines())
|
||||
|
||||
assert x('123 # comment!') is invalid
|
||||
|
||||
def test_parse_options():
|
||||
o = {
|
||||
'foo': 'yes',
|
||||
'hah': 'true',
|
||||
'bar': '',
|
||||
'baz': 'whatever',
|
||||
'bam': '123',
|
||||
'asd': 'off'
|
||||
}
|
||||
assert x('True') == ('True', 1)
|
||||
assert x('False') == ('False', 1)
|
||||
assert x('Yes') == ('Yes', 1)
|
||||
assert x('None') == ('None', 1)
|
||||
assert x('"True"') == ('True', 0)
|
||||
assert x('"False"') == ('False', 0)
|
||||
|
||||
a = dict(cli.utils.parse_options(o.items()))
|
||||
|
||||
expected = {
|
||||
'foo': True,
|
||||
'hah': True,
|
||||
'bar': '',
|
||||
'baz': 'whatever',
|
||||
'bam': 123,
|
||||
'asd': False
|
||||
}
|
||||
|
||||
assert a == expected
|
||||
|
||||
for key in a:
|
||||
# Yes, we want a very strong typecheck here, because we actually have
|
||||
# to differentiate between bool and int, and in Python 2, bool is a
|
||||
# subclass of int.
|
||||
assert a[key].__class__ is expected[key].__class__
|
||||
assert x('"123 # comment!"') == ('123 # comment!', 0)
|
||||
assert x('true') == (True, 0)
|
||||
assert x('false') == (False, 0)
|
||||
assert x('null') == (None, 0)
|
||||
assert x('3.14') == (3.14, 0)
|
||||
assert x('') == ('', 0)
|
||||
assert x('""') == ('', 0)
|
||||
|
|
|
|||
|
|
@ -471,28 +471,17 @@ def parse_config_value(value):
|
|||
try:
|
||||
return json.loads(value)
|
||||
except ValueError:
|
||||
rv = value
|
||||
pass
|
||||
|
||||
if value.lower() in ('on', 'true', 'yes'):
|
||||
cli_logger.warning(
|
||||
'{} is deprecated for the config, please use true.\n'
|
||||
'The old form will be removed in 0.4.0.'
|
||||
.format(value)
|
||||
)
|
||||
return True
|
||||
if value.lower() in ('off', 'false', 'no'):
|
||||
cli_logger.warning(
|
||||
'{} is deprecated for the config, please use false.\n'
|
||||
'The old form will be removed in 0.4.0.'
|
||||
.format(value)
|
||||
)
|
||||
return False
|
||||
if value.lower() == 'none':
|
||||
cli_logger.warning(
|
||||
'None is deprecated for the config, please use null.\n'
|
||||
'The old form will be removed in 0.4.0.'
|
||||
)
|
||||
return None
|
||||
for wrong, right in [
|
||||
(('on', 'yes'), 'true'),
|
||||
(('off', 'no'), 'false'),
|
||||
(('none',), 'null')
|
||||
]:
|
||||
if value.lower() in wrong + (right,):
|
||||
cli_logger.warning('You probably meant {} instead of "{}", which '
|
||||
'will now be interpreted as a literal string.'
|
||||
.format(right, value))
|
||||
|
||||
if '#' in value:
|
||||
raise ValueError('Invalid value:{}\n'
|
||||
|
|
@ -508,7 +497,7 @@ def parse_config_value(value):
|
|||
# # my comment
|
||||
raise ValueError('No multiline-values allowed:\n{}'.format(value))
|
||||
|
||||
return rv
|
||||
return value
|
||||
|
||||
|
||||
def parse_options(items, section=None):
|
||||
|
|
|
|||
Loading…
Reference in a new issue