From 35b6fd75c3e0175585cd2a668836c3caca56adad Mon Sep 17 00:00:00 2001 From: "Rem M." Date: Wed, 26 Jun 2024 18:16:59 +0700 Subject: [PATCH] Fix stylish logix --- gendiff/formatters/stylish.py | 4 +++- tests/test_stylish.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gendiff/formatters/stylish.py b/gendiff/formatters/stylish.py index e5e5c4c..9bc79d8 100644 --- a/gendiff/formatters/stylish.py +++ b/gendiff/formatters/stylish.py @@ -5,7 +5,7 @@ def prepare_value(value): if isinstance(value, dict): - return "{" + return "" elif isinstance(value, bool): return str(value).lower() elif value is None: @@ -35,7 +35,9 @@ def iter_(current_data, level=1): nested_result = iter_(current_data[key], level + 1) + if nested_result: + result[-1] += "{" result.extend(nested_result) result.append(f"{indent}{SHIFT_SIZE * INDENT_SYMBOL}}}") diff --git a/tests/test_stylish.py b/tests/test_stylish.py index f424260..eadeb2f 100644 --- a/tests/test_stylish.py +++ b/tests/test_stylish.py @@ -25,11 +25,11 @@ def file1_2_nested_str(): return data -@pytest.mark.parametrize("test_input,expected", [({"name": "value"}, "{"), +@pytest.mark.parametrize("test_input,expected", [({"name": "value"}, ""), (True, "true"), (False, "false"), (None, "null"), - ({}, "{")]) + ({}, "")]) def test_prepare_value(test_input, expected): assert prepare_value(test_input) == expected