Skip to content
Snippets Groups Projects
Commit ebcbe52d authored by Fraser William Goldsworth's avatar Fraser William Goldsworth
Browse files

ran black on tests

parent 701a6776
No related branches found
No related tags found
No related merge requests found
......@@ -6,20 +6,23 @@ import pyicon as pyic
@pytest.fixture()
def lazy_raw_grid():
path_data = Path(pyic.params['path_example_data'])
path_data = Path(pyic.params["path_example_data"])
path_data.mkdir(parents=True, exist_ok=True)
grid_path = path_data / "icon_grid_0014_R02B04_O.nc"
if not grid_path.exists():
import requests
grid_download_link = "http://icon-downloads.mpimet.mpg.de/grids/public/mpim/0014/icon_grid_0014_R02B04_O.nc"
try:
r = requests.get(grid_download_link, allow_redirects=True)
with open(grid_path, "wb") as grid_file:
grid_file.write(r.content)
except:
raise FileNotFoundError("{grid_path} does not exist and unable to \
download it")
raise FileNotFoundError(
"{grid_path} does not exist and unable to \
download it"
)
ds_grid = xr.open_dataset(grid_path, chunks="auto")
return ds_grid
......@@ -43,20 +46,23 @@ def eager_processed_tgrid(eager_raw_grid):
@pytest.fixture()
def lazy_examp_icon_dataset():
path_data = Path(pyic.params['path_example_data'])
path_data = Path(pyic.params["path_example_data"])
path_data.mkdir(parents=True, exist_ok=True)
fpath_data = path_data / "icon_example_data_r2b4.nc"
if not fpath_data.exists():
import requests
download_link = "https://swift.dkrz.de/v1/dkrz_83018ad4-3c8d-4c7d-b684-7ba0742caa1a/pyicon_test_data/icon_example_data_r2b4.nc?temp_url_sig=03fb5d20a44832c7cf736ab83c1be3936364dbf6&temp_url_expires=2026-11-24T11:53:16Z"
try:
r = requests.get(download_link, allow_redirects=True, stream=True)
with open(fpath_data, "wb") as fobj:
fobj.write(r.content)
except:
raise FileNotFoundError("{fpath_data} does not exist and unable to \
download it")
raise FileNotFoundError(
"{fpath_data} does not exist and unable to \
download it"
)
ds = xr.open_dataset(fpath_data, chunks="auto")
return ds
......
......@@ -11,8 +11,6 @@ def test_docs_build(tmpdir_factory):
# Run the sphinx-build command
try:
subprocess.check_call(
["sphinx-build", "-b", "html", doc_dir, build_dir])
subprocess.check_call(["sphinx-build", "-b", "html", doc_dir, build_dir])
except subprocess.CalledProcessError as e:
pytest.fail(
f"Documentation build failed with exit code {e.returncode}")
pytest.fail(f"Documentation build failed with exit code {e.returncode}")
......@@ -5,7 +5,9 @@ import matplotlib.pyplot as plt
from .conftest import lazy_examp_icon_dataarray, eager_examp_icon_dataarray
@pytest.mark.parametrize("examp_icon_dataarray", ["lazy_examp_icon_dataarray", "eager_examp_icon_dataarray"])
@pytest.mark.parametrize(
"examp_icon_dataarray", ["lazy_examp_icon_dataarray", "eager_examp_icon_dataarray"]
)
@pytest.mark.parametrize("grid_type,", ["auto", "native"])
def test_plot(examp_icon_dataarray, grid_type, request):
examp_icon_dataarray = request.getfixturevalue(examp_icon_dataarray)
......@@ -13,8 +15,10 @@ def test_plot(examp_icon_dataarray, grid_type, request):
return
@pytest.mark.parametrize("examp_icon_dataarray", ["lazy_examp_icon_dataarray", "eager_examp_icon_dataarray"])
@pytest.mark.parametrize(
"examp_icon_dataarray", ["lazy_examp_icon_dataarray", "eager_examp_icon_dataarray"]
)
def test_plot_sec(examp_icon_dataarray, request):
examp_icon_dataarray = request.getfixturevalue(examp_icon_dataarray)
pyic.plot_sec(examp_icon_dataarray.isel(time=0), section='170W')
pyic.plot_sec(examp_icon_dataarray.isel(time=0), section="170W")
return
import numpy as np
from pyicon.pyicon_thermo import (
_calculate_mpiom_density,
_calculate_insitu_temperature
)
from pyicon.pyicon_thermo import _calculate_mpiom_density, _calculate_insitu_temperature
def test_mpiom_density():
"""the test values come from A3.2 of Gill (1982), Atmospheric & Ocean
......@@ -11,9 +9,12 @@ def test_mpiom_density():
assert np.allclose(_calculate_mpiom_density(0, 5, 0), 999.96675, atol=1e-5)
assert np.allclose(_calculate_mpiom_density(35, 5, 0), 1027.67547, atol=1e-5)
assert np.allclose(_calculate_mpiom_density(35, 25, 1000), 1062.53817, atol=1e-5)
def test_insitu_temperature():
"""the test values come from A3.5 of Gill (1982), Atmospheric & Ocean
Dynamics
"""
assert np.allclose(_calculate_insitu_temperature(25, 8.4678516, 1000), 10, atol=1e-7)
\ No newline at end of file
assert np.allclose(
_calculate_insitu_temperature(25, 8.4678516, 1000), 10, atol=1e-7
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment