Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_test(self, decorator, callobj, obj):
with pytest.warns(DeprecationWarning) as record:
o = decorator(callobj)
args = (1, 2, 3)
kwargs = {'a': 1, 'b': 2, 'c': 3}
if obj:
o(obj(), *args, **kwargs)
else:
o(*args, **kwargs)
return record
def test_no_ageostrophic_geopotential():
"""Test ageostrophic wind calculation with geopotential and no ageostrophic wind."""
z = np.array([[48, 49, 48], [49, 50, 49], [48, 49, 48]]) * 100. * units('m^2/s^2')
u = np.array([[-2, 0, 2]] * 3) * units('m/s')
v = -u.T
with pytest.warns(FutureWarning):
uag, vag = ageostrophic_wind(z, 1 / units.sec, 100. * units.meter, 100. * units.meter,
u, v, dim_order='xy')
true = np.array([[0, 0, 0]] * 3) * units('m/s')
assert_array_equal(uag, true)
assert_array_equal(vag, true)
with pytest.warns(UserWarning) as record:
opt = Optimiser(scoring=mape, n_folds=3)
assert len(record) == 1
score = opt.evaluate(None, dict)
assert -np.Inf <= score
with pytest.warns(UserWarning) as record:
opt = Optimiser(scoring=None, n_folds=3)
assert len(record) == 1
score = opt.evaluate(None, dict)
assert -np.Inf <= score
with pytest.warns(UserWarning) as record:
opt = Optimiser(scoring="wrong_scoring", n_folds=3)
assert len(record) == 1
with pytest.warns(UserWarning) as record:
score = opt.evaluate(None, dict)
assert -np.Inf <= score
def test_public_search(ocx, api_data):
with pytest.warns(DeprecationWarning):
samples = ocx.Samples.search_public(filename="tmp.fa")
assert len(samples) == 0
samples = ocx.Samples.where(filename="tmp.fa", public=True)
assert len(samples) == 0
def test_warn_on_too_dense():
import os
from importlib import reload
os.environ['SPARSE_WARN_ON_TOO_DENSE'] = '1'
reload(sparse._settings)
with pytest.warns(RuntimeWarning):
sparse.random((3, 4, 5), density=1.0)
del os.environ['SPARSE_WARN_ON_TOO_DENSE']
reload(sparse._settings)
def test_equivalent_proj():
with pytest.warns(UserWarning):
proj_to = pyproj.Proj(4326).crs.to_proj4()
with pytest.warns(FutureWarning):
transformer = Transformer.from_proj(
"+init=epsg:4326", proj_to, skip_equivalent=True
)
assert transformer._transformer.skip_equivalent
assert transformer._transformer.projections_equivalent
assert not transformer._transformer.projections_exact_same
def test_cog_translate_oneBandJpeg(runner):
"""Should work as expected (create cogeo file)."""
with runner.isolated_filesystem():
profile = jpeg_profile.copy()
with pytest.warns(UserWarning):
cog_translate(
raster_path_rgb, "cogeo.tif", profile, indexes=(1,), quiet=True
)
with rasterio.open("cogeo.tif") as src:
assert src.compression.value == "JPEG"
assert src.colorinterp[0] == rasterio.enums.ColorInterp.gray
def test_save_version_warning(
self, versioned_yaml_data_set, load_version, save_version, yaml_data
):
"""Check the warning when saving to the path that differs from
the subsequent load path."""
pattern = (
r"Save version `{0}` did not match load version `{1}` "
r"for YAMLLocalDataSet\(.+\)".format(save_version, load_version)
)
with pytest.warns(UserWarning, match=pattern):
versioned_yaml_data_set.save(yaml_data)
false_northing=0.0,
)
)
cf_dict = crs.to_cf()
assert cf_dict.pop("crs_wkt").startswith("PROJCRS[")
assert cf_dict == {
"grid_mapping_name": "oblique_mercator",
"latitude_of_projection_origin": 10,
"longitude_of_projection_origin": 15,
"azimuth_of_central_line": 0.35,
"false_easting": 0,
"false_northing": 0,
"reference_ellipsoid_name": "WGS84",
"unit": "m",
}
with pytest.warns(UserWarning):
assert crs.to_dict() == {
"proj": "omerc",
"lat_0": 10,
"lonc": 15,
"alpha": 0.35,
"gamma": 0.35,
"k": 1,
"x_0": 0,
"y_0": 0,
"ellps": "WGS84",
"units": "m",
"no_defs": None,
"type": "crs",
}
# test CRS with input as lon_0 from the user
lon0crs_cf = CRS(
async def test_custom_response_cls(with_subclass):
class CustomResponse(EventSourceResponse if with_subclass else object):
pass
request = make_mocked_request('GET', '/')
if with_subclass:
with pytest.warns(RuntimeWarning):
sse_response(request, response_cls=CustomResponse)
else:
with pytest.raises(TypeError):
sse_response(request, response_cls=CustomResponse)