Skip to content

Commit 627f6b6

Browse files
dopplershiftdcamron
authored andcommitted
ENH: Add tests for AWS access functionality
This requires some infrastructure to use VCRPy to record and mock out web traffic, as well as an optional dependency on boto3.
1 parent f0c1b91 commit 627f6b6

13 files changed

Lines changed: 6985 additions & 4 deletions

.gitattributes

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ staticdata/*.tbl text eol=lf
66
*.ipynb diff=jupyternotebook
77
talks/* linguist-documentation
88
src/metpy/io/_metar_parser/metar_parser.py linguist-generated=true
9-
src/metpy/_vendor/* linguist-vendored
9+
src/metpy/_vendor/* linguist-vendored
10+
11+
# Mark the vcrpy cassettes as generated
12+
tests/remote/fixtures/* linguist-generated=true

.github/workflows/tests-pypi.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ jobs:
6868
# Only needed while we support numpy 1.20
6969
if fname == 'requirements.txt':
7070
out.write('pillow!=10.4.0\n')
71+
# Needed until minium vcrpy is >=7.0.0 for urllib3>=2.3
72+
elif fname == 'requirements.txt':
73+
out.write('urllib3==2.2.3\n')
7174
EOF
7275
7376
- name: Install from PyPI

ci/extra_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
cartopy==0.24.0
22
dask==2025.2.0
33
shapely==2.0.7
4+
boto3==1.35.88

ci/test_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pytest==8.3.5
33
pytest-mpl==0.17.0
44
netCDF4==1.7.2
55
coverage==7.8.0
6+
vcrpy==7.0.0

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ test = [
5858
"netCDF4",
5959
"packaging>=21.0",
6060
"pytest>=7.0",
61-
"pytest-mpl"
61+
"pytest-mpl",
62+
"vcrpy>=4.3.1"
6263
]
6364
extras = [
6465
"cartopy>=0.21.0",
6566
"dask>=2020.12.0",
66-
"shapely>=1.6.4"
67+
"shapely>=1.6.4",
68+
"boto3>=1.26.45"
6769
]
6870

6971
[project.urls]
@@ -77,7 +79,7 @@ extras = [
7779
"MetPy Mondays" = "https://www.youtube.com/playlist?list=PLQut5OXpV-0ir4IdllSt1iEZKTwFBa7kO"
7880

7981
[tool.codespell]
80-
skip = "*.tbl,*.ipynb,AUTHORS.txt,gempak.rst,.git,./staticdata,./docs/build,*.pdf,./talks"
82+
skip = "*.tbl,*.ipynb,AUTHORS.txt,gempak.rst,.git,./staticdata,./docs/build,*.pdf,./talks,./tests/remote/fixtures"
8183
exclude-file = ".codespellexclude"
8284
ignore-words = ".codespellignore"
8385

src/metpy/testing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import contextlib
1111
import functools
1212
from importlib.metadata import PackageNotFoundError, requires, version
13+
import inspect
1314
import operator as op
15+
from pathlib import Path
1416
import re
1517

1618
import matplotlib.pyplot as plt
@@ -132,6 +134,23 @@ def wrapped(*args, **kwargs):
132134
needs_cartopy = needs_module('cartopy')
133135

134136

137+
def needs_aws(test_func):
138+
"""Decorate a test function that needs AWS functionality.
139+
140+
This both sets up recording using VCRPy as well as ensures that the the appropriate
141+
AWS libraries are installed, otherwise the test is skipped.
142+
"""
143+
# Get the vcr module this way so we can skip tests if it's not present
144+
vcr = pytest.importorskip('vcr')
145+
146+
# Set up the fixtures relative to the test file
147+
func_path = inspect.getfile(test_func)
148+
fixture_path = Path(func_path).with_name('fixtures') / f'{test_func.__name__}.yaml'
149+
150+
# Set the cassette to use and also a wrapper function that skips the test if no boto3
151+
return vcr.use_cassette(fixture_path)(needs_module('boto3')(test_func))
152+
153+
135154
@contextlib.contextmanager
136155
def autoclose_figure(*args, **kwargs):
137156
"""Create a figure that is automatically closed when exiting a block.

tests/remote/fixtures/test_goes_range.yaml

Lines changed: 158 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/remote/fixtures/test_goes_single.yaml

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/remote/fixtures/test_nexrad2_range.yaml

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/remote/fixtures/test_nexrad2_single.yaml

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)