Skip to content
Myr

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

4 files+34 added−95 removed

deleted:tests/__init__.py-62 removed
1# -*- coding: utf-8 -*-2"""3 tests4 ~~~~~~~~~~~~~~~56 Tests Flask itself. The majority of Flask is already tested7 as part of Werkzeug.89 :copyright: (c) 2014 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""1213from __future__ import print_function1415import os16import sys17import warnings18from functools import update_wrapper19from contextlib import contextmanager20from flask._compat import StringIO212223@contextmanager24def 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)2829 filters = warnings.filters30 warnings.filters = filters[:]31 old_showwarning = warnings.showwarning32 log = []3334 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_showwarning424344@contextmanager45def 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_stderr535455def 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 lines
124def purge_module(request):125 def inner(name):126 request.addfinalizer(lambda: sys.modules.pop(name, None))127 return inner128129130@pytest.fixture131def 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 lines
12import pytest1314import os15import flask16import unittest16from logging import StreamHandler18from tests import catch_warnings, catch_stderr17from werkzeug.http import parse_cache_control_header, parse_options_header18from flask._compat import StringIO, text_type1920
242 unmodified lines
263 os.path.join(app.root_path, 'static/index.html')264 assert rv.mimetype == 'text/html'265 rv.close()266269 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 = False
4 unmodified lines
278 # mimetypes + etag279 assert len(captured) == 2280281 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 lines
292 assert len(captured) == 2293294 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 lines
316 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 lines
327 # etags328 assert len(captured) == 1329330 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) == 1339342 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 lines
430 assert logger1.name == __name__431 app.logger_name = __name__ + '/test_logger_cache'432 assert app.logger is not logger1433436 def test_debug_log(self):434 def test_debug_log(self, capsys):435 app = flask.Flask(__name__)436 app.debug = True437438 @app.route('/')
6 unmodified lines
445 def exc():446 1 // 0447448 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 err455459 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')458459 def test_debug_log_override(self):460 app = flask.Flask(__name__)461 app.debug = True
175 unmodified lines
modified:tests/test_instance_config.py+9 added-7 removed
117 unmodified lines
118 del sys.modules['site_egg']119120121@pytest.mark.skipif(not PY2, reason='This only works under Python 2.')122def test_meta_path_loader_without_is_package():122def 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__)')125126 class Loader(object):124 def find_module(self, name):127 def find_module(self, name, path=None):128 return self129130 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)132133 with pytest.raises(AttributeError):134 import unimportable