Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging engine issues #20

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"

[project]
name = "xpublish_opendap"
description = ""
description = "OpenDAP plugin for Xpublish"
readme = "README.md"
requires-python = ">=3.9"
keywords = []
keywords = ["xarray", "xpublish", "wms"]
license = { file = "LICENSE.txt" }

classifiers = [
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
black
check-manifest
doctr
h5netcdf
h5pyd
httpx
nbsphinx
netCDF4
pooch
pre-commit
pydap
pylint
pytest
pytest-cov
pytest-flake8
pytest-github-actions-annotate-failures
pytest-xdist
pytest-xprocess
recommonmark
ruff
setuptools_scm
Expand Down
45 changes: 45 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Py.test configuration and shared fixtures."""
from pathlib import Path

import pytest
from xprocess import ProcessStarter

server_path = Path(__file__).parent / "server.py"


@pytest.fixture
def xpublish_server(xprocess):
"""Launch an Xpublish server in the background.

Server has the air_temperature tutorial dataset
at `air` and has the OpenDAP plugin running with
defaults.
"""

class Starter(ProcessStarter):
# Wait till the pattern is printed before
# considering things started
pattern = "Uvicorn running on"

# server startup args
args = ["python", str(server_path)]

# seconds before timing out on server startup
timeout = 30

# Try to cleanup if inturrupted
terminate_on_interrupt = True

xprocess.ensure("xpublish", Starter)
yield "http://0.0.0.0:9000"
xprocess.getinfo("xpublish").terminate()


@pytest.fixture(scope="session")
def dataset():
"""Xarray air temperature tutorial dataset."""
from xarray.tutorial import open_dataset

ds = open_dataset("air_temperature")

return ds
11 changes: 11 additions & 0 deletions tests/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Test OpenDAP server with air temperature dataset."""
import xarray.tutorial
import xpublish

from xpublish_opendap import OpenDapPlugin

ds = xarray.tutorial.open_dataset("air_temperature")

rest = xpublish.Rest({"air": ds}, plugins={"opendap": OpenDapPlugin()})

rest.serve()
25 changes: 25 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Test OpenDAP clients against Xpublish OpenDAP plugin."""
import netCDF4
import pytest
import xarray as xr


def test_netcdf4(xpublish_server):
"""Test opening OpenDAP dataset directly with NetCDF4 library."""
url = f"{xpublish_server}/datasets/air/opendap"
netCDF4.Dataset(url)


def test_default_xarray_engine(xpublish_server, dataset):
"""Test opening OpenDAP dataset with default Xarray engine."""
url = f"{xpublish_server}/datasets/air/opendap"
ds = xr.open_dataset(url)
assert ds == dataset


@pytest.mark.parametrize("engine", ["netcdf4", "h5netcdf", "pydap"])
def test_xarray_engines(xpublish_server, engine, dataset):
"""Test opening OpenDAP dataset with specified engines."""
url = f"{xpublish_server}/datasets/air/opendap"
ds = xr.open_dataset(url, engine=engine)
assert ds == dataset