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():
|
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,14 +275,17 @@ def test_updates():
|
||||||
else:
|
else:
|
||||||
root = None
|
root = None
|
||||||
# dict before modification
|
# dict before modification
|
||||||
with open(join(datadir, modulepath + '.dict'), 'r') as fh:
|
if not isfile(join(datadir, modulepath + '.dict')):
|
||||||
dico_ori = loads(fh.read())
|
dico_ori = None
|
||||||
if issub:
|
else:
|
||||||
new_dico_ori = {}
|
with open(join(datadir, modulepath + '.dict'), 'r') as fh:
|
||||||
for key, value in dico_ori.items():
|
dico_ori = loads(fh.read())
|
||||||
key = modulepath + '.' + key
|
if issub:
|
||||||
new_dico_ori[key] = value
|
new_dico_ori = {}
|
||||||
dico_ori = 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
|
# modify config
|
||||||
with open(join(datadir, modulepath + '.mod{}'.format(idx)), 'r') as fh:
|
with open(join(datadir, modulepath + '.mod{}'.format(idx)), 'r') as fh:
|
||||||
body = loads(fh.read())['body']
|
body = loads(fh.read())['body']
|
||||||
|
@ -288,25 +293,31 @@ 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
|
||||||
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'r') as fh:
|
if not isfile(join(datadir, modulepath + '.updates{}'.format(idx))):
|
||||||
values = loads(fh.read())
|
values = None
|
||||||
if issub:
|
else:
|
||||||
for lidx, key in enumerate(values['updates']):
|
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'r') as fh:
|
||||||
values['updates'][lidx] = modulepath + '.' + key
|
values = loads(fh.read())
|
||||||
if 'model' in values:
|
if issub:
|
||||||
new_model = {}
|
for lidx, key in enumerate(values['updates']):
|
||||||
for key, value in values['model'].items():
|
values['updates'][lidx] = modulepath + '.' + key
|
||||||
new_model[modulepath + '.' + key] = value
|
if 'model' in values:
|
||||||
values['model'] = new_model
|
new_model = {}
|
||||||
|
for key, value in values['model'].items():
|
||||||
|
new_model[modulepath + '.' + key] = value
|
||||||
|
values['model'] = new_model
|
||||||
# dict after modification
|
# dict after modification
|
||||||
with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'r') as fh:
|
if not isfile(join(datadir, modulepath + '.dict{}'.format(idx))):
|
||||||
dico_mod = loads(fh.read())
|
dico_mod = None
|
||||||
if issub:
|
else:
|
||||||
new_dico = {}
|
with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'r') as fh:
|
||||||
for key, value in dico_mod.items():
|
dico_mod = loads(fh.read())
|
||||||
key = modulepath + '.' + key
|
if issub:
|
||||||
new_dico[key] = value
|
new_dico = {}
|
||||||
dico_mod = new_dico
|
for key, value in dico_mod.items():
|
||||||
|
key = modulepath + '.' + key
|
||||||
|
new_dico[key] = value
|
||||||
|
dico_mod = new_dico
|
||||||
if root is None:
|
if root is None:
|
||||||
root_path = ''
|
root_path = ''
|
||||||
else:
|
else:
|
||||||
|
@ -323,7 +334,12 @@ 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())
|
||||||
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:
|
if root is None:
|
||||||
suboption = config.option
|
suboption = config.option
|
||||||
else:
|
else:
|
||||||
|
@ -336,12 +352,22 @@ def test_updates():
|
||||||
bodym = body
|
bodym = body
|
||||||
if with_model:
|
if with_model:
|
||||||
cal_values = suboption.updates(bodym)
|
cal_values = suboption.updates(bodym)
|
||||||
if debug:
|
if values is None:
|
||||||
from pprint import pprint
|
if clearable == 'minimum' and remote == 'minimum':
|
||||||
pprint(cal_values)
|
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'w') as fh:
|
||||||
print('------------')
|
dump(cal_values, fh, indent=2)
|
||||||
pprint(values)
|
else:
|
||||||
assert cal_values == values
|
if debug:
|
||||||
|
from pprint import pprint
|
||||||
|
pprint(cal_values)
|
||||||
|
print('------------')
|
||||||
|
pprint(values)
|
||||||
|
assert cal_values == values
|
||||||
else:
|
else:
|
||||||
assert suboption.updates(bodym) is None
|
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