From aa1e6a86bb67da4ded6c4c444bd5214399da2ecd Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Tue, 31 Jan 2023 14:16:10 +0100
Subject: [PATCH] Tests and remote import/install appears to work!!!

---
 .vscode/settings.json                             | 15 ++++++---------
 LICENSE                                           | 15 +++++++++++++++
 pyproject.toml                                    |  3 +--
 setup.cfg                                         |  3 ++-
 src/vipscore_common/__init__.py                   |  3 +--
 src/vipscore_common/data_utils.py                 |  2 +-
 src/vipscore_common/reference_model.py            | 14 +++++++-------
 src/vipscore_common/vips_model.py                 |  2 +-
 {src/vipscore_common/tests => tests}/__init__.py  |  0
 .../tests => tests}/test_data_utils.py            |  9 ++++-----
 .../tests => tests}/test_reference_model.py       |  6 +++---
 .../weather_data_2015_NO_aas_TMD.json             |  0
 12 files changed, 41 insertions(+), 31 deletions(-)
 create mode 100644 LICENSE
 rename {src/vipscore_common/tests => tests}/__init__.py (100%)
 rename {src/vipscore_common/tests => tests}/test_data_utils.py (81%)
 rename {src/vipscore_common/tests => tests}/test_reference_model.py (94%)
 rename {src/vipscore_common/tests => tests}/weather_data_2015_NO_aas_TMD.json (100%)

diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0cfcb65..b323bd2 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,13 +1,10 @@
 {
-    "python.testing.unittestArgs": [
+    "python.testing.pytestArgs": [
+        "tests/",
         "-v",
-        "-s",
-        "tests",
-        "-t",
-        "src/vipscore_common",
-        "-p",
-        "test_*.py"
+        "-k",
+        "test_"
     ],
-    "python.testing.pytestEnabled": false,
-    "python.testing.unittestEnabled": true
+    "python.testing.pytestEnabled": true,
+    "python.testing.unittestEnabled": false  
 }
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ad9df02
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,15 @@
+Copyright (c) 2023 NIBIO <http://www.nibio.no/>. 
+
+This file is part of VIPSCore-Python-Common.
+VIPSCore-Python-Common is free software: you can redistribute it and/or modify
+it under the terms of the NIBIO Open Source License as published by 
+NIBIO, either version 1 of the License, or (at your option) any
+later version.
+ 
+VIPSCore-Python-Common is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+NIBIO Open Source License for more details.
+
+You should have received a copy of the NIBIO Open Source License
+along with VIPSCore-Python-Common.  If not, see <http://www.nibio.no/licenses/>.
\ No newline at end of file
diff --git a/pyproject.toml b/pyproject.toml
index 374b58c..6fe23d7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,5 @@
 [build-system]
 requires = [
-    "setuptools>=42",
-    "wheel"
+    "setuptools>=61.0"
 ]
 build-backend = "setuptools.build_meta"
diff --git a/setup.cfg b/setup.cfg
index 91debbd..fdadd5a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [metadata]
-name = vipscore-python-common
+name = vipscore_python_common
 version = 0.5.0
 author = Tor-Einar Skog
 author_email = tor-einar.skog@nibio.no
@@ -21,6 +21,7 @@ install_requires =
     shapely
     pydantic
     pytz
+    pandas
 
 [options.packages.find]
 where = src
\ No newline at end of file
diff --git a/src/vipscore_common/__init__.py b/src/vipscore_common/__init__.py
index 44e6f45..8b13789 100755
--- a/src/vipscore_common/__init__.py
+++ b/src/vipscore_common/__init__.py
@@ -1,2 +1 @@
-from .entities import *
-from .vips_model import *
\ No newline at end of file
+
diff --git a/src/vipscore_common/data_utils.py b/src/vipscore_common/data_utils.py
index 6d1abdd..4bc6acd 100644
--- a/src/vipscore_common/data_utils.py
+++ b/src/vipscore_common/data_utils.py
@@ -26,7 +26,7 @@ import numpy as np
 import pandas as pd
 from pandas import DataFrame
 import json
-from entities import *
+from .entities import *
 
 def get_dataframe_from_weather_observations(weather_observations: list, timezone:datetime.tzinfo) -> DataFrame:
     """
diff --git a/src/vipscore_common/reference_model.py b/src/vipscore_common/reference_model.py
index 7178821..1fd3bf6 100755
--- a/src/vipscore_common/reference_model.py
+++ b/src/vipscore_common/reference_model.py
@@ -18,9 +18,9 @@ You should have received a copy of the NIBIO Open Source License
 along with VIPSCore-Python-Common.  If not, see <http://www.nibio.no/licenses/>.
 """
 
-from vips_model import VIPSModel
-from entities import Result, ModelConfiguration, WeatherObservation
-import data_utils
+from .vips_model import VIPSModel
+from .entities import Result, ModelConfiguration, WeatherObservation
+from .data_utils import *
 import numpy as np
 
 class ReferenceModel(VIPSModel):
@@ -46,8 +46,8 @@ class ReferenceModel(VIPSModel):
         self.sowing_date = model_configuration.get_config_parameter_as_date("sowingDate")
         self.timezone = model_configuration.get_config_parameter_as_timezone("timeZone")
         # Weather data is turned into Pandas dataframe
-        self.df = data_utils.get_dataframe_from_weather_observations(
-                data_utils.get_weather_observations_from_json_list(
+        self.df = get_dataframe_from_weather_observations(
+                get_weather_observations_from_json_list(
                     model_configuration.config_parameters["observations"]
                     ),
                 self.timezone
@@ -74,7 +74,7 @@ class ReferenceModel(VIPSModel):
         
         # Calculate day degrees from sowingDate and as far as weather data goes
         # Adjusting for base temperature
-        self.df["TMContrib"] = self.df["TM"].apply(data_utils.get_temp_adjusted_for_base, args=(5,))
+        self.df["TMContrib"] = self.df["TM"].apply(get_temp_adjusted_for_base, args=(5,))
         # Aggregating the day degrees
         self.df["TMDD"] = self.df["TMContrib"].cumsum()
         # Adding the thresholds to the data frame
@@ -84,7 +84,7 @@ class ReferenceModel(VIPSModel):
         # For each day: check accumulated day-degrees and decide warning status
         self.df["WARNING_STATUS"] = self.df["TMDD"].apply(self.determine_warning_status)
         #print(self.df)
-        result = data_utils.get_result_list_from_dataframe(self.df)
+        result = get_result_list_from_dataframe(self.df)
         #print(result)
         return result
         
diff --git a/src/vipscore_common/vips_model.py b/src/vipscore_common/vips_model.py
index 175b032..38e02f9 100755
--- a/src/vipscore_common/vips_model.py
+++ b/src/vipscore_common/vips_model.py
@@ -22,7 +22,7 @@ along with VIPSCore-Python-Common.  If not, see <http://www.nibio.no/licenses/>.
 # @author Tor-Einar Skog <tor-einar.skog@nibio.no>
 
 from abc import ABC, abstractmethod, abstractproperty
-from entities import Result, ModelConfiguration
+from .entities import Result, ModelConfiguration
 
 class VIPSModel(ABC):
 
diff --git a/src/vipscore_common/tests/__init__.py b/tests/__init__.py
similarity index 100%
rename from src/vipscore_common/tests/__init__.py
rename to tests/__init__.py
diff --git a/src/vipscore_common/tests/test_data_utils.py b/tests/test_data_utils.py
similarity index 81%
rename from src/vipscore_common/tests/test_data_utils.py
rename to tests/test_data_utils.py
index 09dab01..5b0b255 100644
--- a/src/vipscore_common/tests/test_data_utils.py
+++ b/tests/test_data_utils.py
@@ -1,9 +1,8 @@
 import unittest
 
 
-import data_utils
-from reference_model import *
-from entities import *
+from src.vipscore_common import data_utils
+from src.vipscore_common.entities import *
 import pytz
 
 class TestDataUtils(unittest.TestCase):
@@ -11,7 +10,7 @@ class TestDataUtils(unittest.TestCase):
         """
         The method can convert a json dict to a list of WeatherObservation objects
         """
-        with open ("src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json") as f:
+        with open ("tests/weather_data_2015_NO_aas_TMD.json") as f:
             result = data_utils.get_weather_observations_from_json(f.read())
             # Length should be > 0
             self.assertGreater(len(result), 0)
@@ -23,7 +22,7 @@ class TestDataUtils(unittest.TestCase):
         """
         Lorem Ipsum osv
         """
-        with open ("src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json") as f:
+        with open ("tests/weather_data_2015_NO_aas_TMD.json") as f:
             weather_observations = data_utils.get_weather_observations_from_json(f.read())
             result = data_utils.get_dataframe_from_weather_observations(weather_observations, pytz.timezone("Europe/Oslo"))
             self.assertIsNotNone(result)
diff --git a/src/vipscore_common/tests/test_reference_model.py b/tests/test_reference_model.py
similarity index 94%
rename from src/vipscore_common/tests/test_reference_model.py
rename to tests/test_reference_model.py
index 743855e..5d6ba90 100644
--- a/src/vipscore_common/tests/test_reference_model.py
+++ b/tests/test_reference_model.py
@@ -2,11 +2,11 @@ import unittest
 
 import json
 
-from reference_model import *
-from entities import *
+from src.vipscore_common.reference_model import *
+from src.vipscore_common.entities import *
 
 def get_model_configuration():
-    with open ("src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json") as f:
+    with open ("tests/weather_data_2015_NO_aas_TMD.json") as f:
         weather_observations = json.load(f)
         return ModelConfiguration(
             model_id=ReferenceModel.MODEL_ID,
diff --git a/src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json b/tests/weather_data_2015_NO_aas_TMD.json
similarity index 100%
rename from src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json
rename to tests/weather_data_2015_NO_aas_TMD.json
-- 
GitLab