1059ce25c5
Fixed #70: SheerkaFilterManager : Pipe functions Fixed #71: SheerkaFilterManager : filter_objects Fixed #75: SheerkaMemory: Enhance memory() to use the filtering capabilities Fixed #76: SheerkaEvaluateConcept: Concepts that modify the state of the system must not be evaluated during question
86 lines
3.0 KiB
Python
86 lines
3.0 KiB
Python
from core.builtin_concepts_ids import BuiltinConcepts
|
|
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
|
|
|
|
|
class TestSheerkaNonRegPipeFunctions(TestUsingMemoryBasedSheerka):
|
|
def test_i_can_filter_a_list_using_pipe(self):
|
|
init = [
|
|
"def concept one as 1",
|
|
"def concept two as 2",
|
|
"def concept three as 3",
|
|
"add_to_memory('x', [one, two, three])"
|
|
]
|
|
|
|
sheerka = self.init_scenario(init)
|
|
res = sheerka.evaluate_user_input("x | where(body=2)")
|
|
|
|
assert len(res) == 1
|
|
assert res[0].status
|
|
assert isinstance(res[0].body, list)
|
|
assert len(res[0].body) == 1
|
|
assert sheerka.isinstance(res[0].body[0], "two")
|
|
|
|
res = sheerka.evaluate_user_input("x | where(__self=two)")
|
|
assert len(res) == 1
|
|
assert res[0].status
|
|
assert isinstance(res[0].body, list)
|
|
assert len(res[0].body) == 1
|
|
assert sheerka.isinstance(res[0].body[0], "two")
|
|
|
|
def test_i_can_filter_using_sheerka_methods(self):
|
|
init = [
|
|
"def concept one as 1",
|
|
"def concept number",
|
|
"set_isa(one, number)",
|
|
"add_to_memory('x', [one])"
|
|
]
|
|
|
|
sheerka = self.init_scenario(init)
|
|
res = sheerka.evaluate_user_input("x | where('isa(self, number)')")
|
|
|
|
assert len(res) == 1
|
|
assert res[0].status
|
|
assert isinstance(res[0].body, list)
|
|
assert len(res[0].body) == 1
|
|
assert sheerka.isinstance(res[0].body[0], "one")
|
|
|
|
def test_i_can_select_properties(self):
|
|
init = [
|
|
"def concept one as 1",
|
|
"def concept two as 2",
|
|
"def concept three as 3",
|
|
"add_to_memory('x', [one, two, three])"
|
|
]
|
|
|
|
sheerka = self.init_scenario(init)
|
|
|
|
res = sheerka.evaluate_user_input("x | select('id', 'name')")
|
|
assert len(res) == 1
|
|
assert res[0].status
|
|
assert res[0].body == (("1001", "one"), ("1002", "two"), ("1003", "three"))
|
|
|
|
res = sheerka.evaluate_user_input("x | select(p1='id', p2='name')")
|
|
assert len(res) == 1
|
|
assert res[0].status
|
|
assert res[0].body == ({"p1": "1001", "p2": "one"},
|
|
{"p1": "1002", "p2": "two"},
|
|
{"p1": "1003", "p2": "three"})
|
|
|
|
def test_i_can_collect_properties(self):
|
|
init = [
|
|
"def concept one as 1",
|
|
"def concept isa from x is a y def_var x def_var y",
|
|
"def concept plus from a plus b as a + b",
|
|
"add_to_memory('x', [one, isa, plus])"
|
|
]
|
|
|
|
sheerka = self.init_scenario(init)
|
|
res = sheerka.evaluate_user_input("x | props()")
|
|
|
|
assert len(res) == 1
|
|
assert res[0].status
|
|
assert sheerka.isinstance(res[0].body, BuiltinConcepts.TO_DICT)
|
|
assert res[0].body.body == {'isa': ['body', 'id', 'key', 'name', 'x', 'y'],
|
|
'one': ['body', 'id', 'key', 'name'],
|
|
'plus': ['a', 'b', 'body', 'id', 'key', 'name']}
|