Implemented SheerkaOntology
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import pytest
|
||||
from cache.CacheManager import ConceptNotFound
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import PROPERTIES_TO_SERIALIZE, Concept, DEFINITION_TYPE_DEF, get_concept_attrs, NotInit, \
|
||||
from core.concept import PROPERTIES_TO_SERIALIZE, Concept, DEFINITION_TYPE_DEF, get_concept_attrs, \
|
||||
DEFINITION_TYPE_BNF
|
||||
from core.global_symbols import NotInit, NotFound
|
||||
from core.sheerka.Sheerka import Sheerka
|
||||
from core.sheerka.services.SheerkaConceptManager import SheerkaConceptManager, NoModificationFound, ForbiddenAttribute, \
|
||||
UnknownAttribute, CannotRemoveMeta, ValueNotFound, ConceptIsReferenced
|
||||
@@ -21,7 +22,7 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
service = sheerka.services[SheerkaConceptManager.NAME]
|
||||
|
||||
res = sheerka.create_new_concept(context, concept)
|
||||
sheerka.cache_manager.commit(context)
|
||||
sheerka.om.commit(context)
|
||||
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.NEW_CONCEPT)
|
||||
@@ -47,15 +48,15 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.get_by_hash(concept.get_definition_hash()) == concept
|
||||
|
||||
# I can get by the first entry
|
||||
assert sheerka.cache_manager.get(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "+") == [concept.id]
|
||||
assert sheerka.cache_manager.get(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "+") == [concept.id]
|
||||
assert sheerka.om.get(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "+") == [concept.id]
|
||||
assert sheerka.om.get(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "+") == [concept.id]
|
||||
|
||||
# saved in sdp
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_ID_ENTRY, concept.id)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_KEY_ENTRY, concept.key)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_NAME_ENTRY, concept.name)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_HASH_ENTRY, concept.get_definition_hash())
|
||||
assert sheerka.sdp.exists(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "+")
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_ID_ENTRY, concept.id)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_KEY_ENTRY, concept.key)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_NAME_ENTRY, concept.name)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_HASH_ENTRY, concept.get_definition_hash())
|
||||
assert sheerka.om.current_sdp().exists(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "+")
|
||||
|
||||
def test_i_cannot_create_a_bnf_concept_that_references_a_concept_that_cannot_be_resolved(self):
|
||||
sheerka, context, one_1, one_1_0 = self.init_concepts(Concept("one", body="1"), Concept("one", body="1.0"))
|
||||
@@ -74,7 +75,7 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
service = sheerka.services[SheerkaConceptManager.NAME]
|
||||
|
||||
res = sheerka.create_new_concept(self.get_context(sheerka), concept)
|
||||
sheerka.cache_manager.commit(context)
|
||||
sheerka.om.commit(context)
|
||||
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.NEW_CONCEPT)
|
||||
@@ -99,11 +100,11 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.get_by_hash(concept.get_definition_hash()) == concept
|
||||
|
||||
# saved in sdp
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_ID_ENTRY, concept.id)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_KEY_ENTRY, concept.key)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_NAME_ENTRY, concept.name)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_HASH_ENTRY, concept.get_definition_hash())
|
||||
assert sheerka.sdp.exists(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "hello")
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_ID_ENTRY, concept.id)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_KEY_ENTRY, concept.key)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_NAME_ENTRY, concept.name)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_HASH_ENTRY, concept.get_definition_hash())
|
||||
assert sheerka.om.current_sdp().exists(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "hello")
|
||||
|
||||
def test_i_cannot_add_the_same_concept_twice(self):
|
||||
"""
|
||||
@@ -184,55 +185,55 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert res.status
|
||||
|
||||
# I can get by the first entry
|
||||
assert sheerka.cache_manager.get(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [concept.id]
|
||||
assert sheerka.cache_manager.get(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [concept.id]
|
||||
assert sheerka.om.get(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [concept.id]
|
||||
assert sheerka.om.get(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [concept.id]
|
||||
|
||||
@pytest.mark.parametrize("expression", [
|
||||
"--'filter' ('one' | 'two') ",
|
||||
"'--filter' ('one' | 'two') ",
|
||||
])
|
||||
def test_i_can_get_first_token_when_bnf_concept_and_not_a_letter(self, expression):
|
||||
sheerka, context, bnf_concept = self.init_concepts(
|
||||
sheerka, context, bnf_concept = self.init_test().with_concepts(
|
||||
Concept("foo", definition=expression),
|
||||
create_new=True)
|
||||
create_new=True).unpack()
|
||||
|
||||
# I can get by the first entry
|
||||
assert sheerka.cache_manager.get(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [bnf_concept.id]
|
||||
assert sheerka.cache_manager.get(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [bnf_concept.id]
|
||||
assert sheerka.om.get(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [bnf_concept.id]
|
||||
assert sheerka.om.get(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "-") == [bnf_concept.id]
|
||||
|
||||
def test_concept_references_are_updated_1(self):
|
||||
sheerka, context, one, two, number, twenty, twenties = self.init_concepts(
|
||||
sheerka, context, one, two, number, twenty, twenties = self.init_test().with_concepts(
|
||||
"one",
|
||||
"two",
|
||||
"number",
|
||||
"twenty",
|
||||
Concept("twenties", definition="twenty one | two 'hundred'"),
|
||||
create_new=True
|
||||
)
|
||||
).unpack()
|
||||
service = sheerka.services[SheerkaConceptManager.NAME]
|
||||
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, one.id) == {twenties.id}
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, two.id) == {twenties.id}
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, number.id) is None
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, twenty.id) == {twenties.id}
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, twenties.id) is None
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, one.id) == {twenties.id}
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, two.id) == {twenties.id}
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, number.id) is NotFound
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, twenty.id) == {twenties.id}
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, twenties.id) is NotFound
|
||||
|
||||
def test_concept_references_are_updated_2(self):
|
||||
sheerka, context, one, two, number, twenty, twenties = self.init_concepts(
|
||||
sheerka, context, one, two, number, twenty, twenties = self.init_test().with_concepts(
|
||||
"one",
|
||||
"two",
|
||||
"number",
|
||||
"twenty",
|
||||
Concept("twenties", definition="twenty number"),
|
||||
create_new=True
|
||||
)
|
||||
).unpack()
|
||||
service = sheerka.services[SheerkaConceptManager.NAME]
|
||||
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, one.id) is None
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, two.id) is None
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, number.id) == {twenties.id}
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, twenty.id) == {twenties.id}
|
||||
assert sheerka.cache_manager.get(service.CONCEPTS_REFERENCES_ENTRY, twenties.id) is None
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, one.id) is NotFound
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, two.id) is NotFound
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, number.id) == {twenties.id}
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, twenty.id) == {twenties.id}
|
||||
assert sheerka.om.get(service.CONCEPTS_REFERENCES_ENTRY, twenties.id) is NotFound
|
||||
|
||||
@pytest.mark.parametrize("attr", [
|
||||
"name",
|
||||
@@ -357,16 +358,18 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.get_by_hash(new_concept.get_definition_hash()).get_metadata().body == "metadata value"
|
||||
|
||||
# sdp is updated
|
||||
sheerka.cache_manager.commit(context)
|
||||
from_sdp = sheerka.sdp.get(service.CONCEPTS_BY_ID_ENTRY, new_concept.id)
|
||||
sheerka.om.commit(context)
|
||||
from_sdp = sheerka.om.current_sdp().get(service.CONCEPTS_BY_ID_ENTRY, new_concept.id)
|
||||
assert from_sdp.get_metadata().body == "metadata value"
|
||||
assert from_sdp.get_metadata().variables == [("var_name", "default value")]
|
||||
assert from_sdp.get_prop(BuiltinConcepts.ISA) == {bar}
|
||||
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_NAME_ENTRY, new_concept.name).get_metadata().body == "metadata value"
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_KEY_ENTRY, new_concept.key).get_metadata().body == "metadata value"
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_HASH_ENTRY,
|
||||
new_concept.get_definition_hash()).get_metadata().body == "metadata value"
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_NAME_ENTRY,
|
||||
new_concept.name).get_metadata().body == "metadata value"
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_KEY_ENTRY,
|
||||
new_concept.key).get_metadata().body == "metadata value"
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_HASH_ENTRY,
|
||||
new_concept.get_definition_hash()).get_metadata().body == "metadata value"
|
||||
|
||||
def test_caches_are_update_when_i_modify_the_name(self):
|
||||
sheerka, context, foo = self.init_concepts("foo", cache_only=False)
|
||||
@@ -391,14 +394,15 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert not sheerka.is_known(sheerka.get_by_key(foo.key))
|
||||
assert not sheerka.is_known(sheerka.get_by_hash(foo.get_definition_hash()))
|
||||
|
||||
sheerka.cache_manager.commit(context)
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_ID_ENTRY, new_concept.id).name == "bar"
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_KEY_ENTRY, new_concept.key).name == "bar"
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_NAME_ENTRY, new_concept.name).name == "bar"
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_HASH_ENTRY, new_concept.get_definition_hash()).name == "bar"
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_KEY_ENTRY, foo.key) is None
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_NAME_ENTRY, foo.name) is None
|
||||
assert sheerka.sdp.get(service.CONCEPTS_BY_HASH_ENTRY, foo.get_definition_hash()) is None
|
||||
sheerka.om.commit(context)
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_ID_ENTRY, new_concept.id).name == "bar"
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_KEY_ENTRY, new_concept.key).name == "bar"
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_NAME_ENTRY, new_concept.name).name == "bar"
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_HASH_ENTRY,
|
||||
new_concept.get_definition_hash()).name == "bar"
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_KEY_ENTRY, foo.key) is NotFound
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_NAME_ENTRY, foo.name) is NotFound
|
||||
assert sheerka.om.current_sdp().get(service.CONCEPTS_BY_HASH_ENTRY, foo.get_definition_hash()) is NotFound
|
||||
|
||||
def test_i_can_modify_a_concept_from_a_list_of_concepts(self):
|
||||
sheerka, context, foo1, foo2 = self.init_concepts(
|
||||
@@ -467,12 +471,12 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert new_concept.key == "__var__0 bar __var__1 __var__2"
|
||||
|
||||
def test_bnf_is_modified_when_modifying_the_definition(self):
|
||||
sheerka, context, one, two, foo = self.init_concepts(
|
||||
sheerka, context, one, two, foo = self.init_test().with_concepts(
|
||||
"one",
|
||||
"two",
|
||||
Concept(name="foo", definition="'twenty' one"),
|
||||
create_new=True
|
||||
)
|
||||
).unpack()
|
||||
|
||||
to_add = {"meta": {"definition": "'twenty' two"}}
|
||||
|
||||
@@ -484,17 +488,17 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert new_concept.get_bnf() == Sequence(StrMatch('twenty'), ConceptExpression(two, rule_name='two'))
|
||||
|
||||
def test_concept_by_first_keyword_is_updated_after_concept_modification(self):
|
||||
sheerka, context, foo, bar, baz = self.init_concepts(
|
||||
sheerka, context, foo, bar, baz = self.init_test().with_concepts(
|
||||
Concept("foo"),
|
||||
Concept("bar"),
|
||||
Concept("baz", definition="foo"),
|
||||
create_new=True)
|
||||
create_new=True).unpack()
|
||||
|
||||
assert sheerka.cache_manager.copy(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
assert sheerka.om.copy(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
"foo": ["1001"],
|
||||
"bar": ["1002"],
|
||||
'c:|1001:': ['1003']}
|
||||
assert sheerka.cache_manager.copy(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
assert sheerka.om.copy(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
'foo': ['1001', '1003'],
|
||||
'bar': ['1002']}
|
||||
|
||||
@@ -502,18 +506,18 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
res = sheerka.modify_concept(context, foo, to_add)
|
||||
|
||||
assert res.status
|
||||
assert sheerka.cache_manager.copy(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
assert sheerka.om.copy(sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
"bar": ["1002", "1001"],
|
||||
'c:|1001:': ['1003']}
|
||||
assert sheerka.cache_manager.copy(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
assert sheerka.om.copy(sheerka.RESOLVED_CONCEPTS_BY_FIRST_KEYWORD_ENTRY) == {
|
||||
'bar': ['1002', '1001', '1003']}
|
||||
|
||||
def test_references_are_updated_after_concept_modification(self):
|
||||
sheerka, context, one, twenty_one = self.init_concepts(
|
||||
sheerka, context, one, twenty_one = self.init_test().with_concepts(
|
||||
"onz",
|
||||
Concept("twenty one", definition="'twenty' onz"),
|
||||
create_new=True
|
||||
)
|
||||
).unpack()
|
||||
|
||||
assert twenty_one.get_bnf() == Sequence(StrMatch('twenty'), ConceptExpression(one, rule_name='onz'))
|
||||
|
||||
@@ -530,6 +534,35 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
BaseNodeParser.ensure_bnf(context, twenty_one)
|
||||
assert twenty_one.get_bnf() == Sequence(StrMatch('twenty'), ConceptExpression(modified, rule_name='one'))
|
||||
|
||||
def test_i_can_modify_on_top_of_a_new_ontology_layer(self):
|
||||
sheerka, context, foo = self.init_concepts(Concept("foo").def_var("a").def_var("b"), cache_only=False)
|
||||
|
||||
sheerka.push_ontology(context, "new ontology")
|
||||
|
||||
to_add = {
|
||||
"meta": {"body": "a body"},
|
||||
"props": {BuiltinConcepts.ISA: "bar"},
|
||||
"variables": {"c": "value"}
|
||||
}
|
||||
to_remove = {
|
||||
"variables": ["b"]
|
||||
}
|
||||
|
||||
res = sheerka.modify_concept(context, foo, to_add=to_add, to_remove=to_remove)
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NEW_CONCEPT)
|
||||
assert res.body.body.get_metadata().body == "a body"
|
||||
assert res.body.body.get_metadata().variables == [("a", None), ("c", "value")]
|
||||
assert res.body.body.get_metadata().props == {BuiltinConcepts.ISA: {"bar"}}
|
||||
|
||||
# and correctly set in cache
|
||||
updated = sheerka.get_by_id(foo.id)
|
||||
assert updated.get_metadata().body == "a body"
|
||||
assert updated.get_metadata().variables == [("a", None), ("c", "value")]
|
||||
assert updated.get_metadata().props == {BuiltinConcepts.ISA: {"bar"}}
|
||||
|
||||
sheerka.pop_ontology()
|
||||
|
||||
def test_i_cannot_modify_without_any_modification(self):
|
||||
sheerka, context, foo = self.init_concepts("foo")
|
||||
service = sheerka.services[SheerkaConceptManager.NAME]
|
||||
@@ -627,10 +660,10 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.get_attr(foo, prop) == bar
|
||||
|
||||
def test_i_cannot_remove_a_concept_which_has_reference(self):
|
||||
sheerka, context, one, twenty_one = self.init_concepts(
|
||||
sheerka, context, one, twenty_one = self.init_test().with_concepts(
|
||||
Concept("one"),
|
||||
Concept("twenty one", definition="'twenty' one"),
|
||||
create_new=True)
|
||||
create_new=True).unpack()
|
||||
|
||||
res = sheerka.remove_concept(context, one)
|
||||
|
||||
@@ -639,9 +672,9 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert res.body.body == ConceptIsReferenced([twenty_one])
|
||||
|
||||
def test_i_can_remove_a_concept(self):
|
||||
sheerka, context, one = self.init_concepts(
|
||||
sheerka, context, one = self.init_test().with_concepts(
|
||||
Concept("one"),
|
||||
create_new=True)
|
||||
create_new=True).unpack()
|
||||
|
||||
# sanity check
|
||||
assert sheerka.get_by_id(one.id) == one
|
||||
@@ -669,6 +702,34 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.ERROR)
|
||||
assert res.body.body == ConceptNotFound(one)
|
||||
|
||||
def test_i_can_create_concepts_in_multiple_ontology_layers(self):
|
||||
sheerka, context = self.init_concepts(cache_only=False)
|
||||
|
||||
res = sheerka.create_new_concept(context, Concept("foo"))
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NEW_CONCEPT)
|
||||
|
||||
sheerka.push_ontology(context, "new ontology")
|
||||
res = sheerka.create_new_concept(context, Concept("bar"))
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NEW_CONCEPT)
|
||||
|
||||
# I cannot defined foo again, even if it's not the same layer
|
||||
res = sheerka.create_new_concept(context, Concept("foo"))
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.CONCEPT_ALREADY_DEFINED)
|
||||
|
||||
# I cannot define bar again in this layer
|
||||
res = sheerka.create_new_concept(context, Concept("bar"))
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.CONCEPT_ALREADY_DEFINED)
|
||||
|
||||
sheerka.pop_ontology()
|
||||
# But I can if I remove the layer
|
||||
res = sheerka.create_new_concept(context, Concept("bar"))
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.NEW_CONCEPT)
|
||||
|
||||
|
||||
class TestSheerkaConceptManagerUsingFileBasedSheerka(TestUsingFileBasedSheerka):
|
||||
def test_i_can_add_several_concepts(self):
|
||||
@@ -678,42 +739,40 @@ class TestSheerkaConceptManagerUsingFileBasedSheerka(TestUsingFileBasedSheerka):
|
||||
|
||||
hello = Concept("Hello world a").def_var("a")
|
||||
res = sheerka.create_new_concept(context, hello)
|
||||
sheerka.cache_manager.commit(context)
|
||||
sheerka.om.commit(context)
|
||||
assert res.status
|
||||
|
||||
sheerka = self.get_sheerka() # another instance
|
||||
context = self.get_context(sheerka)
|
||||
greeting = Concept("Greeting a").def_var("a")
|
||||
res = sheerka.create_new_concept(context, greeting)
|
||||
sheerka.cache_manager.commit(context)
|
||||
sheerka.om.commit(context)
|
||||
assert res.status
|
||||
|
||||
sheerka = self.get_sheerka() # another instance again
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_KEY_ENTRY, hello.key)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_KEY_ENTRY, greeting.key)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_ID_ENTRY, hello.id)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_ID_ENTRY, greeting.id)
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_NAME_ENTRY, "Hello world a")
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_NAME_ENTRY, "Greeting a")
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_HASH_ENTRY, hello.get_definition_hash())
|
||||
assert sheerka.sdp.exists(service.CONCEPTS_BY_HASH_ENTRY, greeting.get_definition_hash())
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_KEY_ENTRY, hello.key)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_KEY_ENTRY, greeting.key)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_ID_ENTRY, hello.id)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_ID_ENTRY, greeting.id)
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_NAME_ENTRY, "Hello world a")
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_NAME_ENTRY, "Greeting a")
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_HASH_ENTRY, hello.get_definition_hash())
|
||||
assert sheerka.om.current_sdp().exists(service.CONCEPTS_BY_HASH_ENTRY, greeting.get_definition_hash())
|
||||
|
||||
assert sheerka.sdp.exists(Sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "Hello")
|
||||
assert sheerka.sdp.exists(Sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "Greeting")
|
||||
assert sheerka.om.current_sdp().exists(Sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "Hello")
|
||||
assert sheerka.om.current_sdp().exists(Sheerka.CONCEPTS_BY_FIRST_KEYWORD_ENTRY, "Greeting")
|
||||
|
||||
def test_i_cannot_add_the_same_concept_twice_using_sdp(self):
|
||||
"""
|
||||
Checks that duplicated concepts are managed by sheerka, not by sheerka.sdp
|
||||
:return:
|
||||
"""
|
||||
sheerka = self.get_sheerka(cache_only=False)
|
||||
context = self.get_context(sheerka)
|
||||
concept = self.get_default_concept()
|
||||
sheerka, context, concept = self.init_concepts("foo")
|
||||
|
||||
sheerka.create_new_concept(context, concept)
|
||||
sheerka.cache_manager.commit(context)
|
||||
sheerka.om.commit(context)
|
||||
|
||||
sheerka.cache_manager.clear()
|
||||
sheerka.om.current_cache_manager().clear(set_is_cleared=False)
|
||||
res = sheerka.create_new_concept(context, concept)
|
||||
|
||||
assert not res.status
|
||||
@@ -727,13 +786,13 @@ class TestSheerkaConceptManagerUsingFileBasedSheerka(TestUsingFileBasedSheerka):
|
||||
|
||||
sheerka.create_new_concept(context, Concept("foo", body="1"))
|
||||
sheerka.create_new_concept(context, Concept("foo", body="2"))
|
||||
sheerka.cache_manager.commit(context)
|
||||
sheerka.om.commit(context)
|
||||
|
||||
assert len(sheerka.sdp.get(service.CONCEPTS_BY_KEY_ENTRY, "foo")) == 2
|
||||
assert len(sheerka.om.current_sdp().get(service.CONCEPTS_BY_KEY_ENTRY, "foo")) == 2
|
||||
|
||||
sheerka = self.get_sheerka() # new instance
|
||||
context = self.get_context(sheerka)
|
||||
sheerka.create_new_concept(context, Concept("foo", body="3"))
|
||||
sheerka.cache_manager.commit(context)
|
||||
sheerka.om.commit(context)
|
||||
|
||||
assert len(sheerka.sdp.get(service.CONCEPTS_BY_KEY_ENTRY, "foo")) == 3
|
||||
assert len(sheerka.om.current_sdp().get(service.CONCEPTS_BY_KEY_ENTRY, "foo")) == 3
|
||||
|
||||
Reference in New Issue
Block a user