Example #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)
Example #2
0
def test_deprecation_class_text_specified(text: Optional[str]) -> None:
    class _Class:
        def __init__(self, a: Any, b: Any, c: Any) -> None:
            pass

    decorator_deprecation = _deprecated.deprecated_class("1.1.0",
                                                         "3.0.0",
                                                         text=text)
    decorated_class = decorator_deprecation(_Class)
    expected_class_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_class_doc += "\n\n    " + text + "\n"
    else:
        expected_class_doc += "\n\n\n"
    assert decorated_class.__name__ == _Class.__name__
    assert decorated_class.__doc__ == expected_class_doc

    with pytest.warns(FutureWarning) as record:
        decorated_class(None, None, None)
    assert isinstance(record.list[0].message, Warning)
    expected_warning_message = _deprecated._DEPRECATION_WARNING_TEMPLATE.format(
        name="_Class", 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
Example #3
0
def test_deprecation_class_decorator_name() -> None:

    name = "foo"
    decorator_deprecation = _deprecated.deprecated_class("1.1.0",
                                                         "3.0.0",
                                                         name=name)
    decorated_sample = decorator_deprecation(_Sample)

    with pytest.warns(FutureWarning) as record:
        decorated_sample("a", "b", "c")

    assert isinstance(record.list[0].message, Warning)
    assert name in record.list[0].message.args[0]
Example #4
0
def test_deprecation_class_decorator() -> None:
    deprecated_version = "1.1.0"
    removed_version = "3.0.0"
    decorator_deprecation = _deprecated.deprecated_class(
        deprecated_version, removed_version)
    assert callable(decorator_deprecation)

    decorated_class = decorator_deprecation(_Sample)
    assert decorated_class.__name__ == "_Sample"
    assert decorated_class.__init__.__name__ == "__init__"
    assert decorated_class.__doc__ == _deprecated._DEPRECATION_NOTE_TEMPLATE.format(
        d_ver=deprecated_version, r_ver=removed_version)

    with pytest.warns(FutureWarning):
        decorated_class("a", "b", "c")