71d1b1d1ca
Fixed #103 : Implement PlurialNodeParser Fixed #104 : Implement dynamic concept Fixed #107 : PrepareEvalxxxEvaluator: context hints are lost on a second evaluation
76 lines
3.2 KiB
Python
76 lines
3.2 KiB
Python
from core.builtin_concepts import BuiltinConcepts
|
|
|
|
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
|
|
|
|
|
class TestSheerkaHasAManager(TestUsingMemoryBasedSheerka):
|
|
def test_i_can_set_hasa(self):
|
|
sheerka, context, king, kingdom = self.init_concepts("king", "kingdom")
|
|
|
|
king_instance = sheerka.new("king")
|
|
res = sheerka.set_hasa(context, king_instance, kingdom)
|
|
|
|
assert res.status
|
|
assert king_instance.get_prop(BuiltinConcepts.HASA) == {kingdom}
|
|
assert sheerka.hasa(king_instance, kingdom)
|
|
|
|
# when global truth is not activated, only the current instance is modified
|
|
another_king = sheerka.get_by_key("king")
|
|
assert not another_king.get_prop(BuiltinConcepts.HASA) == {kingdom}
|
|
assert not sheerka.hasa(another_king, kingdom)
|
|
|
|
def test_i_cannot_set_the_same_attribute_twice(self):
|
|
sheerka, context, king, kingdom = self.init_concepts("king", "kingdom")
|
|
|
|
king_instance = sheerka.new("king")
|
|
sheerka.set_hasa(context, king_instance, kingdom)
|
|
res = sheerka.set_hasa(context, king_instance, kingdom)
|
|
|
|
assert not res.status
|
|
assert sheerka.isinstance(res.body, BuiltinConcepts.PROPERTY_ALREADY_DEFINED)
|
|
assert res.body.property_name == BuiltinConcepts.HASA
|
|
assert res.body.property_value == kingdom
|
|
assert res.body.concept == king_instance
|
|
|
|
def test_i_can_set_hasa_when_global_truth_is_activated(self):
|
|
sheerka, context, king, kingdom = self.init_test(global_truth=True).with_concepts(
|
|
"king",
|
|
"kingdom").unpack()
|
|
|
|
res = sheerka.set_hasa(context, sheerka.new("king"), kingdom)
|
|
assert res.status
|
|
|
|
another_king = sheerka.get_by_key("king")
|
|
assert another_king.get_prop(BuiltinConcepts.HASA) == {kingdom}
|
|
|
|
# check that the definition of the concept has been updated
|
|
assert sheerka.hasa(sheerka.new("king"), kingdom)
|
|
|
|
def test_i_cannot_set_the_same_attribute_twice_when_global_truth_is_activated(self):
|
|
sheerka, context, king, kingdom = self.init_test(global_truth=True).with_concepts(
|
|
"king",
|
|
"kingdom").unpack()
|
|
|
|
sheerka.set_hasa(context, sheerka.new("king"), kingdom)
|
|
res = sheerka.set_hasa(context, sheerka.new("king"), kingdom)
|
|
|
|
assert not res.status
|
|
assert sheerka.isinstance(res.body, BuiltinConcepts.PROPERTY_ALREADY_DEFINED)
|
|
assert res.body.property_name == BuiltinConcepts.HASA
|
|
assert res.body.property_value == kingdom
|
|
assert res.body.concept == sheerka.new("king")
|
|
|
|
def test_i_can_set_hase_twice_when_global_truth_is_true_the_second_time(self):
|
|
sheerka, context, king, kingdom = self.init_concepts("king", "kingdom")
|
|
global_truth_context = self.get_context(sheerka, global_truth=True)
|
|
|
|
king_instance = sheerka.new("king")
|
|
sheerka.set_hasa(context, king_instance, kingdom)
|
|
|
|
# set it again with global_truth = True
|
|
res = sheerka.set_hasa(global_truth_context, king_instance, kingdom)
|
|
|
|
assert res.status
|
|
assert sheerka.hasa(king_instance, kingdom)
|
|
assert sheerka.hasa(sheerka.new("king"), kingdom) # try another instance
|