fixed unit test folder
This commit is contained in:
@@ -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 {} +
|
||||
|
||||
+24
-5
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user