summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2023-02-14 19:11:22 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2023-03-06 19:38:15 +0000
commit62be049045fad723cd6f4834ea63e47aafc7a716 (patch)
tree24965bb13161b28f058e68c645af74b03fb93bdc /setuptools
parent57ff9519bdd7024d9b0f98227055229786181522 (diff)
downloadpython-setuptools-git-62be049045fad723cd6f4834ea63e47aafc7a716.tar.gz
Add tests for warning formatting and tweaks to implementation
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/tests/test_warnings.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/setuptools/tests/test_warnings.py b/setuptools/tests/test_warnings.py
new file mode 100644
index 00000000..75e468d2
--- /dev/null
+++ b/setuptools/tests/test_warnings.py
@@ -0,0 +1,106 @@
+from inspect import cleandoc
+
+import pytest
+
+from setuptools.warnings import SetuptoolsDeprecationWarning, SetuptoolsWarning
+
+
+_EXAMPLES = {
+ "default": dict(
+ args=("Hello {x}", "\n\t{target} {v:.1f}"),
+ kwargs={"x": 5, "v": 3, "target": "World"},
+ expected = """
+ Hello 5
+ !!
+
+ ********************************************************************************
+ World 3.0
+ ********************************************************************************
+
+ !!
+ """ # noqa,
+ ),
+ "futue_due_date": dict(
+ args=("Summary", "Lorem ipsum"),
+ kwargs={"due_date": (9999, 11, 22)},
+ expected = """
+ Summary
+ !!
+
+ ********************************************************************************
+ Lorem ipsum
+
+ By 9999-Nov-22, you need to update your project and remove deprecated calls
+ or your builds will no longer be supported.
+ ********************************************************************************
+
+ !!
+ """ # noqa
+ ),
+ "past_due_date_with_docs": dict(
+ args=("Summary", "Lorem ipsum"),
+ kwargs={"due_date": (2000, 11, 22), "see_docs": "some_page.html"},
+ expected="""
+ Summary
+ !!
+
+ ********************************************************************************
+ Lorem ipsum
+
+ This deprecation is overdue, please update your project and remove deprecated
+ calls to avoid build errors in the future.
+
+ See https://setuptools.pypa.io/en/latest/some_page.html for details.
+ ********************************************************************************
+
+ !!
+ """ # noqa
+ ),
+}
+
+
+@pytest.mark.parametrize("example_name", _EXAMPLES.keys())
+def test_formatting(example_name):
+ """
+ It should automatically handle indentation, interpolation and things like due date.
+ """
+ args = _EXAMPLES[example_name]["args"]
+ kwargs = _EXAMPLES[example_name]["kwargs"]
+ expected = _EXAMPLES[example_name]["expected"]
+
+ with pytest.warns(SetuptoolsWarning) as warn_info:
+ SetuptoolsWarning.emit(*args, **kwargs)
+ assert _get_message(warn_info) == cleandoc(expected)
+
+
+def test_due_date_enforcement(monkeypatch):
+ class _MyDeprecation(SetuptoolsDeprecationWarning):
+ _SUMMARY = "Summary"
+ _DETAILS = "Lorem ipsum"
+ _DUE_DATE = (2000, 11, 22)
+ _SEE_DOCS = "some_page.html"
+
+ monkeypatch.setenv("SETUPTOOLS_ENFORCE_DEPRECATION", "true")
+ with pytest.raises(SetuptoolsDeprecationWarning) as exc_info:
+ _MyDeprecation.emit()
+
+ expected="""
+ Summary
+ !!
+
+ ********************************************************************************
+ Lorem ipsum
+
+ This deprecation is overdue, please update your project and remove deprecated
+ calls to avoid build errors in the future.
+
+ See https://setuptools.pypa.io/en/latest/some_page.html for details.
+ ********************************************************************************
+
+ !!
+ """ # noqa
+ assert str(exc_info.value) == cleandoc(expected)
+
+
+def _get_message(warn_info):
+ return next(warn.message.args[0] for warn in warn_info)