Fixed error when desc() returns multiple results

This commit is contained in:
2020-12-04 17:37:06 +01:00
parent 8b86998225
commit d364878ddb
16 changed files with 408 additions and 19 deletions
+46 -7
View File
@@ -1,6 +1,7 @@
from core.builtin_concepts import BuiltinConcepts
from core.sheerka.services.SheerkaDebugManager import NullDebugLogger
from core.sheerka.services.SheerkaOut import SheerkaOut
from core.sheerka.services.SheerkaRuleManager import FormatAstList, FormatAstVariable
from core.sheerka.services.SheerkaRuleManager import FormatAstList, FormatAstVariable, FormatAstDict, FormatAstMulti
from out.DeveloperVisitor import DeveloperVisitor
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
@@ -12,10 +13,10 @@ class TestDeveloperVisitor(TestUsingMemoryBasedSheerka):
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
bag = {"a": ["a", "b", "c"]}
bag = {"to_format": ["a", "b", "c"]}
res = dev_visitor.visit(context, FormatAstList("a"), bag)
assert res == FormatAstList(variable="a", items=[
res = dev_visitor.visit(context, FormatAstList("to_format"), bag)
assert res == FormatAstList(variable="to_format", items=[
FormatAstVariable(name="__item", index=0, value="a"),
FormatAstVariable(name="__item", index=1, value="b"),
FormatAstVariable(name="__item", index=2, value="c"),
@@ -26,10 +27,10 @@ class TestDeveloperVisitor(TestUsingMemoryBasedSheerka):
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
bag = {"a": [["a1", "a2"], ["b1"]]}
bag = {"to_format": [["a1", "a2"], ["b1"]]}
res = dev_visitor.visit(context, FormatAstList("a"), bag)
assert res == FormatAstList(variable="a", items=[
res = dev_visitor.visit(context, FormatAstList("to_format"), bag)
assert res == FormatAstList(variable="to_format", 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"),
@@ -38,3 +39,41 @@ class TestDeveloperVisitor(TestUsingMemoryBasedSheerka):
FormatAstVariable(name="__item", index=0, debug=True, value="b1"),
]),
])
def test_i_can_develop_dict(self):
sheerka, context = self.init_concepts()
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
bag = {"to_format": {"a": "value1", "b": 3.14}}
res = dev_visitor.visit(context, FormatAstDict("to_format"), bag)
assert res == FormatAstDict(variable='to_format', items=[
(FormatAstVariable(name='__key', index=0, value='a'),
FormatAstVariable(name='__value', index='a', value='value1')),
(FormatAstVariable(name='__key', index=1, value='b'),
FormatAstVariable(name='__value', index='b', value=3.14))])
def test_i_can_develop_multi(self):
sheerka, context, *rules = self.init_format_rules(
("isinstance(to_format, BuiltinConcepts.TO_DICT)", "dict(to_format)"))
service_out = sheerka.services[SheerkaOut.NAME]
dev_visitor = DeveloperVisitor(service_out, NullDebugLogger(), set(), 0)
item1 = sheerka.new(BuiltinConcepts.TO_DICT, body={"a1": "value1"})
item2 = sheerka.new(BuiltinConcepts.TO_DICT, body={"a2": "value2"})
bag = {"to_format": sheerka.new(BuiltinConcepts.TO_MULTI, body=[item1, item2])}
res = dev_visitor.visit(context, FormatAstMulti("to_format"), bag)
assert res == FormatAstMulti("to_format", items=[
FormatAstDict(variable='to_format', items=[
(FormatAstVariable(name='__key', index=0, value='a1'),
FormatAstVariable(name='__value', index='a1', value='value1'))]),
FormatAstDict(variable='to_format', items=[
(FormatAstVariable(name='__key', index=0, value='a2'),
FormatAstVariable(name='__value', index='a2', value='value2'))])
])