First implementation of Debugger for SyaNodeParser

This commit is contained in:
2020-12-03 21:50:48 +01:00
parent 4f899280c4
commit 8b86998225
48 changed files with 1781 additions and 1795 deletions
+11 -3
View File
@@ -142,7 +142,7 @@ class TestAsStrVisitor(TestUsingMemoryBasedSheerka):
(FormatAstVariable('__key', index=0, value="key1", debug=True),
FormatAstVariable('__value', index="key1", value=1, debug=True)),
(FormatAstVariable('__key', index=0, value="key2", debug=True),
(FormatAstVariable('__key', index=1, value="key2", debug=True),
FormatAstDict("__value", debug=True, prefix="{", suffix="}", items=[
(FormatAstVariable('__key', index=0, value="sub_key1", debug=True),
FormatAstVariable('__value', index="sub_key1", value=1, debug=True)),
@@ -155,8 +155,14 @@ class TestAsStrVisitor(TestUsingMemoryBasedSheerka):
])),
])),
(FormatAstVariable('__key', index=1, value="long_key3", debug=True),
(FormatAstVariable('__key', index=2, value="long_key3", debug=True),
FormatAstVariable('__value', index="key2", value="value2", debug=True)),
(FormatAstVariable('__key', index=3, value="key3", debug=True),
FormatAstList("__value", debug=True, prefix="[", suffix="]", items=[
FormatAstVariable('__item', index=0, value="first element", debug=True),
FormatAstVariable('__item', index=1, value="second element", debug=True),
])),
])
res = visitor.visit(bag)
@@ -165,4 +171,6 @@ class TestAsStrVisitor(TestUsingMemoryBasedSheerka):
'key2' : {'sub_key1' : 1,
'sub_long_key2': {'sub_sub_key1': 1,
'sub_sub_key2': 'sub_sub_value'}},
'long_key3': 'value2'}"""
'long_key3': 'value2',
'key3' : ['first element',
'second element']}"""
+40
View File
@@ -0,0 +1,40 @@
from core.sheerka.services.SheerkaDebugManager import NullDebugLogger
from core.sheerka.services.SheerkaOut import SheerkaOut
from core.sheerka.services.SheerkaRuleManager import FormatAstList, FormatAstVariable
from out.DeveloperVisitor import DeveloperVisitor
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
class TestDeveloperVisitor(TestUsingMemoryBasedSheerka):
def test_i_can_develop_list(self):
sheerka, context = self.init_concepts()
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
bag = {"a": ["a", "b", "c"]}
res = dev_visitor.visit(context, FormatAstList("a"), bag)
assert res == FormatAstList(variable="a", items=[
FormatAstVariable(name="__item", index=0, value="a"),
FormatAstVariable(name="__item", index=1, value="b"),
FormatAstVariable(name="__item", index=2, value="c"),
])
def test_i_can_develop_list_of_list(self):
sheerka, context = self.init_concepts()
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
bag = {"a": [["a1", "a2"], ["b1"]]}
res = dev_visitor.visit(context, FormatAstList("a"), bag)
assert res == FormatAstList(variable="a", items=[
FormatAstList(variable="__item", index=0, debug=True, prefix='[', suffix=']', items=[
FormatAstVariable(name="__item", index=0, debug=True, value="a1"),
FormatAstVariable(name="__item", index=1, debug=True, value="a2"),
]),
FormatAstList(variable="__item", index=1, debug=True, prefix='[', suffix=']', items=[
FormatAstVariable(name="__item", index=0, debug=True, value="b1"),
]),
])
+48
View File
@@ -449,3 +449,51 @@ key2: value2
captured = capsys.readouterr()
assert captured.out == """{'\x1b[32mkey1\x1b[0m': 'value1', 'key2': 1, 'key3': DummyObj(prop_1=3.15, prop_2='a string'), 'key4': ['alpha', 0]}
"""
def test_i_can_print_out_dict_sub_items(self, capsys):
sheerka, context, service, *rules = self.init_service_with_rules(
("isinstance(__obj, dict)", "dict(__obj)"),
("__key=='key1'", "green(__key)")
)
obj = {
"key1": "value1",
"key2": 1,
"key3": DummyObj(prop_1=3.15, prop_2='a string'),
"key4": {"a": 1, "b": "value"},
"key5": ["alpha", 0]
}
service.process_return_values(context, obj)
captured = capsys.readouterr()
assert captured.out == """\x1b[32mkey1\x1b[0m: value1
key2: 1
key3: DummyObj(prop_1=3.15, prop_2='a string')
key4: {'a': 1, 'b': 'value'}
key5: ['alpha', 0]
"""
def test_i_can_print_out_dict_with_expanded_sub_items(self, capsys):
sheerka, context, service, *rules = self.init_service_with_rules(
("isinstance(__obj, dict)", "dict(__obj)"),
("__key=='key1'", "green(__key)")
)
obj = {
"key1": "value1",
"key2": 1,
"key3": DummyObj(prop_1=3.15, prop_2='a string'),
"key4": {"a": 1, "b": "value"},
"key5": ["alpha", 0]
}
old_value = service.out_visitors[0].console_width
service.out_visitors[0].console_width = 5
service.process_return_values(context, obj)
captured = capsys.readouterr()
assert captured.out == """\x1b[32mkey1\x1b[0m: value1
key2: 1
key3: DummyObj(prop_1=3.15, prop_2='a string')
key4: {'a': 1,
'b': 'value'}
key5: ['alpha',
0]
"""
service.out_visitors[0].console_width = old_value