-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from axiom-data-science/testcov
Adds unit tests for ERDDAP Catalog
- Loading branch information
Showing
2 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,60 @@ | ||
#!/usr/bin/env pytest | ||
"""Unit tests.""" | ||
from unittest import mock | ||
|
||
import intake | ||
import pandas as pd | ||
import pytest | ||
|
||
from intake_erddap.erddap_cat import ERDDAPCatalog | ||
|
||
|
||
def test_nothing(): | ||
"""This test exists to ensure that at least one test works.""" | ||
pass | ||
|
||
|
||
@mock.patch("erddapy.ERDDAP.to_pandas") | ||
def test_erddap_catalog(mock_to_pandas): | ||
results = pd.DataFrame() | ||
results["datasetID"] = ["abc123"] | ||
mock_to_pandas.return_value = results | ||
server = "http://erddap.invalid/erddap" | ||
cat = ERDDAPCatalog(server=server) | ||
assert list(cat) == ["abc123"] | ||
|
||
|
||
@mock.patch("pandas.read_csv") | ||
def test_erddap_catalog_searching(mock_read_csv): | ||
results = pd.DataFrame() | ||
results["datasetID"] = ["abc123"] | ||
mock_read_csv.return_value = results | ||
kw = { | ||
"min_lon": -180, | ||
"max_lon": -156, | ||
"min_lat": 50, | ||
"max_lat": 66, | ||
"min_time": "2021-4-1", | ||
"max_time": "2021-4-2", | ||
} | ||
server = "http://erddap.invalid/erddap" | ||
cat = ERDDAPCatalog(server=server, kwargs_search=kw) | ||
assert list(cat) == ["abc123"] | ||
|
||
|
||
@pytest.mark.integration | ||
def test_ioos_erddap_catalog_and_source(): | ||
kw = { | ||
"min_lon": -180, | ||
"max_lon": -156, | ||
"min_lat": 50, | ||
"max_lat": 66, | ||
"min_time": "2021-4-1", | ||
"max_time": "2021-4-2", | ||
} | ||
server = "http://erddap.sensors.ioos.us/erddap" | ||
cat_sensors = intake.open_erddap_cat(server, kwargs_search=kw) | ||
df = cat_sensors[list(cat_sensors)[0]].read() | ||
assert df is not None | ||
assert isinstance(df, pd.DataFrame) | ||
assert len(df) > 0 |