From 3f423454c88d8e38472458ca3e2728d691513048 Mon Sep 17 00:00:00 2001 From: Kodjo Sossouvi Date: Wed, 28 Aug 2019 18:25:15 +0200 Subject: [PATCH] fixed unit test folder --- Makefile | 4 +++- core/sheerka.py | 29 ++++++++++++++++++++++++----- tests/test_sheerka.py | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f27a118..4f4180b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ .PHONY: test -test: +test: clean py.test tests clean: + rm -rf build find . -name '.pytest_cache' -exec rm -rf {} + + find . -name '__pycache__' -exec rm -rf {} + diff --git a/core/sheerka.py b/core/sheerka.py index cee0110..2862f67 100644 --- a/core/sheerka.py +++ b/core/sheerka.py @@ -38,26 +38,38 @@ class Sheerka(Concept, metaclass=Singleton): def __init__(self): super().__init__(Sheerka.NAME) - # ist of all concepts known be the system + # list of all concepts known be the system self.concepts = [] - # At a given point of time, (TODO: in a specific contexts), somme concepts are instantiated + # a concept can be instantiated # ex: File is a concept, but File('foo.txt') is an instance - self.instances = [] # list of actual instances + # TODO: manage contexts + self.instances = [] # List of the known rules by the system # ex: hello => say('hello') self.rules = [] - self.create_builtin_concept() + self.create_builtin_concepts() - def create_builtin_concept(self): + def create_builtin_concepts(self): + """ + Initializes the builtin concepts + :return: None + """ self.concepts.append(self) self.concepts.append(Concept(Sheerka.UNKNOWN_CONCEPT_NAME)) self.concepts.append(Concept(Sheerka.SUCCESS_CONCEPT_NAME)) self.concepts.append(Concept(Sheerka.ERROR_CONCEPT_NAME)) def initialize(self, root_folder): + """ + Starting Sheerka + Loads the current configuration + Notes that when it's the first time, it also create the needed working folders + :param root_folder: root configuration folder + :return: ReturnValue(Success or Error) + """ # create the folder configuration folder if needed try: if not os.path.exists(root_folder): @@ -68,6 +80,12 @@ class Sheerka(Concept, metaclass=Singleton): return ReturnValue(True, self.get_concept(Sheerka.SUCCESS_CONCEPT_NAME, True)) def get_concept(self, name, is_builtin=False): + """ + Given a concept name, tries to find it + :param name: name of the concept to look for + :param is_builtin: is it a builtin concept ? + :return: concept if found, UNKNOWN_CONCEPT otherwise + """ for concept in self.concepts: if concept.name == name and concept.is_builtin == is_builtin: return concept @@ -75,6 +93,7 @@ class Sheerka(Concept, metaclass=Singleton): @staticmethod def concept_equals(concept1, concept2): + """True if the two concepts refer to the same concept""" if concept1 is None and concept2 is None: return True diff --git a/tests/test_sheerka.py b/tests/test_sheerka.py index 07825be..d0701c1 100644 --- a/tests/test_sheerka.py +++ b/tests/test_sheerka.py @@ -1,10 +1,27 @@ +import pytest import os from core.concept import Concept from core.sheerka import Sheerka +@pytest.fixture(autouse=True) +def init_test(): + print("Before yield") + print("Current folder " + os.getcwd()) + if not os.path.exists("build/tests"): + os.makedirs("build/tests") + current_pwd = os.getcwd() + os.chdir("build/tests") + yield None + + os.chdir(current_pwd) + print("After yield") + print("Current folder " + os.getcwd()) + + def test_root_folder_is_created_after_initialization(): + print("Before yield") root_folder = "init_folder" return_value = Sheerka().initialize(root_folder)