better symlink support for option.dict()
This commit is contained in:
parent
63094f7e54
commit
829247e79f
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"options.unicode1": "test",
|
||||
"options.unicode2": "test"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"options.unicode1": "val",
|
||||
"options.unicode2": "val"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{"cmd": "config.option('options.unicode1').value.set('val')",
|
||||
"body": {"updates": [{"action": "modify",
|
||||
"name": "options.unicode1",
|
||||
"value": "val"}]}}
|
|
@ -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
|
|
@ -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,14 +275,17 @@ def test_updates():
|
|||
else:
|
||||
root = None
|
||||
# dict before modification
|
||||
with open(join(datadir, modulepath + '.dict'), 'r') as fh:
|
||||
dico_ori = loads(fh.read())
|
||||
if issub:
|
||||
new_dico_ori = {}
|
||||
for key, value in dico_ori.items():
|
||||
key = modulepath + '.' + key
|
||||
new_dico_ori[key] = value
|
||||
dico_ori = new_dico_ori
|
||||
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:
|
||||
new_dico_ori = {}
|
||||
for key, value in dico_ori.items():
|
||||
key = modulepath + '.' + key
|
||||
new_dico_ori[key] = value
|
||||
dico_ori = new_dico_ori
|
||||
# modify config
|
||||
with open(join(datadir, modulepath + '.mod{}'.format(idx)), 'r') as fh:
|
||||
body = loads(fh.read())['body']
|
||||
|
@ -288,25 +293,31 @@ def test_updates():
|
|||
for value in body['updates']:
|
||||
value['name'] = modulepath + '.' + value['name']
|
||||
# returns of set_updates
|
||||
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'r') as fh:
|
||||
values = loads(fh.read())
|
||||
if issub:
|
||||
for lidx, key in enumerate(values['updates']):
|
||||
values['updates'][lidx] = modulepath + '.' + key
|
||||
if 'model' in values:
|
||||
new_model = {}
|
||||
for key, value in values['model'].items():
|
||||
new_model[modulepath + '.' + key] = value
|
||||
values['model'] = new_model
|
||||
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:
|
||||
for lidx, key in enumerate(values['updates']):
|
||||
values['updates'][lidx] = modulepath + '.' + key
|
||||
if 'model' in values:
|
||||
new_model = {}
|
||||
for key, value in values['model'].items():
|
||||
new_model[modulepath + '.' + key] = value
|
||||
values['model'] = new_model
|
||||
# dict after modification
|
||||
with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'r') as fh:
|
||||
dico_mod = loads(fh.read())
|
||||
if issub:
|
||||
new_dico = {}
|
||||
for key, value in dico_mod.items():
|
||||
key = modulepath + '.' + key
|
||||
new_dico[key] = value
|
||||
dico_mod = new_dico
|
||||
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:
|
||||
new_dico = {}
|
||||
for key, value in dico_mod.items():
|
||||
key = modulepath + '.' + key
|
||||
new_dico[key] = value
|
||||
dico_mod = new_dico
|
||||
if root is None:
|
||||
root_path = ''
|
||||
else:
|
||||
|
@ -323,7 +334,12 @@ def test_updates():
|
|||
if isfile(join(datadir, modulepath + '.mod')):
|
||||
with open(join(datadir, modulepath + '.mod'), 'r') as fh:
|
||||
eval(fh.read())
|
||||
assert config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename)
|
||||
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
|
||||
else:
|
||||
|
@ -336,12 +352,22 @@ def test_updates():
|
|||
bodym = body
|
||||
if with_model:
|
||||
cal_values = suboption.updates(bodym)
|
||||
if debug:
|
||||
from pprint import pprint
|
||||
pprint(cal_values)
|
||||
print('------------')
|
||||
pprint(values)
|
||||
assert cal_values == values
|
||||
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)
|
||||
print('------------')
|
||||
pprint(values)
|
||||
assert cal_values == values
|
||||
else:
|
||||
assert suboption.updates(bodym) is None
|
||||
assert config.value.dict() == dico_mod
|
||||
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 New Issue