Skip to content
Snippets Groups Projects
Commit df9c84f4 authored by lukas leufen's avatar lukas leufen
Browse files

hopefully corrected all failing tests

parent 4b89a24a
No related branches found
No related tags found
4 merge requests!125Release v0.10.0,!124Update Master to new version v0.10.0,!98include track datastore,!91WIP: Resolve "create sphinx docu"
Pipeline #36835 passed
import os
import re
import shutil
......@@ -20,5 +21,25 @@ def pytest_runtest_teardown(item, nextitem):
shutil.rmtree(os.path.join(path, "data"), ignore_errors=True)
if "TestExperiment" in list_dir:
shutil.rmtree(os.path.join(path, "TestExperiment"), ignore_errors=True)
# remove all tracking json
remove_files_from_regex(list_dir, path, re.compile(r"tracking_\d*\.json"))
# remove all tracking pdf
remove_files_from_regex(list_dir, path, re.compile(r"tracking\.pdf"))
# remove all tracking json
remove_files_from_regex(list_dir, path, re.compile(r"logging_\d*\.log"))
else:
pass # nothing to do if next test is from same test class
def remove_files_from_regex(list_dir, path, regex):
r = list(filter(regex.search, list_dir))
if len(r) > 0:
for e in r:
del_path = os.path.join(path, e)
try:
if os.path.isfile(del_path):
os.remove(del_path)
else:
shutil.rmtree(os.path.join(path, e), ignore_errors=True)
except:
pass
......@@ -114,9 +114,12 @@ class RunEnvironment(object):
self.del_by_exit = True
# copy log file and clear data store only if called as base class and not as super class
if self.__class__.__name__ == "RunEnvironment":
TrackPlot(self.tracker_list, True, plot_folder=self.data_store.get_default("experiment_path", "."))
self.__save_tracking()
self.__copy_log_file()
try:
TrackPlot(self.tracker_list, True, plot_folder=self.data_store.get_default("experiment_path", "."))
self.__save_tracking()
self.__copy_log_file()
except FileNotFoundError:
pass
self.data_store.clear_data_store()
def __enter__(self):
......
......@@ -65,7 +65,7 @@ class TestPreProcessing:
caplog.set_level(logging.DEBUG)
obj_with_exp_setup.data_store.set("use_all_stations_on_all_data_sets", False, "general")
obj_with_exp_setup.create_set_split(slice(0, 2), "awesome")
assert caplog.record_tuples[0] == ('root', 10, "Awesome stations (len=2): ['DEBW107', 'DEBY081']")
assert ('root', 10, "Awesome stations (len=2): ['DEBW107', 'DEBY081']") in caplog.record_tuples
data_store = obj_with_exp_setup.data_store
assert isinstance(data_store.get("generator", "general.awesome"), DataGenerator)
with pytest.raises(NameNotFoundInScope):
......@@ -75,8 +75,8 @@ class TestPreProcessing:
def test_create_set_split_all_stations(self, caplog, obj_with_exp_setup):
caplog.set_level(logging.DEBUG)
obj_with_exp_setup.create_set_split(slice(0, 2), "awesome")
assert caplog.record_tuples[0] == ('root', 10, "Awesome stations (len=6): ['DEBW107', 'DEBY081', 'DEBW013', "
"'DEBW076', 'DEBW087', 'DEBW001']")
message = "Awesome stations (len=6): ['DEBW107', 'DEBY081', 'DEBW013', 'DEBW076', 'DEBW087', 'DEBW001']"
assert ('root', 10, message) in caplog.record_tuples
data_store = obj_with_exp_setup.data_store
assert isinstance(data_store.get("generator", "general.awesome"), DataGenerator)
with pytest.raises(NameNotFoundInScope):
......
......@@ -17,7 +17,7 @@ class TestRunEnvironment:
with RunEnvironment() as r:
r.do_stuff(0.1)
expression = PyTestRegex(r"RunEnvironment finished after \d+:\d+:\d+ \(hh:mm:ss\)")
assert caplog.record_tuples[-1] == ('root', 20, expression)
assert ('root', 20, expression) in caplog.record_tuples[-3:]
def test_init(self, caplog):
caplog.set_level(logging.INFO)
......@@ -30,4 +30,4 @@ class TestRunEnvironment:
r.do_stuff(0.2)
del r
expression = PyTestRegex(r"RunEnvironment finished after \d+:\d+:\d+ \(hh:mm:ss\)")
assert caplog.record_tuples[-1] == ('root', 20, expression)
assert ('root', 20, expression) in caplog.record_tuples[-3:]
......@@ -202,8 +202,8 @@ class TestTraining:
model_name = "test_model.h5"
assert model_name not in os.listdir(path)
init_without_run.save_model()
assert caplog.record_tuples[0] == (
"root", 10, PyTestRegex(f"save best model to {os.path.join(path, model_name)}"))
message = PyTestRegex(f"save best model to {os.path.join(path, model_name)}")
assert caplog.record_tuples[1] == ("root", 10, message)
assert model_name in os.listdir(path)
def test_load_best_model_no_weights(self, init_without_run, caplog):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment