better symlink support for option.dict()

This commit is contained in:
Emmanuel Garette 2019-04-17 19:13:17 +02:00
parent 63094f7e54
commit 829247e79f
7 changed files with 138 additions and 35 deletions

View File

@ -0,0 +1,4 @@
{
"options.unicode1": "test",
"options.unicode2": "test"
}

View File

@ -0,0 +1,4 @@
{
"options.unicode1": "val",
"options.unicode2": "val"
}

View File

@ -0,0 +1,42 @@
{
"schema": {
"options": {
"name": "options",
"properties": {
"options.unicode1": {
"name": "options.unicode1",
"type": "string",
"value": "test",
"title": "Unicode 1"
},
"options.unicode2": {
"name": "options.unicode2",
"type": "symlink",
"opt_path": "options.unicode1",
"title": "Unicode 1"
}
},
"type": "object",
"title": "Common configuration"
}
},
"model": {
"options.unicode1": {
"value": "test",
"owner": "default"
}
},
"form": {
"options.unicode1": {
"clearable": true,
"type": "input"
},
"null": [
{
"title": "Configurer",
"type": "submit"
}
]
},
"version": "1.0"
}

View File

@ -0,0 +1,4 @@
{"cmd": "config.option('options.unicode1').value.set('val')",
"body": {"updates": [{"action": "modify",
"name": "options.unicode1",
"value": "val"}]}}

View File

@ -0,0 +1,12 @@
"""two unicode options
"""
from tiramisu.option import StrOption, OptionDescription, SymLinkOption
def get_description():
"""generate description for this test
"""
option1 = StrOption('unicode1', "Unicode 1", 'test')
option2 = SymLinkOption('unicode2', option1)
descr1 = OptionDescription("options", "Common configuration", [option1, option2])
descr = OptionDescription("unicode2_symlink", "One unicode, one symlink", [descr1])
return descr

View File

@ -0,0 +1,11 @@
{
"updates": [
"options.unicode1"
],
"model": {
"options.unicode1": {
"value": "val",
"owner": "user"
}
}
}

View File

@ -64,7 +64,7 @@ def parse_expected(schema, all_options):
for key, value in schema['properties'].items(): for key, value in schema['properties'].items():
if 'properties' in value: if 'properties' in value:
parse_expected(value, all_options) parse_expected(value, all_options)
else: elif value.get('type') != 'symlink':
all_options.append(key) all_options.append(key)
@ -206,6 +206,8 @@ def test_jsons_subconfig():
for key_schema, val_schema in schema.items(): for key_schema, val_schema in schema.items():
key = modulepath + '.' + key_schema key = modulepath + '.' + key_schema
val_schema['name'] = key val_schema['name'] = key
if 'opt_path' in val_schema:
val_schema['opt_path'] = modulepath + '.' + val_schema['opt_path']
if 'properties' in val_schema: if 'properties' in val_schema:
val_schema['properties'] = change_key(val_schema['properties']) val_schema['properties'] = change_key(val_schema['properties'])
new_schema[key] = val_schema new_schema[key] = val_schema
@ -273,6 +275,9 @@ def test_updates():
else: else:
root = None root = None
# dict before modification # dict before modification
if not isfile(join(datadir, modulepath + '.dict')):
dico_ori = None
else:
with open(join(datadir, modulepath + '.dict'), 'r') as fh: with open(join(datadir, modulepath + '.dict'), 'r') as fh:
dico_ori = loads(fh.read()) dico_ori = loads(fh.read())
if issub: if issub:
@ -288,6 +293,9 @@ def test_updates():
for value in body['updates']: for value in body['updates']:
value['name'] = modulepath + '.' + value['name'] value['name'] = modulepath + '.' + value['name']
# returns of set_updates # returns of set_updates
if not isfile(join(datadir, modulepath + '.updates{}'.format(idx))):
values = None
else:
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'r') as fh: with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'r') as fh:
values = loads(fh.read()) values = loads(fh.read())
if issub: if issub:
@ -299,6 +307,9 @@ def test_updates():
new_model[modulepath + '.' + key] = value new_model[modulepath + '.' + key] = value
values['model'] = new_model values['model'] = new_model
# dict after modification # dict after modification
if not isfile(join(datadir, modulepath + '.dict{}'.format(idx))):
dico_mod = None
else:
with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'r') as fh: with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'r') as fh:
dico_mod = loads(fh.read()) dico_mod = loads(fh.read())
if issub: if issub:
@ -323,6 +334,11 @@ def test_updates():
if isfile(join(datadir, modulepath + '.mod')): if isfile(join(datadir, modulepath + '.mod')):
with open(join(datadir, modulepath + '.mod'), 'r') as fh: with open(join(datadir, modulepath + '.mod'), 'r') as fh:
eval(fh.read()) eval(fh.read())
if dico_ori is None:
if clearable == 'minimum' and remote == 'minimum':
with open(join(datadir, modulepath + '.dict'), 'w') as fh:
dump(config.value.dict(), fh, indent=2)
else:
assert config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename) assert config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename)
if root is None: if root is None:
suboption = config.option suboption = config.option
@ -336,6 +352,11 @@ def test_updates():
bodym = body bodym = body
if with_model: if with_model:
cal_values = suboption.updates(bodym) cal_values = suboption.updates(bodym)
if values is None:
if clearable == 'minimum' and remote == 'minimum':
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'w') as fh:
dump(cal_values, fh, indent=2)
else:
if debug: if debug:
from pprint import pprint from pprint import pprint
pprint(cal_values) pprint(cal_values)
@ -344,4 +365,9 @@ def test_updates():
assert cal_values == values assert cal_values == values
else: else:
assert suboption.updates(bodym) is None assert suboption.updates(bodym) is None
if dico_mod is None:
if clearable == 'minimum' and remote == 'minimum':
with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'w') as fh:
dump(config.value.dict(), fh, indent=2)
else:
assert config.value.dict() == dico_mod assert config.value.dict() == dico_mod