Testsuite is not a package
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 56db3dd · Browse files · 4 files·+34 added−95 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+34 added−95 removed
- tests:+34 added−95 removed
Provenance
- Commit
192da32- Tree
51073c6- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
56db3dd
4 files changed+34 added−95 removed
deleted:tests/__init__.py-62 removed
1-# -*- coding: utf-8 -*-2-"""3- tests4- ~~~~~~~~~~~~~~~5-6- Tests Flask itself. The majority of Flask is already tested7- as part of Werkzeug.8-9- :copyright: (c) 2014 by Armin Ronacher.10- :license: BSD, see LICENSE for more details.11-"""12-13-from __future__ import print_function14-15-import os16-import sys17-import warnings18-from functools import update_wrapper19-from contextlib import contextmanager20-from flask._compat import StringIO21-22-23-@contextmanager24-def catch_warnings():25- """Catch warnings in a with block in a list"""26- # make sure deprecation warnings are active in tests27- warnings.simplefilter('default', category=DeprecationWarning)28-29- filters = warnings.filters30- warnings.filters = filters[:]31- old_showwarning = warnings.showwarning32- log = []33-34- def showwarning(message, category, filename, lineno, file=None, line=None):35- log.append(locals())36- try:37- warnings.showwarning = showwarning38- yield log39- finally:40- warnings.filters = filters41- warnings.showwarning = old_showwarning42-43-44-@contextmanager45-def catch_stderr():46- """Catch stderr in a StringIO"""47- old_stderr = sys.stderr48- sys.stderr = rv = StringIO()49- try:50- yield rv51- finally:52- sys.stderr = old_stderr53-54-55-def emits_module_deprecation_warning(f):56- def new_f(self, *args, **kwargs):57- with catch_warnings() as log:58- f(self, *args, **kwargs)59- assert log, 'expected deprecation warning'60- for entry in log:61- assert 'Modules are deprecated' in str(entry['message'])62- return update_wrapper(new_f, f)modified:tests/conftest.py+7 added
123 unmodified lines124 def purge_module(request):125 def inner(name):126 request.addfinalizer(lambda: sys.modules.pop(name, None))127 return inner128+129+130+@pytest.fixture131+def catch_deprecation_warnings():132+ import warnings133+ warnings.simplefilter('default', category=DeprecationWarning)134+ return lambda: warnings.catch_warnings(record=True)modified:tests/test_helpers.py+18 added-26 removed
11 unmodified lines12 import pytest13 14 import os15 import flask16-import unittest16 from logging import StreamHandler18-from tests import catch_warnings, catch_stderr17 from werkzeug.http import parse_cache_control_header, parse_options_header18 from flask._compat import StringIO, text_type19 20 242 unmodified lines263 os.path.join(app.root_path, 'static/index.html')264 assert rv.mimetype == 'text/html'265 rv.close()266 269- def test_send_file_object(self):267+ def test_send_file_object(self, catch_deprecation_warnings):268 app = flask.Flask(__name__)271- with catch_warnings() as captured:269+ with catch_deprecation_warnings() as captured:270 with app.test_request_context():271 f = open(os.path.join(app.root_path, 'static/index.html'), mode='rb')272 rv = flask.send_file(f)273 rv.direct_passthrough = False4 unmodified lines278 # mimetypes + etag279 assert len(captured) == 2280 281 app.use_x_sendfile = True284- with catch_warnings() as captured:282+ with catch_deprecation_warnings() as captured:283 with app.test_request_context():284 f = open(os.path.join(app.root_path, 'static/index.html'))285 rv = flask.send_file(f)286 assert rv.mimetype == 'text/html'5 unmodified lines292 assert len(captured) == 2293 294 app.use_x_sendfile = False295 with app.test_request_context():298- with catch_warnings() as captured:296+ with catch_deprecation_warnings() as captured:297 f = StringIO('Test')298 rv = flask.send_file(f)299 rv.direct_passthrough = False300 assert rv.data == b'Test'301 assert rv.mimetype == 'application/octet-stream'302 rv.close()303 # etags304 assert len(captured) == 1307- with catch_warnings() as captured:305+ with catch_deprecation_warnings() as captured:306 class PyStringIO(object):307 def __init__(self, *args, **kwargs):308 self._io = StringIO(*args, **kwargs)309 def __getattr__(self, name):6 unmodified lines316 assert rv.mimetype == 'text/plain'317 rv.close()318 # attachment_filename and etags319 assert len(captured) == 3322- with catch_warnings() as captured:320+ with catch_deprecation_warnings() as captured:321 f = StringIO('Test')322 rv = flask.send_file(f, mimetype='text/plain')323 rv.direct_passthrough = False324 assert rv.data == b'Test'2 unmodified lines327 # etags328 assert len(captured) == 1329 330 app.use_x_sendfile = True333- with catch_warnings() as captured:331+ with catch_deprecation_warnings() as captured:332 with app.test_request_context():333 f = StringIO('Test')334 rv = flask.send_file(f)335 assert 'x-sendfile' not in rv.headers336 rv.close()337 # etags338 assert len(captured) == 1339 342- def test_attachment(self):340+ def test_attachment(self, catch_deprecation_warnings):341 app = flask.Flask(__name__)344- with catch_warnings() as captured:342+ with catch_deprecation_warnings() as captured:343 with app.test_request_context():344 f = open(os.path.join(app.root_path, 'static/index.html'))345 rv = flask.send_file(f, as_attachment=True)346 value, options = parse_options_header(rv.headers['Content-Disposition'])83 unmodified lines430 assert logger1.name == __name__431 app.logger_name = __name__ + '/test_logger_cache'432 assert app.logger is not logger1433 436- def test_debug_log(self):434+ def test_debug_log(self, capsys):435 app = flask.Flask(__name__)436 app.debug = True437 438 @app.route('/')6 unmodified lines445 def exc():446 1 // 0447 448 with app.test_client() as c:451- with catch_stderr() as err:452- c.get('/')453- out = err.getvalue()454- assert 'WARNING in test_helpers [' in out455- assert os.path.basename(__file__.rsplit('.', 1)[0] + '.py') in out456- assert 'the standard library is dead' in out457- assert 'this is a debug statement' in out449+ c.get('/')450+ out, err = capsys.readouterr()451+ assert 'WARNING in test_helpers [' in err452+ assert os.path.basename(__file__.rsplit('.', 1)[0] + '.py') in err453+ assert 'the standard library is dead' in err454+ assert 'this is a debug statement' in err455 459- with catch_stderr() as err:460- try:461- c.get('/exc')462- except ZeroDivisionError:463- pass464- else:465- assert False, 'debug log ate the exception'456+ with pytest.raises(ZeroDivisionError):457+ c.get('/exc')458 459 def test_debug_log_override(self):460 app = flask.Flask(__name__)461 app.debug = True175 unmodified linesmodified:tests/test_instance_config.py+9 added-7 removed
117 unmodified lines118 del sys.modules['site_egg']119 120 121 @pytest.mark.skipif(not PY2, reason='This only works under Python 2.')122-def test_meta_path_loader_without_is_package():122+def test_meta_path_loader_without_is_package(request, modules_tmpdir):123+ app = modules_tmpdir.join('unimportable.py')124+ app.write('import flask\napp = flask.Flask(__name__)')125+126 class Loader(object):124- def find_module(self, name):127+ def find_module(self, name, path=None):128 return self129 130 sys.meta_path.append(Loader())128- try:129- with pytest.raises(AttributeError):130- flask.Flask(__name__)131- finally:132- sys.meta_path.pop()131+ request.addfinalizer(sys.meta_path.pop)132+133+ with pytest.raises(AttributeError):134+ import unimportable