Repository: iaroslavscript/elk-confd-parser

Issue:
hot fix for root.append AttributeError: 'dict' object has no attribute 'append'

Discussion:

Patch:
diff --git a/elkconfdparser/cli.py b/elkconfdparser/cli.py
index d8d92a7..9e296b3 100644
--- a/elkconfdparser/cli.py
+++ b/elkconfdparser/cli.py
@@ -37,4 +37,4 @@ def display(data):
 
 
 if __name__ == "__main__":  # noqa
-    main(sys.argv[1:])
\ No newline at end of file
+    main(sys.argv[1:])
diff --git a/elkconfdparser/parser.py b/elkconfdparser/parser.py
index a4406fb..0fe7718 100644
--- a/elkconfdparser/parser.py
+++ b/elkconfdparser/parser.py
@@ -104,7 +104,7 @@ def _parse(text, start, end):  # noqa: C901  # FIXME
 
 def _drop_stack(root, stack):
     if len(stack) > 1:
-        root.append({stack.pop(): stack.pop()})
+        root.setdefault(stack.pop(), []).append(stack.pop())
 
         if len(stack):
             raise errors.StackNotEmptyException('Unknown operands left on stack after assigment')


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 5a90c3a..8f1c6ea 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -3,6 +3,7 @@ import pytest
 from elkconfdparser import errors
 from elkconfdparser import parser
 
+
 class TestDropStack:
     @pytest.mark.parametrize(
         "input_root, input_stack, expected_root, expected_stack",
@@ -10,11 +11,11 @@ class TestDropStack:
             ({}, [], {}, []),
             ({}, [1], {}, [1]),
             ({}, [2, 1], {1: [2]}, []),
-            ({1:[8]}, [2, 1], {1: [8, 2]}, []),
-            ({1:[8], 3: [9]}, [2, 1], {1: [8, 2], 3: [9]}, []),
+            ({1: [8]}, [2, 1], {1: [8, 2]}, []),
+            ({1: [8], 3: [9]}, [2, 1], {1: [8, 2], 3: [9]}, []),
         ],
     )
-    def testTwoOperands(input_root, input_stack, expected_root, expected_stack):
+    def testTwoOperands(self, input_root, input_stack, expected_root, expected_stack):
 
         assert parser._drop_stack(input_root, input_stack) is None
         assert input_root == expected_root
@@ -23,10 +24,10 @@ class TestDropStack:
     @pytest.mark.parametrize(
         "input_root, input_stack, expected_root, expected_stack",
         [
-            ({}, [3, 2, 1,], {1: [2]}, [3]),
+            ({}, [3, 2, 1], {1: [2]}, [3]),
         ],
     )
-    def testMultipleOperands(input_root, input_stack, expected_root, expected_stack):
+    def testMultipleOperands(self, input_root, input_stack, expected_root, expected_stack):
 
         with pytest.raises(errors.StackNotEmptyException, match=r'.*operands left.*'):
             parser._drop_stack(input_root, input_stack)