From dc8010f0af83c66b5f0b2fb035dec240c20cff44 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 4 Aug 2020 16:43:40 +0200 Subject: [PATCH] calc_value with join parameter now work if an option is empty --- tests/test_option_callback.py | 9 ++++++--- tiramisu/function.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_option_callback.py b/tests/test_option_callback.py index 491aafe..a0c402c 100644 --- a/tests/test_option_callback.py +++ b/tests/test_option_callback.py @@ -1433,11 +1433,14 @@ async def test_calc_value_remove_duplicate(config_type): async def test_calc_value_join(config_type): val1 = StrOption('val1', "", 'val1') val2 = StrOption('val2', "", 'val2') - val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.')))) - od = OptionDescription('root', '', [val1, val2, val3]) + val3 = StrOption('val3', "") + val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2), ParamOption(val3)), join=ParamValue('.')))) + od = OptionDescription('root', '', [val1, val2, val3, val4]) async with await Config(od) as cfg: cfg = await get_config(cfg, config_type) - assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'} + assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': None, 'val4': None} + await cfg.option('val3').value.set('val3') + assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'} assert not await list_sessions() diff --git a/tiramisu/function.py b/tiramisu/function.py index f96ea5d..1779bcb 100644 --- a/tiramisu/function.py +++ b/tiramisu/function.py @@ -311,7 +311,10 @@ class CalcValue: min_args_len) if not multi: if join is not None: - value = join.join(value) + if None not in value: + value = join.join(value) + else: + value = None elif value and operator: new_value = value[0] op = {'mul': mul,