From 933851183ed9cce2d3411f890dca3e19385480f6 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Mon, 12 Apr 2021 20:17:18 +0200 Subject: [PATCH] fix(api_helpers): re-add falcon.api_helpers (#1904) --- docs/_newsfragments/1902.rst | 2 ++ falcon/api_helpers.py | 7 +++++++ falcon/app_helpers.py | 7 +++++++ tests/test_deprecations.py | 26 +++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 docs/_newsfragments/1902.rst create mode 100644 falcon/api_helpers.py diff --git a/docs/_newsfragments/1902.rst b/docs/_newsfragments/1902.rst new file mode 100644 index 000000000..2d0ebd868 --- /dev/null +++ b/docs/_newsfragments/1902.rst @@ -0,0 +1,2 @@ +Re-add ``api_helpers`` module that was renamed ``app_helpers``. +This module is considered deprecated, and will be removed in a future Falcon version. \ No newline at end of file diff --git a/falcon/api_helpers.py b/falcon/api_helpers.py new file mode 100644 index 000000000..9024872ad --- /dev/null +++ b/falcon/api_helpers.py @@ -0,0 +1,7 @@ +from .app_helpers import * # NOQA + +# TODO deprecate +# import warnings +# from .util.deprecation import DeprecatedWarning + +# warnings.warn('The api_helpers module was renamed to app_helpers.', DeprecatedWarning) diff --git a/falcon/app_helpers.py b/falcon/app_helpers.py index 2d9bcd0c1..03951b7c9 100644 --- a/falcon/app_helpers.py +++ b/falcon/app_helpers.py @@ -22,6 +22,13 @@ from falcon.errors import CompatibilityError from falcon.util.sync import _wrap_non_coroutine_unsafe +__all__ = ( + 'prepare_middleware', + 'prepare_middleware_ws', + 'default_serialize_error', + 'CloseableStreamIterator' +) + def prepare_middleware(middleware, independent_middleware=False, asgi=False): """Check middleware interfaces and prepare the methods for request handling. diff --git a/tests/test_deprecations.py b/tests/test_deprecations.py index 09570a3b0..dd6a0332b 100644 --- a/tests/test_deprecations.py +++ b/tests/test_deprecations.py @@ -1,6 +1,30 @@ -from falcon import request_helpers, stream +import pytest + +from falcon import app_helpers, request_helpers, stream + +# from _util import has_cython def test_bounded_stream(): assert request_helpers.Body is stream.Body assert request_helpers.BoundedStream is stream.BoundedStream + + +class TestApiHelpers: + @pytest.mark.filterwarnings('ignore:The api_helpers') + def test_imports(self): + from falcon import api_helpers + + for name in app_helpers.__all__: + assert getattr(api_helpers, name) is getattr(app_helpers, name) + + # TODO enable test of deprecation + # @pytest.mark.skipif(has_cython, reason='Reloading modules on Cython does not work') + # def test_warning(self): + # import importlib + + # from falcon.util.deprecation import DeprecatedWarning + + # with pytest.warns(DeprecatedWarning, match='The api_helpers'): + # from falcon import api_helpers + # importlib.reload(api_helpers)