Skip to content

Commit

Permalink
prevent copy of already present Parameter_Wat_Omschrijving column (#104)
Browse files Browse the repository at this point in the history
* prevent copy of already present Parameter_Wat_Omschrijving column

* made fixture available for scope=session to speed up tests

* cleaned up test scripts
  • Loading branch information
veenstrajelmer authored May 17, 2024
1 parent 9bc5d88 commit 328b7e5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
1 change: 0 additions & 1 deletion ddlpy/ddlpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ def _combine_waarnemingenlijst(result, location):
"Naam",
"X",
"Y",
"Parameter_Wat_Omschrijving",
]:
df[name] = location[name]

Expand Down
25 changes: 20 additions & 5 deletions tests/test_ddlpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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():
Expand All @@ -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):
Expand All @@ -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):
Expand Down
11 changes: 6 additions & 5 deletions tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
"""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
return ddlpy.ddlpy.ENDPOINTS


@pytest.fixture
def collect_catalogue_resp(endpoints):
Expand Down Expand Up @@ -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']
Expand All @@ -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']
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)),
Expand Down

0 comments on commit 328b7e5

Please sign in to comment.