71d1b1d1ca
Fixed #103 : Implement PlurialNodeParser Fixed #104 : Implement dynamic concept Fixed #107 : PrepareEvalxxxEvaluator: context hints are lost on a second evaluation
77 lines
3.0 KiB
Python
77 lines
3.0 KiB
Python
from core.builtin_concepts_ids import BuiltinConcepts
|
|
from core.global_symbols import NotFound
|
|
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
|
|
|
|
|
class TestSheerkaPluralManager(TestUsingMemoryBasedSheerka):
|
|
def test_i_can_set_plural(self):
|
|
sheerka, context, man, men = self.init_concepts("man", "men")
|
|
|
|
men_instance = sheerka.new("men")
|
|
res = sheerka.set_plural(context, men_instance, man)
|
|
|
|
assert res.status
|
|
assert men_instance.get_prop(BuiltinConcepts.PLURAL) == man
|
|
assert sheerka.is_plural(men_instance)
|
|
assert sheerka.is_plural(men_instance, man)
|
|
|
|
# global truth is not set
|
|
another_instance = sheerka.new("men")
|
|
assert another_instance.get_prop(BuiltinConcepts.PLURAL) is None
|
|
|
|
def test_i_can_set_plural_when_global_truth_is_set(self):
|
|
sheerka, context, man, men = self.init_concepts("man", "men", global_truth=True)
|
|
|
|
assert sheerka.known_plural(man) == NotFound
|
|
|
|
res = sheerka.set_plural(context, men, man)
|
|
|
|
assert res.status
|
|
assert sheerka.is_plural(men)
|
|
|
|
another_instance = sheerka.new("men")
|
|
assert sheerka.is_plural(another_instance)
|
|
assert sheerka.known_plural(man) == men.id
|
|
|
|
def test_i_cannot_set_plural_twice(self):
|
|
sheerka, context, man, men = self.init_concepts("man", "men")
|
|
men_instance = sheerka.new("men")
|
|
sheerka.set_plural(context, men_instance, man)
|
|
|
|
res = sheerka.set_plural(context, men_instance, man)
|
|
|
|
assert not res.status
|
|
assert sheerka.isinstance(res.body, BuiltinConcepts.PROPERTY_ALREADY_DEFINED)
|
|
assert res.body.concept == men_instance
|
|
assert res.body.property_name == BuiltinConcepts.PLURAL
|
|
assert res.body.property_value == man
|
|
|
|
def test_i_cannot_set_plural_twice_when_global_truth(self):
|
|
sheerka, context, man, men = self.init_concepts("man", "men", global_truth=True)
|
|
sheerka.set_plural(context, men, man)
|
|
|
|
another_instance = sheerka.new("men")
|
|
res = sheerka.set_plural(context, another_instance, man)
|
|
|
|
assert not res.status
|
|
assert sheerka.isinstance(res.body, BuiltinConcepts.PROPERTY_ALREADY_DEFINED)
|
|
assert res.body.concept == another_instance
|
|
assert res.body.property_name == BuiltinConcepts.PLURAL
|
|
assert res.body.property_value == man
|
|
|
|
def test_i_can_set_plural_twice_when_global_truth_is_true_the_second_time(self):
|
|
sheerka, context, man, men = self.init_concepts("man", "men")
|
|
global_truth_context = self.get_context(sheerka, global_truth=True)
|
|
|
|
men_instance = sheerka.new("men")
|
|
sheerka.set_plural(context, men_instance, man)
|
|
|
|
# set it again with global_truth = True
|
|
res = sheerka.set_plural(global_truth_context, men_instance, man)
|
|
|
|
assert res.status
|
|
assert men_instance.get_prop(BuiltinConcepts.PLURAL) == man
|
|
|
|
# and it's now true for all newly created context
|
|
assert sheerka.is_plural(sheerka.new("men"), man)
|