예제 #1
0
def test_deprecation_raises_error_for_invalid_version(
        deprecated_version: Any, removed_version: Any) -> None:
    with pytest.raises(ValueError):
        _deprecated.deprecated_func(deprecated_version, removed_version)

    with pytest.raises(ValueError):
        _deprecated.deprecated_class(deprecated_version, removed_version)
예제 #2
0
def test_deprecation_text_specified(text: Optional[str]) -> None:
    def _func() -> int:

        return 10

    decorator_deprecation = _deprecated.deprecated_func("1.1.0",
                                                        "3.0.0",
                                                        text=text)
    decorated_func = decorator_deprecation(_func)
    expected_func_doc = _deprecated._DEPRECATION_NOTE_TEMPLATE.format(
        d_ver="1.1.0", r_ver="3.0.0")
    if text is None:
        pass
    elif len(text) > 0:
        expected_func_doc += "\n\n    " + text + "\n"
    else:
        expected_func_doc += "\n\n\n"
    assert decorated_func.__name__ == _func.__name__
    assert decorated_func.__doc__ == expected_func_doc

    with pytest.warns(FutureWarning) as record:
        decorated_func()
    assert isinstance(record.list[0].message, Warning)
    expected_warning_message = _deprecated._DEPRECATION_WARNING_TEMPLATE.format(
        name="_func", d_ver="1.1.0", r_ver="3.0.0")
    if text is not None:
        expected_warning_message += " " + text
    assert record.list[0].message.args[0] == expected_warning_message
예제 #3
0
def test_deprecation_instance_method_decorator() -> None:
    deprecated_version = "1.1.0"
    removed_version = "3.0.0"
    decorator_deprecation = _deprecated.deprecated_func(
        deprecated_version, removed_version)
    assert callable(decorator_deprecation)

    decorated_method = decorator_deprecation(_Sample._method)
    assert decorated_method.__name__ == _Sample._method.__name__
    assert decorated_method.__doc__ == _Sample._method_expected.__doc__

    with pytest.warns(FutureWarning):
        decorated_method(None)  # type: ignore
예제 #4
0
def test_deprecation_decorator_name() -> None:
    def _func() -> int:

        return 10

    name = "bar"
    decorator_deprecation = _deprecated.deprecated_func("1.1.0",
                                                        "3.0.0",
                                                        name=name)
    decorated_sample_func = decorator_deprecation(_func)

    with pytest.warns(FutureWarning) as record:
        decorated_sample_func()

    assert isinstance(record.list[0].message, Warning)
    assert name in record.list[0].message.args[0]
예제 #5
0
def test_deprecation_decorator() -> None:
    deprecated_version = "1.1.0"
    removed_version = "3.0.0"
    decorator_deprecation = _deprecated.deprecated_func(
        deprecated_version, removed_version)
    assert callable(decorator_deprecation)

    def _func() -> int:

        return 10

    decorated_func = decorator_deprecation(_func)
    assert decorated_func.__name__ == _func.__name__
    assert decorated_func.__doc__ == _deprecated._DEPRECATION_NOTE_TEMPLATE.format(
        d_ver=deprecated_version, r_ver=removed_version)

    with pytest.warns(FutureWarning):
        decorated_func()