From 8b4ceddb81d92848a67b0882aa8ecbc7f77ac678 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 12 Apr 2023 12:01:56 +0200 Subject: [PATCH] calc_value: remove duplicate value even if use join --- tests/test_option_callback.py | 12 ++++++++++++ tiramisu/function.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_option_callback.py b/tests/test_option_callback.py index bed5273..3f64c5f 100644 --- a/tests/test_option_callback.py +++ b/tests/test_option_callback.py @@ -1514,6 +1514,18 @@ async def test_calc_value_remove_duplicate(config_type): assert not await list_sessions() +@pytest.mark.asyncio +async def test_calc_value_remove_duplicate2(config_type): + val1 = StrOption('val1', "", ['val1', 'val1'], multi=True, properties=('notunique',)) + val2 = StrOption('val2', "", ['val1', 'val1'], multi=True, properties=('notunique',)) + val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True), join=ParamValue('-'))), multi=True) + od = OptionDescription('root', '', [val1, val2, val3]) + async with await Config(od) as cfg: + cfg = await get_config(cfg, config_type) + assert await cfg.value.dict() == {'val1': ['val1', 'val1'], 'val2': ['val1', 'val1'], 'val3': ['val1-val1']} + assert not await list_sessions() + + @pytest.mark.asyncio async def test_calc_value_join(config_type): val1 = StrOption('val1', "", 'val1') diff --git a/tiramisu/function.py b/tiramisu/function.py index 8e2001e..8e4cfb5 100644 --- a/tiramisu/function.py +++ b/tiramisu/function.py @@ -361,7 +361,7 @@ class CalcValue: value = [] elif None in value and not allow_none: value = [] - elif remove_duplicate_value: + if remove_duplicate_value: new_value = [] for val in value: if val not in new_value: