import os import shutil from os import path import pytest from core.BuiltinConcepts import BuiltinConcepts from core.Sheerka import Sheerka from helpers import _rv from parsers.ParserInput import ParserInput from sdp.sheerkaDataProvider import SheerkaDataProvider class DummyObj: def __init__(self, a: str = "hello", b: str = "world"): self.a = a self.b = b def __eq__(self, other): if not isinstance(other, DummyObj): return False return self.a == other.a and self.b == other.b def __hash__(self): return hash((self.a, self.b)) def __repr__(self): return f"Dummy('{self.a}', '{self.b}')" class BaseTest: @pytest.fixture() def sdp(self) -> SheerkaDataProvider: return SheerkaDataProvider("mem://", name="test") class BaseParserTest(BaseTest): @staticmethod def get_parser_input(context, command): pi = ParserInput(command) pi.init() return _rv(context.sheerka.newn(BuiltinConcepts.PARSER_INPUT, pi=pi)) class UsingFileBasedSheerka(BaseTest): TESTS_ROOT_DIRECTORY = path.abspath("../build/tests") SHEERKA_ROOT_DIR = os.path.join(TESTS_ROOT_DIRECTORY, ".sheerka") @pytest.fixture(scope="class") def sheerka_fb(self): """ the default fixture to get Sheerka is overriden :return: :rtype: """ # first, make sure to create a fresh environment if path.exists(self.SHEERKA_ROOT_DIR): shutil.rmtree(self.SHEERKA_ROOT_DIR) # create the new Sheerka instance sheerka = Sheerka() sheerka.initialize(root_folder=self.SHEERKA_ROOT_DIR) return sheerka