Skip to content

Commit f72b73e

Browse files
committed
Fixes in test_application tests
1 parent d8a503e commit f72b73e

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

tests/default_test_configuration.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ cascade = 1,1
5151
# evaluation_method = standalone_function
5252
# evaluation_method = standalone_files
5353
evaluation_method = mfile_standalone
54-
evaluation_function = toy_problem_python_ev
55-
# evaluation_function = toy_problem_python_ev
54+
evaluation_function = toy_problem
5655
indfile = ind.dat
5756
Jfile = J.dat
5857
# exchangedir = fullfile(pwd,evaluator0)

tests/mlc/test_application.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
import os
33
import unittest
44

5-
from MLC.Population.Creation import BaseCreation
6-
from tests.test_helpers import TestHelper
7-
from MLC.config import get_working_directory
8-
from MLC.config import get_test_path
9-
from MLC.mlc_parameters.mlc_parameters import saved, Config
105
from MLC.api.MLCLocal import MLCLocal
11-
12-
from MLC.Simulation import Simulation
136
from MLC.Application import Application, MLC_CALLBACKS
14-
7+
from MLC.config import set_working_directory
8+
from MLC.config import get_working_directory
9+
from MLC.config import get_test_path
1510
from MLC.db.mlc_repository import MLCRepository
11+
from MLC.mlc_parameters.mlc_parameters import saved
12+
from MLC.mlc_parameters.mlc_parameters import Config
13+
from MLC.Population.Creation import BaseCreation
14+
from MLC.Simulation import Simulation
15+
from tests.test_helpers import TestHelper
1616

1717

1818
class ApplicationTest(unittest.TestCase):
@@ -22,20 +22,24 @@ class ApplicationTest(unittest.TestCase):
2222
on_new_generation = []
2323
on_finish = 0
2424
experiment_name = "test_application"
25-
workspace_dir = os.path.join(get_working_directory(), "workspace")
25+
workspace_dir = os.path.abspath("/tmp/mlc_workspace/")
2626
test_conf_path = os.path.join(get_test_path(), TestHelper.DEFAULT_CONF_FILENAME)
2727
experiment_dir = os.path.join(workspace_dir, experiment_name)
2828
mlc_local = None
2929

3030
@classmethod
3131
def setUpClass(cls):
3232
TestHelper.load_default_configuration()
33-
# Create the MLC workspace dir of this tests
34-
os.makedirs(ApplicationTest.workspace_dir)
33+
try:
34+
os.makedirs(ApplicationTest.workspace_dir)
35+
except OSError:
36+
shutil.rmtree(ApplicationTest.workspace_dir)
37+
os.makedirs(ApplicationTest.workspace_dir)
3538

3639
# Create the MLCLocal and the workspace of MLC, and create
3740
# a new experiment to be used to test the callbacks
38-
ApplicationTest.mlc_local = MLCLocal(ApplicationTest.workspace_dir)
41+
set_working_directory(ApplicationTest.workspace_dir)
42+
ApplicationTest.mlc_local = MLCLocal(working_dir=ApplicationTest.workspace_dir)
3943

4044
@classmethod
4145
def tearDownClass(cls):
@@ -117,6 +121,7 @@ def test_set_custom_gen_creator(self):
117121
from MLC.individual.Individual import Individual
118122

119123
class TestCreator(BaseCreation):
124+
120125
def __init__(self):
121126
BaseCreation.__init__(self)
122127

@@ -137,4 +142,3 @@ def individuals(self):
137142
# Assert first Population was filled using the TestCreator
138143
population = MLCRepository.get_instance().get_population(1)
139144
self.assertEqual(population.get_individuals(), [1, 2, 3, 4, 5])
140-

0 commit comments

Comments
 (0)