Implemented SheerkaOntology

This commit is contained in:
2021-01-11 15:36:03 +01:00
parent e3c2adb533
commit e26c83a825
119 changed files with 6876 additions and 2002 deletions
+28 -34
View File
@@ -1,43 +1,37 @@
import os
import shutil
from os import path
import pytest
from core.concept import ALL_ATTRIBUTES
from conftest import SHEERKA_TEST_FOLDER
from core.sheerka.Sheerka import Sheerka
from core.sheerka.SheerkaOntologyManager import SheerkaOntologyManager
from tests.BaseTest import BaseTest
class TestUsingFileBasedSheerka(BaseTest):
tests_root = path.abspath("../../build/tests")
root_folder = "init_folder"
sheerka = None
context = None
root_ontology_name = SheerkaOntologyManager.ROOT_ONTOLOGY_NAME
@pytest.fixture(autouse=True)
def init_test(self):
if path.exists(self.tests_root):
shutil.rmtree(self.tests_root)
if not path.exists(self.tests_root):
os.makedirs(self.tests_root)
current_pwd = os.getcwd()
os.chdir(self.tests_root)
yield None
os.chdir(current_pwd)
def get_sheerka(self, **kwargs):
reset_attrs = kwargs.get("reset_attrs", True)
if reset_attrs:
ALL_ATTRIBUTES.clear()
use_dict = kwargs.get("use_dict", False)
# use dictionary based io instead of file
# If you do so, information between two different instances of sheerka
# won't be shared
root = "mem://" if use_dict else self.root_folder
sheerka = Sheerka()
sheerka.initialize(root, save_execution_context=False, enable_process_return_values=False)
def teardown_method(self, method):
# to do after the test
if TestUsingFileBasedSheerka.sheerka:
while TestUsingFileBasedSheerka.sheerka.om.current_ontology().name != self.root_ontology_name:
ontology = TestUsingFileBasedSheerka.sheerka.pop_ontology().body.body
ontology.cache_manager.sdp.test_only_destroy_refs()
@staticmethod
def new_sheerka_instance(cache_only):
sheerka = Sheerka(cache_only=cache_only)
sheerka.initialize(SHEERKA_TEST_FOLDER,
save_execution_context=False,
enable_process_return_values=False)
return sheerka
def get_sheerka(self, **kwargs) -> Sheerka:
cache_only = kwargs.get("cache_only", False)
ontology_name = kwargs.get("ontology", "#unit_test#") or "#unit_test#"
if TestUsingFileBasedSheerka.sheerka is None:
TestUsingFileBasedSheerka.sheerka = self.new_sheerka_instance(False)
TestUsingFileBasedSheerka.context = self.get_context(TestUsingFileBasedSheerka.sheerka)
self.sheerka.push_ontology(self.context, ontology_name, cache_only=cache_only)
return TestUsingFileBasedSheerka.sheerka