From dc01c022ad6bfba5084c4fef442fbd76382fab6b Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Fri, 17 May 2024 10:48:23 +0200 Subject: [PATCH 1/4] removed parameter column that is already present --- ddlpy/ddlpy.py | 1 - tests/test_ddlpy.py | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ddlpy/ddlpy.py b/ddlpy/ddlpy.py index e884dcc..ddd5552 100644 --- a/ddlpy/ddlpy.py +++ b/ddlpy/ddlpy.py @@ -272,7 +272,6 @@ def _combine_waarnemingenlijst(result, location): "Naam", "X", "Y", - "Parameter_Wat_Omschrijving", ]: df[name] = location[name] diff --git a/tests/test_ddlpy.py b/tests/test_ddlpy.py index 86061e6..947e965 100755 --- a/tests/test_ddlpy.py +++ b/tests/test_ddlpy.py @@ -40,6 +40,13 @@ def test_locations(locations): assert locations.shape[1] == 18 # the number of rows is the number of stations, so will change over time assert locations.shape[0] > 1 + + # check presence of columns + assert "Coordinatenstelsel" in locations.columns + assert "Naam" in locations.columns + assert "X" in locations.columns + assert "Y" in locations.columns + assert "Parameter_Wat_Omschrijving" in locations.columns def test_locations_extended(): @@ -55,6 +62,14 @@ def test_locations_extended(): def test_measurements(measurements): assert measurements.shape[0] > 1 + + # check presence of columns + assert "Coordinatenstelsel" in measurements.columns + assert "Naam" in measurements.columns + assert "X" in measurements.columns + assert "Y" in measurements.columns + assert "Parameter_Wat_Omschrijving" in measurements.columns + assert "Code" in measurements.columns def test_measurements_freq_yearly(location, measurements): @@ -67,8 +82,8 @@ def test_measurements_freq_yearly(location, measurements): def test_measurements_freq_none(location, measurements): start_date = dt.datetime(1953, 1, 1) end_date = dt.datetime(1953, 4, 1) - measurements_yearly = ddlpy.measurements(location, start_date=start_date, end_date=end_date, freq=None) - assert measurements.shape == measurements_yearly.shape + measurements_monthly = ddlpy.measurements(location, start_date=start_date, end_date=end_date, freq=None) + assert measurements.shape == measurements_monthly.shape def test_measurements_available(location): From 9ba8fac2769d3c7d9e1937ca50ad519f629f2213 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Fri, 17 May 2024 10:55:14 +0200 Subject: [PATCH 2/4] made fixture available for scope=session to speed up tests --- tests/test_ddlpy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_ddlpy.py b/tests/test_ddlpy.py index 947e965..370b459 100755 --- a/tests/test_ddlpy.py +++ b/tests/test_ddlpy.py @@ -10,14 +10,14 @@ import numpy as np -@pytest.fixture +@pytest.fixture(scope="session") def locations(): """return all locations""" locations = ddlpy.locations() return locations -@pytest.fixture +@pytest.fixture(scope="session") def location(locations): """return sample location""" bool_grootheid = locations['Grootheid.Code'] == 'WATHTE' @@ -26,7 +26,7 @@ def location(locations): return location -@pytest.fixture +@pytest.fixture(scope="session") def measurements(location): """measurements for a location """ start_date = dt.datetime(1953, 1, 1) From 50c1013d6cffacc8134d057e693ea6c53d2bca91 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Fri, 17 May 2024 11:00:03 +0200 Subject: [PATCH 3/4] cleaned up test scripts --- tests/test_endpoints.py | 9 +++++---- tests/test_utils.py | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index d46389a..8175d0a 100755 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -4,19 +4,18 @@ """Tests for `ddlpy` package.""" import pytest - import requests - -from ddlpy import ddlpy +import ddlpy -@pytest.fixture +@pytest.fixture(scope="session") def endpoints(): """ Get the endpoints from the api """ return ddlpy.ENDPOINTS + @pytest.fixture def collect_catalogue_resp(endpoints): endpoint = endpoints['collect_catalogue'] @@ -56,6 +55,7 @@ def check_observations_available_resp(endpoints): def test_check_observations_available(check_observations_available_resp): assert check_observations_available_resp.status_code == 200 + @pytest.fixture def collect_number_of_observations_resp(endpoints): endpoint = endpoints['collect_number_of_observations'] @@ -65,6 +65,7 @@ def collect_number_of_observations_resp(endpoints): def test_collect_number_of_observations(collect_number_of_observations_resp): assert collect_number_of_observations_resp.status_code == 200 + @pytest.fixture def request_bulk_observations_resp(endpoints): endpoint = endpoints['request_bulk_observations'] diff --git a/tests/test_utils.py b/tests/test_utils.py index f06796a..d7dbf2b 100755 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,17 +3,17 @@ """Tests for `utils` package.""" -from ddlpy import utils +from ddlpy.utils import date_series import datetime -def test_content(): +def test_date_series(): """Sample pytest test function with the pytest fixture as an argument.""" # from bs4 import BeautifulSoup # assert 'GitHub' in BeautifulSoup(response.content).title.string start = datetime.datetime(2018, 1, 1) end = datetime.datetime(2018, 3, 1) - result = utils.date_series(start, end) + result = date_series(start, end) expected = [ (datetime.datetime(2018, 1, 1, 0, 0), datetime.datetime(2018, 2, 1, 0, 0)), (datetime.datetime(2018, 2, 1, 0, 0), datetime.datetime(2018, 3, 1, 0, 0)) @@ -22,7 +22,7 @@ def test_content(): start = datetime.datetime(2017, 11, 15) end = datetime.datetime(2018, 3, 5) - result = utils.date_series(start, end) + result = date_series(start, end) expected = [ (datetime.datetime(2017, 11, 15, 0, 0), datetime.datetime(2017, 12, 15, 0, 0)), (datetime.datetime(2017, 12, 15, 0, 0), datetime.datetime(2018, 1, 15, 0, 0)), From 9fd06d08631885e498d1894c77390d8cadd916a0 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Fri, 17 May 2024 11:02:33 +0200 Subject: [PATCH 4/4] cleaned up test scripts --- tests/test_endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 8175d0a..84a04de 100755 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -13,7 +13,7 @@ def endpoints(): """ Get the endpoints from the api """ - return ddlpy.ENDPOINTS + return ddlpy.ddlpy.ENDPOINTS @pytest.fixture