Fixed #12
Fixed #13
Fixed #14
This commit is contained in:
2023-05-08 17:50:28 +02:00
parent 21a397861a
commit e41094f908
95 changed files with 12168 additions and 260 deletions
+84
View File
@@ -0,0 +1,84 @@
import pytest
from helpers import GetNextId
@pytest.fixture(scope="session")
def sheerka():
from core.Sheerka import Sheerka
sheerka = Sheerka()
sheerka.initialize("mem://")
return sheerka
@pytest.fixture(scope="module", autouse=True)
def on_new_module(sheerka, request):
"""
For each new module, make sure to create a new ontology
Remove it at the end of the module
:param sheerka:
:type sheerka:
:param request:
:type request:
:return:
:rtype:
"""
from core.Event import Event
from core.ExecutionContext import ExecutionContext, ExecutionContextActions
module_name = request.module.__name__.split(".")[-1]
context = ExecutionContext("test",
Event(message=f"Executing module {module_name}"),
sheerka,
ExecutionContextActions.TESTING,
None)
ontology = sheerka.om.push_ontology(module_name)
yield
sheerka.om.revert_ontology(context, ontology)
@pytest.fixture(scope="function")
def context(sheerka):
from core.Event import Event
from core.ExecutionContext import ExecutionContext, ExecutionContextActions
return ExecutionContext("test",
Event(message=""),
sheerka,
ExecutionContextActions.TESTING,
None)
@pytest.fixture()
def next_id():
return GetNextId()
class TestUsingFileBasedSheerka:
@pytest.fixture(scope="class")
def sheerka(self):
sheerka = Sheerka()
sheerka.initialize()
return sheerka
class NewOntology:
"""
For some test who may need to declare the same concepts across the tests
"""
from core.ExecutionContext import ExecutionContext
def __init__(self, context: ExecutionContext, name="current_test"):
self.sheerka = context.sheerka
self.context = context
self.name = name
self.ontology = None
def __enter__(self):
self.ontology = self.sheerka.om.push_ontology(self.name)
return self.ontology
def __exit__(self, exc_type, exc_val, exc_tb):
self.sheerka.om.revert_ontology(self.context, self.ontology)
return False