fixed unit test folder

This commit is contained in:
Kodjo Sossouvi
2019-08-28 18:25:15 +02:00
parent 25d9092c52
commit 3f423454c8
3 changed files with 44 additions and 6 deletions
+3 -1
View File
@@ -1,8 +1,10 @@
.PHONY: test .PHONY: test
test: test: clean
py.test tests py.test tests
clean: clean:
rm -rf build
find . -name '.pytest_cache' -exec rm -rf {} + find . -name '.pytest_cache' -exec rm -rf {} +
find . -name '__pycache__' -exec rm -rf {} +
+24 -5
View File
@@ -38,26 +38,38 @@ class Sheerka(Concept, metaclass=Singleton):
def __init__(self): def __init__(self):
super().__init__(Sheerka.NAME) super().__init__(Sheerka.NAME)
# ist of all concepts known be the system # list of all concepts known be the system
self.concepts = [] 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 # 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 # List of the known rules by the system
# ex: hello => say('hello') # ex: hello => say('hello')
self.rules = [] 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(self)
self.concepts.append(Concept(Sheerka.UNKNOWN_CONCEPT_NAME)) self.concepts.append(Concept(Sheerka.UNKNOWN_CONCEPT_NAME))
self.concepts.append(Concept(Sheerka.SUCCESS_CONCEPT_NAME)) self.concepts.append(Concept(Sheerka.SUCCESS_CONCEPT_NAME))
self.concepts.append(Concept(Sheerka.ERROR_CONCEPT_NAME)) self.concepts.append(Concept(Sheerka.ERROR_CONCEPT_NAME))
def initialize(self, root_folder): 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 # create the folder configuration folder if needed
try: try:
if not os.path.exists(root_folder): 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)) return ReturnValue(True, self.get_concept(Sheerka.SUCCESS_CONCEPT_NAME, True))
def get_concept(self, name, is_builtin=False): 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: for concept in self.concepts:
if concept.name == name and concept.is_builtin == is_builtin: if concept.name == name and concept.is_builtin == is_builtin:
return concept return concept
@@ -75,6 +93,7 @@ class Sheerka(Concept, metaclass=Singleton):
@staticmethod @staticmethod
def concept_equals(concept1, concept2): def concept_equals(concept1, concept2):
"""True if the two concepts refer to the same concept"""
if concept1 is None and concept2 is None: if concept1 is None and concept2 is None:
return True return True
+17
View File
@@ -1,10 +1,27 @@
import pytest
import os import os
from core.concept import Concept from core.concept import Concept
from core.sheerka import Sheerka 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(): def test_root_folder_is_created_after_initialization():
print("Before yield")
root_folder = "init_folder" root_folder = "init_folder"
return_value = Sheerka().initialize(root_folder) return_value = Sheerka().initialize(root_folder)