コード例 #1
0
def test_warn_deprecated_broken_new_qualname_no_check():
    """Fail if new qualname is wrong."""
    warn_deprecated(
        deprecated_qual_name_usage="glotaran.does_not_exists(foo)",
        new_qual_name_usage="glotaran.does_not_exists(foo)",
        to_be_removed_in_version="0.6.0",
        check_qual_names=(False, True),
    )
コード例 #2
0
def test_warn_deprecated_broken_deprecated_qualname(
        deprecated_qual_name_usage: str, new_qual_name_usage: str):
    """Fail if any qualname is wrong."""
    warn_deprecated(
        deprecated_qual_name_usage=deprecated_qual_name_usage,
        new_qual_name_usage=new_qual_name_usage,
        to_be_removed_in_version="0.6.0",
    )
コード例 #3
0
def test_warn_deprecated_overdue_deprecation(monkeypatch: MonkeyPatch):
    """Current version is equal or bigger than drop_version."""

    with pytest.raises(OverDueDeprecation) as excinfo:
        warn_deprecated(
            deprecated_qual_name_usage=DEPRECATION_QUAL_NAME,
            new_qual_name_usage=NEW_QUAL_NAME,
            to_be_removed_in_version="0.6.0",
        )
    assert str(excinfo.value) == OVERDUE_ERROR_MESSAGE
コード例 #4
0
def test_warn_deprecated_sliced_mapping():
    """Slice away mapping for importing and check class for attribute"""
    with pytest.warns(DeprecationWarning):
        warn_deprecated(
            deprecated_qual_name_usage=
            ("glotaran.deprecation.test.test_deprecation_utils.DummyClass.foo['bar']"
             ),
            new_qual_name_usage=DEPRECATION_QUAL_NAME,
            to_be_removed_in_version="0.6.0",
            importable_indices=(2, 1),
        )
コード例 #5
0
def test_warn_deprecated_broken_qualname_no_check(
        deprecated_qual_name_usage: str, new_qual_name_usage: str,
        check_qualnames: tuple[bool, bool]):
    """Not checking broken imports."""
    with pytest.warns(DeprecationWarning):
        warn_deprecated(
            deprecated_qual_name_usage=deprecated_qual_name_usage,
            new_qual_name_usage=new_qual_name_usage,
            to_be_removed_in_version="0.6.0",
            check_qual_names=check_qualnames,
        )
コード例 #6
0
def test_warn_deprecated():
    """Warning gets shown when all is in order."""
    with pytest.warns(DeprecationWarning) as record:
        warn_deprecated(
            deprecated_qual_name_usage=DEPRECATION_QUAL_NAME,
            new_qual_name_usage=NEW_QUAL_NAME,
            to_be_removed_in_version="0.6.0",
        )

        assert len(record) == 1
        assert record[0].message.args[0] == DEPRECATION_WARN_MESSAGE
        assert Path(record[0].filename) == Path(__file__)
コード例 #7
0
def test_warn_deprecated_no_overdue_deprecation_on_dev(
        monkeypatch: MonkeyPatch):
    """Current version is equal or bigger than drop_version but it's a dev version."""
    monkeypatch.setattr(glotaran.deprecation.deprecation_utils,
                        "glotaran_version", lambda: "0.6.0-dev")

    with pytest.raises(OverDueDeprecation):
        warn_deprecated(
            deprecated_qual_name_usage=DEPRECATION_QUAL_NAME,
            new_qual_name_usage=NEW_QUAL_NAME,
            to_be_removed_in_version="0.6.0",
        )
コード例 #8
0
def test_warn_deprecated_overdue_deprecation(monkeypatch: MonkeyPatch):
    """Current version is equal or bigger than drop_version."""
    monkeypatch.setattr(glotaran.deprecation.deprecation_utils,
                        "glotaran_version", lambda: "1.0.0")

    with pytest.raises(OverDueDeprecation) as record:
        warn_deprecated(
            deprecated_qual_name_usage=DEPRECATION_QUAL_NAME,
            new_qual_name_usage=NEW_QUAL_NAME,
            to_be_removed_in_version="0.6.0",
        )

        assert len(record) == 1  # type: ignore [arg-type]
        expected = ("Support for 'glotaran.read_model_from_yaml' was supposed "
                    "to be dropped in version: '0.6.0'.\n"
                    "Current version is: '1.0.0'")

        assert record[0].message.args[0] == expected  # type: ignore [index]
        assert Path(record[0].filename) == Path(
            __file__)  # type: ignore [index]