Skip to content

Commit 864de4d

Browse files
committed
Mark test that require access to the internet
I some cases it is necessary to run teh test suite in an environment without access to teh internet (e.g. when one is building Debian packages). This PR add the "network" mark to all tests requiring access to the internet. In this way, it is easy to skip them using the following command: $ python3 -m pytest -m "not network" tests
1 parent 933ab93 commit 864de4d

18 files changed

+246
-1
lines changed

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ combine_as_imports = true
103103
combine_star = true
104104

105105
[tool.pytest.ini_options]
106-
markers = "xfail_dask: marks tests as expected to fail with Dask arrays"
106+
markers = [
107+
"xfail_dask: marks tests as expected to fail with Dask arrays",
108+
"network: make tests requiring access to the internet",
109+
]
107110
norecursedirs = "build docs .idea"
108111
doctest_optionflags = "NORMALIZE_WHITESPACE"
109112
mpl-results-path = "test_output"

tests/calc/test_basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ def test_altimeter_to_sea_level_pressure_hpa(array_type):
814814
assert_array_almost_equal(res, truth, 3)
815815

816816

817+
@pytest.mark.network
817818
def test_zoom_xarray():
818819
"""Test zoom_xarray on 2D DataArray."""
819820
data = xr.open_dataset(get_test_data('GFS_test.nc', False))

tests/calc/test_calc_tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,7 @@ def test_remove_nans():
13061306
assert_almost_equal(y_expected, y_test, 0)
13071307

13081308

1309+
@pytest.mark.network
13091310
@pytest.mark.parametrize('subset', (False, True))
13101311
@pytest.mark.parametrize('datafile, assign_lat_lon, no_crs, transpose',
13111312
[('GFS_test.nc', False, False, False),
@@ -1583,6 +1584,7 @@ def test_peak_persistence_minima(peak_data):
15831584
assert per == [((2, 3), np.inf), ((3, 0), 2)]
15841585

15851586

1587+
@pytest.mark.network
15861588
def test_find_peaks(peak_data):
15871589
"""Test find_peaks correctly identifies peaks."""
15881590
data = xr.open_dataset(get_test_data('GFS_test.nc', as_file_obj=False))
@@ -1596,6 +1598,7 @@ def test_find_peaks(peak_data):
15961598
assert_array_almost_equal(hgt.metpy.x[xind], [3.665191, 5.235988], 6)
15971599

15981600

1601+
@pytest.mark.network
15991602
def test_find_peaks_minima(peak_data):
16001603
"""Test find_peaks correctly identifies peaks."""
16011604
data = xr.open_dataset(get_test_data('GFS_test.nc', as_file_obj=False))

tests/calc/test_cross_sections.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ def test_absolute_momentum_given_xy(test_cross_xy):
323323
assert_xarray_allclose(momentum, true_momentum)
324324

325325

326+
@pytest.mark.network
326327
def test_absolute_momentum_xarray_units_attr():
327328
"""Test absolute momentum when `u` and `v` are DataArrays with a `units` attribute."""
328329
data = xr.open_dataset(get_test_data('narr_example.nc', False))

tests/calc/test_indices.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from metpy.units import concatenate, units
1717

1818

19+
@pytest.mark.network
1920
def test_precipitable_water():
2021
"""Test precipitable water with observed sounding."""
2122
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -24,6 +25,7 @@ def test_precipitable_water():
2425
assert_array_almost_equal(pw, truth, 4)
2526

2627

28+
@pytest.mark.network
2729
def test_precipitable_water_no_bounds():
2830
"""Test precipitable water with observed sounding and no bounds given."""
2931
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -83,6 +85,7 @@ def test_precipitable_water_descriptive_bound_error():
8385
precipitable_water(pressure, dewpoint, bottom=units.Quantity(999, 'hPa'))
8486

8587

88+
@pytest.mark.network
8689
def test_mean_pressure_weighted():
8790
"""Test pressure-weighted mean wind function with vertical interpolation."""
8891
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -95,6 +98,7 @@ def test_mean_pressure_weighted():
9598
assert_almost_equal(v, 7.966031839967931 * units('m/s'), 7)
9699

97100

101+
@pytest.mark.network
98102
def test_mean_pressure_weighted_temperature():
99103
"""Test pressure-weighted mean temperature function with vertical interpolation."""
100104
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -105,6 +109,7 @@ def test_mean_pressure_weighted_temperature():
105109
assert_almost_equal(t, 281.535035296836 * units('kelvin'), 7)
106110

107111

112+
@pytest.mark.network
108113
def test_mean_pressure_weighted_elevated():
109114
"""Test pressure-weighted mean wind function with a base above the surface."""
110115
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -118,6 +123,7 @@ def test_mean_pressure_weighted_elevated():
118123
assert_almost_equal(v, 1.7392601775853547 * units('m/s'), 7)
119124

120125

126+
@pytest.mark.network
121127
def test_weighted_continuous_average():
122128
"""Test pressure-weighted mean wind function with vertical interpolation."""
123129
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -130,6 +136,7 @@ def test_weighted_continuous_average():
130136
assert_almost_equal(v, 6.900543760612305 * units('m/s'), 7)
131137

132138

139+
@pytest.mark.network
133140
def test_weighted_continuous_average_temperature():
134141
"""Test pressure-weighted mean temperature function with vertical interpolation."""
135142
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -140,6 +147,7 @@ def test_weighted_continuous_average_temperature():
140147
assert_almost_equal(t, 279.07450928270185 * units('kelvin'), 7)
141148

142149

150+
@pytest.mark.network
143151
def test_weighted_continuous_average_elevated():
144152
"""Test pressure-weighted mean wind function with a base above the surface."""
145153
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -153,6 +161,7 @@ def test_weighted_continuous_average_elevated():
153161
assert_almost_equal(v, 1.616638856115755 * units('m/s'), 7)
154162

155163

164+
@pytest.mark.network
156165
def test_precipitable_water_xarray():
157166
"""Test precipitable water with xarray input."""
158167
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -163,6 +172,7 @@ def test_precipitable_water_xarray():
163172
assert_almost_equal(pw, truth)
164173

165174

175+
@pytest.mark.network
166176
def test_bunkers_motion():
167177
"""Test Bunkers storm motion with observed sounding."""
168178
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -174,6 +184,7 @@ def test_bunkers_motion():
174184
assert_almost_equal(motion.flatten(), truth, 8)
175185

176186

187+
@pytest.mark.network
177188
def test_corfidi_motion():
178189
"""Test corfidi MCS motion with observed sounding."""
179190
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -184,6 +195,7 @@ def test_corfidi_motion():
184195
assert_almost_equal(motion_full.flatten(), truth_full, 8)
185196

186197

198+
@pytest.mark.network
187199
def test_corfidi_motion_override_llj():
188200
"""Test corfidi MCS motion with overridden LLJ."""
189201
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -204,13 +216,15 @@ def test_corfidi_motion_override_llj():
204216
data['v_wind'], v_llj=10 * units('kt'))
205217

206218

219+
@pytest.mark.network
207220
def test_corfidi_corfidi_llj_unaivalable():
208221
"""Test corfidi MCS motion where the LLJ is unailable."""
209222
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
210223
with pytest.raises(ValueError):
211224
corfidi_storm_motion(data['pressure'][6:], data['u_wind'][6:], data['v_wind'][6:])
212225

213226

227+
@pytest.mark.network
214228
def test_corfidi_corfidi_cloudlayer_trimmed():
215229
"""Test corfidi MCS motion where sounding does not include the entire cloud layer."""
216230
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -221,6 +235,7 @@ def test_corfidi_corfidi_cloudlayer_trimmed():
221235
assert_almost_equal(motion_no_top.flatten(), truth_no_top, 8)
222236

223237

238+
@pytest.mark.network
224239
def test_corfidi_motion_with_nans():
225240
"""Test corfidi MCS motion with observed sounding with nans."""
226241
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -235,6 +250,7 @@ def test_corfidi_motion_with_nans():
235250
assert_almost_equal(motion_with_nans.flatten(), truth_with_nans, 8)
236251

237252

253+
@pytest.mark.network
238254
def test_bunkers_motion_with_nans():
239255
"""Test Bunkers storm motion with observed sounding."""
240256
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -250,6 +266,7 @@ def test_bunkers_motion_with_nans():
250266
assert_almost_equal(motion.flatten(), truth, 8)
251267

252268

269+
@pytest.mark.network
253270
def test_bulk_shear():
254271
"""Test bulk shear with observed sounding."""
255272
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -261,6 +278,7 @@ def test_bulk_shear():
261278
assert_almost_equal(v.to('knots'), truth[1], 8)
262279

263280

281+
@pytest.mark.network
264282
def test_bulk_shear_no_depth():
265283
"""Test bulk shear with observed sounding and no depth given. Issue #568."""
266284
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -271,6 +289,7 @@ def test_bulk_shear_no_depth():
271289
assert_almost_equal(v.to('knots'), truth[1], 8)
272290

273291

292+
@pytest.mark.network
274293
def test_bulk_shear_elevated():
275294
"""Test bulk shear with observed sounding and a base above the surface."""
276295
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -325,6 +344,7 @@ def test_sigtor_scalar():
325344
assert_almost_equal(sigtor, truth, 6)
326345

327346

347+
@pytest.mark.network
328348
def test_critical_angle():
329349
"""Test critical angle with observed sounding."""
330350
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')
@@ -335,6 +355,7 @@ def test_critical_angle():
335355
assert_almost_equal(ca, truth, 8)
336356

337357

358+
@pytest.mark.network
338359
def test_critical_angle_units():
339360
"""Test critical angle with observed sounding and different storm motion units."""
340361
data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC')

tests/calc/test_kinematics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def test_advection_z_y():
426426
assert_array_equal(a, truth)
427427

428428

429+
@pytest.mark.network
429430
def test_advection_4d_vertical(data_4d):
430431
"""Test 4-d vertical advection with parsed dims."""
431432
data_4d['w'] = -abs(data_4d['u'])
@@ -1029,6 +1030,7 @@ def test_potential_vorticity_baroclinic_isobaric_real_data():
10291030
assert_almost_equal(pvor, true_pv, 10)
10301031

10311032

1033+
@pytest.mark.network
10321034
def test_potential_vorticity_baroclinic_4d(data_4d):
10331035
"""Test potential vorticity calculation with latlon+xarray spatial handling."""
10341036
theta = potential_temperature(data_4d.pressure, data_4d.temperature)
@@ -1421,12 +1423,14 @@ def data_4d():
14211423
2.84689950e-05]]]]) * units('s^-1')
14221424

14231425

1426+
@pytest.mark.network
14241427
def test_vorticity_4d(data_4d):
14251428
"""Test vorticity on a 4D (time, pressure, y, x) grid."""
14261429
vort = vorticity(data_4d.u, data_4d.v)
14271430
assert_array_almost_equal(vort.data, true_vort4d, 12)
14281431

14291432

1433+
@pytest.mark.network
14301434
def test_absolute_vorticity_4d(data_4d):
14311435
"""Test absolute_vorticity on a 4D (time, pressure, y, x) grid."""
14321436
vort = absolute_vorticity(data_4d.u, data_4d.v)
@@ -1435,6 +1439,7 @@ def test_absolute_vorticity_4d(data_4d):
14351439
assert_array_almost_equal(vort.data, truth, 12)
14361440

14371441

1442+
@pytest.mark.network
14381443
def test_divergence_4d(data_4d):
14391444
"""Test divergence on a 4D (time, pressure, y, x) grid."""
14401445
div = divergence(data_4d.u, data_4d.v)
@@ -1478,6 +1483,7 @@ def test_divergence_4d(data_4d):
14781483
assert_array_almost_equal(div.data, truth, 12)
14791484

14801485

1486+
@pytest.mark.network
14811487
def test_shearing_deformation_4d(data_4d):
14821488
"""Test shearing_deformation on a 4D (time, pressure, y, x) grid."""
14831489
shdef = shearing_deformation(data_4d.u, data_4d.v)
@@ -1521,6 +1527,7 @@ def test_shearing_deformation_4d(data_4d):
15211527
assert_array_almost_equal(shdef.data, truth, 12)
15221528

15231529

1530+
@pytest.mark.network
15241531
def test_stretching_deformation_4d(data_4d):
15251532
"""Test stretching_deformation on a 4D (time, pressure, y, x) grid."""
15261533
stdef = stretching_deformation(data_4d.u, data_4d.v)
@@ -1564,6 +1571,7 @@ def test_stretching_deformation_4d(data_4d):
15641571
assert_array_almost_equal(stdef.data, truth, 10)
15651572

15661573

1574+
@pytest.mark.network
15671575
def test_total_deformation_4d(data_4d):
15681576
"""Test total_deformation on a 4D (time, pressure, y, x) grid."""
15691577
totdef = total_deformation(data_4d.u, data_4d.v)
@@ -1607,6 +1615,7 @@ def test_total_deformation_4d(data_4d):
16071615
assert_array_almost_equal(totdef.data, truth, 12)
16081616

16091617

1618+
@pytest.mark.network
16101619
def test_frontogenesis_4d(data_4d):
16111620
"""Test frontogenesis on a 4D (time, pressure, y, x) grid."""
16121621
theta = potential_temperature(data_4d.pressure, data_4d.temperature)
@@ -1657,6 +1666,7 @@ def test_frontogenesis_4d(data_4d):
16571666
assert_array_almost_equal(frnt.data, truth, 13)
16581667

16591668

1669+
@pytest.mark.network
16601670
def test_geostrophic_wind_4d(data_4d):
16611671
"""Test geostrophic_wind on a 4D (time, pressure, y, x) grid."""
16621672
u_g, v_g = geostrophic_wind(data_4d.height)
@@ -1772,6 +1782,7 @@ def test_geostrophic_wind_4d(data_4d):
17721782
assert_array_almost_equal(v_g.data, v_g_truth, 4)
17731783

17741784

1785+
@pytest.mark.network
17751786
def test_inertial_advective_wind_4d(data_4d):
17761787
"""Test inertial_advective_wind on a 4D (time, pressure, y, x) grid."""
17771788
u_g, v_g = geostrophic_wind(data_4d.height)
@@ -1860,6 +1871,7 @@ def test_inertial_advective_wind_4d(data_4d):
18601871
assert_array_almost_equal(v_i.data, v_i_truth, 4)
18611872

18621873

1874+
@pytest.mark.network
18631875
def test_q_vector_4d(data_4d):
18641876
"""Test q_vector on a 4D (time, pressure, y, x) grid."""
18651877
u_g, v_g = geostrophic_wind(data_4d.height)

tests/interpolate/test_grid.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def test_generate_grid_coords():
151151
assert pts.flags['C_CONTIGUOUS'] # need output to be C-contiguous
152152

153153

154+
@pytest.mark.network
154155
def test_natural_neighbor_to_grid(test_data, test_grid):
155156
r"""Test natural neighbor interpolation to grid function."""
156157
xp, yp, z = test_data
@@ -167,6 +168,7 @@ def test_natural_neighbor_to_grid(test_data, test_grid):
167168
interp_methods = ['cressman', 'barnes']
168169

169170

171+
@pytest.mark.network
170172
@pytest.mark.parametrize('method', interp_methods)
171173
def test_inverse_distance_to_grid(method, test_data, test_grid):
172174
r"""Test inverse distance interpolation to grid function."""
@@ -243,6 +245,7 @@ def test_interpolate_to_isosurface():
243245
assert_array_almost_equal(truth, dt_theta)
244246

245247

248+
@pytest.mark.network
246249
@pytest.mark.parametrize('assume_units', [None, 'mbar'])
247250
@pytest.mark.parametrize('method', interp_methods)
248251
@pytest.mark.parametrize('boundary_coords', boundary_types)

tests/interpolate/test_points.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def test_barnes_point(test_data):
9696
assert_almost_equal(barnes_point(dists, values, 5762.7), 4.0871824)
9797

9898

99+
@pytest.mark.network
99100
def test_natural_neighbor_to_points(test_data, test_points):
100101
r"""Test natural neighbor interpolation to grid function."""
101102
xp, yp, z = test_data
@@ -109,6 +110,7 @@ def test_natural_neighbor_to_points(test_data, test_points):
109110
assert_array_almost_equal(truth, img)
110111

111112

113+
@pytest.mark.network
112114
def test_inverse_distance_to_points_invalid(test_data, test_points):
113115
"""Test that inverse_distance_to_points raises when given an invalid method."""
114116
xp, yp, z = test_data
@@ -117,6 +119,7 @@ def test_inverse_distance_to_points_invalid(test_data, test_points):
117119
inverse_distance_to_points(obs_points, z, test_points, kind='shouldraise', r=40)
118120

119121

122+
@pytest.mark.network
120123
@pytest.mark.parametrize('assume_units', [None, 'mbar'])
121124
@pytest.mark.parametrize('method', ['cressman', 'barnes'])
122125
def test_inverse_distance_to_points(method, assume_units, test_data, test_points):
@@ -138,6 +141,7 @@ def test_inverse_distance_to_points(method, assume_units, test_data, test_points
138141
assert_array_almost_equal(truth, img)
139142

140143

144+
@pytest.mark.network
141145
def test_interpolate_to_points_invalid(test_data):
142146
"""Test that interpolate_to_points raises when given an invalid method."""
143147
xp, yp, z = test_data
@@ -150,6 +154,7 @@ def test_interpolate_to_points_invalid(test_data):
150154
interpolate_to_points(obs_points, z, test_points, interp_type='shouldraise')
151155

152156

157+
@pytest.mark.network
153158
@pytest.mark.parametrize('assume_units', [None, 'mbar'])
154159
@pytest.mark.parametrize('method', ['natural_neighbor', 'cressman', 'barnes', 'linear',
155160
'nearest', 'rbf', 'cubic'])

0 commit comments

Comments
 (0)