Files
Sheerka-Old/tests/non_reg/test_sheerka_non_reg_pipe_functions.py
T
kodjo e69745adc8 Fixed #100 : SheerkaAdmin: Add builtins() command
Fixed #99 : SheerkaQueryManager: I can manage contains predicate when filtering objects
Fixed #97 : ERROR: list indices must be integers or slices, not Concept
Fixed #96 : SequenceNodeParser: SequenceNodeParser must correctly handle concept definition
Fixed #95 : ResolveAmbiguity must not remove concepts that do not require evaluation
Fixed #94 : Concepts with the same key are lost when new ontology
Fixed #93 : Introduce BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED
Fixed #92 : ExpressionParser: Implement compile_disjunctions()
Fixed #91 : Implement get_concepts_complexity(context, concepts, concept_parts)
Fixed #90 : ResolveAmbiguity : where predicate is not used to resolve ambiguity
Fixed #89 : ResolveAmbiguityEvaluator: Concepts embedded in ConceptNode are not resolved
Fixed #88: SyaNodeParser: Parse multiple parameters when some of the are not recognized
Fixed #87: SyaNodeParser : Parse the multiple parameters
2021-07-31 08:52:00 +02:00

86 lines
3.1 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, global_truth=True)
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']}