better symlink support for option.dict()
This commit is contained in:
parent
63094f7e54
commit
829247e79f
7 changed files with 138 additions and 35 deletions
4
tests/dict/data/unicode2_symlink.dict
Normal file
4
tests/dict/data/unicode2_symlink.dict
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"options.unicode1": "test",
|
||||
"options.unicode2": "test"
|
||||
}
|
4
tests/dict/data/unicode2_symlink.dict1
Normal file
4
tests/dict/data/unicode2_symlink.dict1
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"options.unicode1": "val",
|
||||
"options.unicode2": "val"
|
||||
}
|
42
tests/dict/data/unicode2_symlink.json
Normal file
42
tests/dict/data/unicode2_symlink.json
Normal 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"
|
||||
}
|
4
tests/dict/data/unicode2_symlink.mod1
Normal file
4
tests/dict/data/unicode2_symlink.mod1
Normal file
|
@ -0,0 +1,4 @@
|
|||
{"cmd": "config.option('options.unicode1').value.set('val')",
|
||||
"body": {"updates": [{"action": "modify",
|
||||
"name": "options.unicode1",
|
||||
"value": "val"}]}}
|
12
tests/dict/data/unicode2_symlink.py
Normal file
12
tests/dict/data/unicode2_symlink.py
Normal 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
|
11
tests/dict/data/unicode2_symlink.updates1
Normal file
11
tests/dict/data/unicode2_symlink.updates1
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"updates": [
|
||||
"options.unicode1"
|
||||
],
|
||||
"model": {
|
||||
"options.unicode1": {
|
||||
"value": "val",
|
||||
"owner": "user"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,7 +64,7 @@ def parse_expected(schema, all_options):
|
|||
for key, value in schema['properties'].items():
|
||||
if 'properties' in value:
|
||||
parse_expected(value, all_options)
|
||||
else:
|
||||
elif value.get('type') != 'symlink':
|
||||
all_options.append(key)
|
||||
|
||||
|
||||
|
@ -206,6 +206,8 @@ def test_jsons_subconfig():
|
|||
for key_schema, val_schema in schema.items():
|
||||
key = modulepath + '.' + key_schema
|
||||
val_schema['name'] = key
|
||||
if 'opt_path' in val_schema:
|
||||
val_schema['opt_path'] = modulepath + '.' + val_schema['opt_path']
|
||||
if 'properties' in val_schema:
|
||||
val_schema['properties'] = change_key(val_schema['properties'])
|
||||
new_schema[key] = val_schema
|
||||
|
@ -273,6 +275,9 @@ def test_updates():
|
|||
else:
|
||||
root = None
|
||||
# dict before modification
|
||||
if not isfile(join(datadir, modulepath + '.dict')):
|
||||
dico_ori = None
|
||||
else:
|
||||
with open(join(datadir, modulepath + '.dict'), 'r') as fh:
|
||||
dico_ori = loads(fh.read())
|
||||
if issub:
|
||||
|
@ -288,6 +293,9 @@ def test_updates():
|
|||
for value in body['updates']:
|
||||
value['name'] = modulepath + '.' + value['name']
|
||||
# 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:
|
||||
values = loads(fh.read())
|
||||
if issub:
|
||||
|
@ -299,6 +307,9 @@ def test_updates():
|
|||
new_model[modulepath + '.' + key] = value
|
||||
values['model'] = new_model
|
||||
# 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:
|
||||
dico_mod = loads(fh.read())
|
||||
if issub:
|
||||
|
@ -323,6 +334,11 @@ def test_updates():
|
|||
if isfile(join(datadir, modulepath + '.mod')):
|
||||
with open(join(datadir, modulepath + '.mod'), 'r') as fh:
|
||||
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)
|
||||
if root is None:
|
||||
suboption = config.option
|
||||
|
@ -336,6 +352,11 @@ def test_updates():
|
|||
bodym = body
|
||||
if with_model:
|
||||
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:
|
||||
from pprint import pprint
|
||||
pprint(cal_values)
|
||||
|
@ -344,4 +365,9 @@ def test_updates():
|
|||
assert cal_values == values
|
||||
else:
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue