From 0a52888526e1a038db7089e1d218fbe0987d4310 Mon Sep 17 00:00:00 2001
From: lukas leufen <l.leufen@fz-juelich.de>
Date: Tue, 30 Jun 2020 18:14:46 +0200
Subject: [PATCH] tests are up to date now

---
 mlair/configuration/path_config.py          | 2 +-
 test/test_configuration/test_path_config.py | 8 +++-----
 test/test_data_handling/test_bootstraps.py  | 6 +++---
 test/test_helpers/test_helpers.py           | 5 +++--
 test/test_modules/test_experiment_setup.py  | 4 ++--
 5 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/mlair/configuration/path_config.py b/mlair/configuration/path_config.py
index 48c4135e..0ef082b5 100644
--- a/mlair/configuration/path_config.py
+++ b/mlair/configuration/path_config.py
@@ -32,7 +32,7 @@ def prepare_host(create_new=True, data_path=None, sampling="daily") -> str:
             data_path = f"/home/{user}/Data/toar_{sampling}/"
         elif hostname == "zam347":
             data_path = f"/home/{user}/Data/toar_{sampling}/"
-        elif hostname == "linux-aa9bc":
+        elif hostname == "linux-aa9b":
             data_path = f"/home/{user}/machinelearningtools/data/toar_{sampling}/"
         elif (len(hostname) > 2) and (hostname[:2] == "jr"):
             data_path = f"/p/project/cjjsc42/{user}/DATA/toar_{sampling}/"
diff --git a/test/test_configuration/test_path_config.py b/test/test_configuration/test_path_config.py
index 320261b8..128ddfce 100644
--- a/test/test_configuration/test_path_config.py
+++ b/test/test_configuration/test_path_config.py
@@ -25,13 +25,11 @@ class TestPrepareHost:
 
     @mock.patch("socket.gethostname", return_value="NotExistingHostName")
     @mock.patch("getpass.getuser", return_value="zombie21")
-    def test_error_handling_unknown_host(self, mock_user, mock_host):
-        with pytest.raises(OSError) as e:
-            prepare_host()
-        assert "unknown host 'NotExistingHostName'" in e.value.args[0]
+    def test_prepare_host_unknown(self, mock_user, mock_host):
+        assert prepare_host() == os.path.join(os.path.abspath(os.getcwd()), 'data', 'daily')
 
     @mock.patch("getpass.getuser", return_value="zombie21")
-    @mock.patch("src.configuration.path_config.check_path_and_create", side_effect=PermissionError)
+    @mock.patch("mlair.configuration.path_config.check_path_and_create", side_effect=PermissionError)
     @mock.patch("os.path.exists", return_value=False)
     def test_error_handling(self, mock_path_exists, mock_cpath, mock_user):
         # if "runner-6HmDp9Qd-project-2411-concurrent" not in platform.node():
diff --git a/test/test_data_handling/test_bootstraps.py b/test/test_data_handling/test_bootstraps.py
index 36d55ccc..c47ec59a 100644
--- a/test/test_data_handling/test_bootstraps.py
+++ b/test/test_data_handling/test_bootstraps.py
@@ -73,7 +73,7 @@ class TestCreateShuffledData:
         return CreateShuffledData(orig_generator, 20, data_path)
 
     @pytest.fixture
-    @mock.patch("src.data_handling.bootstraps.CreateShuffledData.create_shuffled_data", return_value=None)
+    @mock.patch("mlair.data_handling.bootstraps.CreateShuffledData.create_shuffled_data", return_value=None)
     def shuffled_data_no_creation(self, mock_create_shuffle_data, orig_generator, data_path):
         return CreateShuffledData(orig_generator, 20, data_path)
 
@@ -174,7 +174,7 @@ class TestBootStraps:
         return BootStraps(orig_generator, data_path, 20)
 
     @pytest.fixture
-    @mock.patch("src.data_handling.bootstraps.CreateShuffledData", return_value=None)
+    @mock.patch("mlair.data_handling.bootstraps.CreateShuffledData", return_value=None)
     def bootstrap_no_shuffling(self, mock_create_shuffle_data, orig_generator, data_path):
         shutil.rmtree(data_path)
         return BootStraps(orig_generator, data_path, 20)
@@ -211,7 +211,7 @@ class TestBootStraps:
         assert xr.testing.assert_equal(gen.history, expected.sel(variables=var_others)) is None
         assert gen.shuffled.variables == "o3"
 
-    @mock.patch("src.data_handling.data_generator.DataGenerator._load_pickle_data", side_effect=FileNotFoundError)
+    @mock.patch("mlair.data_handling.data_generator.DataGenerator._load_pickle_data", side_effect=FileNotFoundError)
     def test_get_generator_different_generator(self, mock_load_pickle, data_path, orig_generator):
         BootStraps(orig_generator, data_path, 20)  # to create
         orig_generator.window_history_size = 4
diff --git a/test/test_helpers/test_helpers.py b/test/test_helpers/test_helpers.py
index d2067fcc..281d60e0 100644
--- a/test/test_helpers/test_helpers.py
+++ b/test/test_helpers/test_helpers.py
@@ -5,6 +5,7 @@ import datetime as dt
 import logging
 import math
 import time
+import os
 
 import mock
 import pytest
@@ -236,8 +237,8 @@ class TestLogger:
 
     def test_setup_logging_path_none(self):
         log_file = Logger.setup_logging_path(None)
-        assert PyTestRegex(
-            ".*machinelearningtools/logging/logging_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\.log") == log_file
+        test_regex = os.getcwd() + r"/logging/logging_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\.log"
+        assert PyTestRegex(test_regex) == log_file
 
     @mock.patch("os.makedirs", side_effect=None)
     def test_setup_logging_path_given(self, mock_makedirs):
diff --git a/test/test_modules/test_experiment_setup.py b/test/test_modules/test_experiment_setup.py
index b63409b8..60f0d2f9 100644
--- a/test/test_modules/test_experiment_setup.py
+++ b/test/test_modules/test_experiment_setup.py
@@ -14,7 +14,7 @@ class TestExperimentSetup:
     @pytest.fixture
     def empty_obj(self, caplog):
         obj = object.__new__(ExperimentSetup)
-        obj.time = TimeTracking()
+        super(ExperimentSetup, obj).__init__()
         caplog.set_level(logging.DEBUG)
         return obj
 
@@ -43,7 +43,7 @@ class TestExperimentSetup:
         assert data_store.get("fraction_of_training", "general") == 0.8
         # set experiment name
         assert data_store.get("experiment_name", "general") == "TestExperiment_daily"
-        path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "TestExperiment_daily"))
+        path = os.path.abspath(os.path.join(os.getcwd(), "TestExperiment_daily"))
         assert data_store.get("experiment_path", "general") == path
         default_statistics_per_var = {'o3': 'dma8eu', 'relhum': 'average_values', 'temp': 'maximum',
                                       'u': 'average_values', 'v': 'average_values', 'no': 'dma8eu', 'no2': 'dma8eu',
-- 
GitLab