CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_warnings.py107 linesDownload Raw Back to tests
1from inspect import cleandoc2 3import pytest4 5from setuptools.warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning6 7_EXAMPLES = {8    "default": dict(9        args=("Hello {x}", "\n\t{target} {v:.1f}"),10        kwargs={"x": 5, "v": 3, "target": "World"},11        expected="""12    Hello 513    !!14 15            ********************************************************************************16            World 3.017            ********************************************************************************18 19    !!20    """,21    ),22    "futue_due_date": dict(23        args=("Summary", "Lorem ipsum"),24        kwargs={"due_date": (9999, 11, 22)},25        expected="""26    Summary27    !!28 29            ********************************************************************************30            Lorem ipsum31 32            By 9999-Nov-22, you need to update your project and remove deprecated calls33            or your builds will no longer be supported.34            ********************************************************************************35 36    !!37    """,38    ),39    "past_due_date_with_docs": dict(40        args=("Summary", "Lorem ipsum"),41        kwargs={"due_date": (2000, 11, 22), "see_docs": "some_page.html"},42        expected="""43    Summary44    !!45 46            ********************************************************************************47            Lorem ipsum48 49            This deprecation is overdue, please update your project and remove deprecated50            calls to avoid build errors in the future.51 52            See https://setuptools.pypa.io/en/latest/some_page.html for details.53            ********************************************************************************54 55    !!56    """,57    ),58}59 60 61@pytest.mark.parametrize("example_name", _EXAMPLES.keys())62def test_formatting(monkeypatch, example_name):63    """64    It should automatically handle indentation, interpolation and things like due date.65    """66    args = _EXAMPLES[example_name]["args"]67    kwargs = _EXAMPLES[example_name]["kwargs"]68    expected = _EXAMPLES[example_name]["expected"]69 70    monkeypatch.setenv("SETUPTOOLS_ENFORCE_DEPRECATION", "false")71    with pytest.warns(SetuptoolsWarning) as warn_info:72        SetuptoolsWarning.emit(*args, **kwargs)73    assert _get_message(warn_info) == cleandoc(expected)74 75 76def test_due_date_enforcement(monkeypatch):77    class _MyDeprecation(SetuptoolsDeprecationWarning):78        _SUMMARY = "Summary"79        _DETAILS = "Lorem ipsum"80        _DUE_DATE = (2000, 11, 22)81        _SEE_DOCS = "some_page.html"82 83    monkeypatch.setenv("SETUPTOOLS_ENFORCE_DEPRECATION", "true")84    with pytest.raises(SetuptoolsDeprecationWarning) as exc_info:85        _MyDeprecation.emit()86 87    expected = """88    Summary89    !!90 91            ********************************************************************************92            Lorem ipsum93 94            This deprecation is overdue, please update your project and remove deprecated95            calls to avoid build errors in the future.96 97            See https://setuptools.pypa.io/en/latest/some_page.html for details.98            ********************************************************************************99 100    !!101    """102    assert str(exc_info.value) == cleandoc(expected)103 104 105def _get_message(warn_info):106    return next(warn.message.args[0] for warn in warn_info)107 
Aluode/PerceptionLabPortable · CoolFace