Skip to content
Myr

Added deprecation warnings for modules

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 5910ef8 · Browse files · 2 files+47 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+47 added−4 removed

  • tests:+30 added−4 removed
  • other:+17 added−0 removed

2 files+47 added−4 removed

modified:flask/app.py+17 added
167 unmodified lines
168 #:169 #: .. versionadded:: 0.4170 logger_name = ConfigAttribute('LOGGER_NAME')171172 #: Enable the deprecated module support? This is active by default173 #: in 0.7 but will be changed to False in 0.8. With Flask 1.0 modules174 #: will be removed in favor of Blueprints175 enable_modules = True176177 #: The logging format used for the debug logger. This is only used when178 #: the application is in debug mode, otherwise the attached logging179 #: handler does the formatting.180 #:
356 unmodified lines
537 of this function are the same as the ones for the constructor of the538 :class:`Module` class and will override the values of the module if539 provided.540 """541 if not self.enable_modules:542 raise RuntimeError('Module support was disabled but code '543 'attempted to register a module named %r' % module)544 else:545 from warnings import warn546 warn(DeprecationWarning('Modules are deprecated. Upgrade to '547 'using blueprints. Have a look into the documentation for '548 'more information. If this module was registered by a '549 'Flask-Extension upgrade the extension or contact the author '550 'of that extension instead. (Registered %r)' % module),551 stacklevel=2)552553 options.setdefault('url_prefix', module.url_prefix)554 options.setdefault('subdomain', module.subdomain)555 self.view_functions.update(module.view_functions)556 state = _ModuleSetupState(self, **options)
493 unmodified lines
modified:tests/flask_tests.py+30 added-4 removed
13 unmodified lines
14import re15import sys16import flask17import unittest18import warnings19from threading import Thread20from logging import StreamHandler21from contextlib import contextmanager22from functools import update_wrapper23from datetime import datetime24from werkzeug import parse_date, parse_options_header25from werkzeug.exceptions import NotFound26from jinja2 import TemplateNotFound
17 unmodified lines
44TEST_KEY = 'foo'45SECRET_KEY = 'devkey'464748# import moduleapp here because it uses deprecated features and we don't49# want to see the warnings50warnings.simplefilter('ignore', DeprecationWarning)51from moduleapp import app as moduleapp52warnings.simplefilter('default', DeprecationWarning)535455@contextmanager56def catch_warnings():57 """Catch warnings in a with block in a list"""49 import warnings5058 # make sure deprecation warnings are active in tests59 warnings.simplefilter('default', category=DeprecationWarning)6061 filters = warnings.filters
20 unmodified lines
82 finally:83 sys.stderr = old_stderr848586def emits_module_deprecation_warning(f):87 def new_f(*args, **kwargs):88 with catch_warnings() as log:89 f(*args, **kwargs)90 assert log, 'expected deprecation warning'91 for entry in log:92 assert 'Modules are deprecated' in str(entry['message'])93 return update_wrapper(new_f, f)949596class ContextTestCase(unittest.TestCase):9798 def test_context_binding(self):99 app = flask.Flask(__name__)
877 unmodified lines
977978979class ModuleTestCase(unittest.TestCase):980981 @emits_module_deprecation_warning982 def test_basic_module(self):983 app = flask.Flask(__name__)984 admin = flask.Module(__name__, 'admin', url_prefix='/admin')985 @admin.route('/')
14 unmodified lines
1000 assert c.get('/admin/').data == 'admin index'1001 assert c.get('/admin/login').data == 'admin login'1002 assert c.get('/admin/logout').data == 'admin logout'10031004 @emits_module_deprecation_warning1005 def test_default_endpoint_name(self):1006 app = flask.Flask(__name__)1007 mod = flask.Module(__name__, 'frontend')1008 def index():
4 unmodified lines
1013 assert rv.data == 'Awesome'1014 with app.test_request_context():1015 assert flask.url_for('frontend.index') == '/'10161017 @emits_module_deprecation_warning1018 def test_request_processing(self):1019 catched = []1020 app = flask.Flask(__name__)1021 admin = flask.Module(__name__, 'admin', url_prefix='/admin')
27 unmodified lines
1049 assert c.get('/admin/').data == 'the admin'1050 assert catched == ['before-app', 'before-admin',1051 'after-admin', 'after-app']10521053 @emits_module_deprecation_warning1054 def test_context_processors(self):1055 app = flask.Flask(__name__)1056 admin = flask.Module(__name__, 'admin', url_prefix='/admin')1057 @app.context_processor
15 unmodified lines
1073 c = app.test_client()1074 assert c.get('/').data == '13'1075 assert c.get('/admin/').data == '123'10761077 @emits_module_deprecation_warning1078 def test_late_binding(self):1079 app = flask.Flask(__name__)1080 admin = flask.Module(__name__, 'admin')1081 @admin.route('/')
1 unmodified line
1083 return '42'1084 app.register_module(admin, url_prefix='/admin')1085 assert app.test_client().get('/admin/').data == '42'10861087 @emits_module_deprecation_warning1088 def test_error_handling(self):1089 app = flask.Flask(__name__)1090 admin = flask.Module(__name__, 'admin')1091 @admin.app_errorhandler(404)
17 unmodified lines
1109 assert rv.status_code == 5001110 assert 'internal server error' == rv.data11111112 def test_templates_and_static(self):1090 from moduleapp import app1113 app = moduleapp1114 c = app.test_client()11151116 rv = c.get('/')1117 assert rv.data == 'Hello from the Frontend'
21 unmodified lines
1139 with flask.Flask(__name__).test_request_context():1140 assert flask.render_template('nested/nested.txt') == 'I\'m nested'11411142 def test_safe_access(self):1120 from moduleapp import app1143 app = moduleapp11441145 with app.test_request_context():1146 f = app.view_functions['admin.static']1147
24 unmodified lines
1172 assert 0, 'expected exception'1173 finally:1174 os.path = old_path11751176 @emits_module_deprecation_warning1177 def test_endpoint_decorator(self):1178 from werkzeug.routing import Submount, Rule1179 from flask import Module1180
281 unmodified lines
14621463 rv = c.get('/', 'http://test.localhost/')1464 assert rv.data == 'test index'14651466 @emits_module_deprecation_warning1467 def test_module_static_path_subdomain(self):1468 app = flask.Flask(__name__)1469 app.config['SERVER_NAME'] = 'example.com'1470 from subdomaintestmodule import mod
12 unmodified lines
1483 c = app.test_client()1484 rv = c.get('/', 'http://mitsuhiko.localhost/')1485 assert rv.data == 'index for mitsuhiko'14861487 @emits_module_deprecation_warning1488 def test_module_subdomain_support(self):1489 app = flask.Flask(__name__)1490 mod = flask.Module(__name__, 'test', subdomain='testing')1491 app.config['SERVER_NAME'] = 'localhost'
144 unmodified lines