1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
from iminuit._deprecated import deprecated, deprecated_parameter
import pytest
def test_deprecated_func_1():
@deprecated("bla")
def func(x):
pass
with pytest.warns(
FutureWarning,
match="func is deprecated: bla",
):
func(1)
def test_deprecated_func_2():
@deprecated("bla", removal="1.0")
def func(x):
pass
with pytest.warns(
DeprecationWarning,
match="func is deprecated and will be removed in version 1.0: bla",
):
func(1)
def test_deprecated_func_3():
@deprecated("bla", removal="1000.0")
def func(x):
pass
with pytest.warns(
FutureWarning,
match="func is deprecated and will be removed in version 1000.0: bla",
):
func(1)
def test_deprecated_parameter():
@deprecated_parameter(foo="bar")
def some_function(x, y, foo):
pass
some_function(1, 2, foo=3)
with pytest.warns(
FutureWarning,
match="keyword 'bar' is deprecated, please use 'foo'",
):
some_function(1, 2, bar=3)
with pytest.raises(TypeError):
some_function(x=1, baz=3, y=2)
|