Kill classes in test_regression
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 f8a778d · Browse files · 1 file·+43 added−53 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+43 added−53 removed
- tests:+43 added−53 removed
Provenance
- Commit
71dae37- Tree
db35204- Author
Markus Unterwaditzer <markus@unterwaditzer.net>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
f8a778d
1 file changed+43 added−53 removed
modified:tests/test_regression.py+43 added-53 removed
17 unmodified lines18 import threading19 from werkzeug.exceptions import NotFound20 21 22-22 _gc_lock = threading.Lock()23 24 26-class _NoLeakAsserter(object):25+class assert_no_leak(object):26 28- def __init__(self, testcase):29- self.testcase = testcase30-27 def __enter__(self):28 gc.disable()29 _gc_lock.acquire()30 loc = flask._request_ctx_stack._local11 unmodified lines42 if not hasattr(sys, 'getrefcount'):43 gc.collect()44 new_objects = len(gc.get_objects())45 if new_objects > self.old_objects:50- self.testcase.fail('Example code leaked')46+ pytest.fail('Example code leaked')47 _gc_lock.release()48 gc.enable()49 50 51 # XXX: untitaker: These tests need to be revised. They broke around the time we52 # ported Flask to Python 3.53 @pytest.mark.skipif(os.environ.get('RUN_FLASK_MEMORY_TESTS') != '1',54 reason='Turned off due to envvar.')59-class TestMemory(object):55+def test_memory_consumption():56+ app = flask.Flask(__name__)57 61- def assert_no_leak(self):62- return _NoLeakAsserter(self)58+ @app.route('/')59+ def index():60+ return flask.render_template('simple_template.html', whiskey=42)61 64- def test_memory_consumption(self):65- app = flask.Flask(__name__)62+ def fire():63+ with app.test_client() as c:64+ rv = c.get('/')65+ assert rv.status_code == 20066+ assert rv.data == b'<h1>42</h1>'67 67- @app.route('/')68- def index():69- return flask.render_template('simple_template.html', whiskey=42)68+ # Trigger caches69+ fire()70 71- def fire():72- with app.test_client() as c:73- rv = c.get('/')74- assert rv.status_code == 20075- assert rv.data == b'<h1>42</h1>'71+ # This test only works on CPython 2.7.72+ if sys.version_info >= (2, 7) and \73+ not hasattr(sys, 'pypy_translation_info'):74+ with assert_no_leak():75+ for x in range(10):76+ fire()77 77- # Trigger caches78- fire()78 80- # This test only works on CPython 2.7.81- if sys.version_info >= (2, 7) and \82- not hasattr(sys, 'pypy_translation_info'):83- with self.assert_no_leak():84- for x in range(10):85- fire()79+def test_safe_join_toplevel_pardir():80+ from flask.helpers import safe_join81+ with pytest.raises(NotFound):82+ safe_join('/foo', '..')83 87- def test_safe_join_toplevel_pardir(self):88- from flask.helpers import safe_join89- with pytest.raises(NotFound):90- safe_join('/foo', '..')84 85+def test_aborting():86+ class Foo(Exception):87+ whatever = 4288+ app = flask.Flask(__name__)89+ app.testing = True90 93-class TestException(object):91+ @app.errorhandler(Foo)92+ def handle_foo(e):93+ return str(e.whatever)94 95- def test_aborting(self):96- class Foo(Exception):97- whatever = 4298- app = flask.Flask(__name__)99- app.testing = True95+ @app.route('/')96+ def index():97+ raise flask.abort(flask.redirect(flask.url_for('test')))98 101- @app.errorhandler(Foo)102- def handle_foo(e):103- return str(e.whatever)99+ @app.route('/test')100+ def test():101+ raise Foo()102 105- @app.route('/')106- def index():107- raise flask.abort(flask.redirect(flask.url_for('test')))108-109- @app.route('/test')110- def test():111- raise Foo()112-113- with app.test_client() as c:114- rv = c.get('/')115- assert rv.headers['Location'] == 'http://localhost/test'116- rv = c.get('/test')117- assert rv.data == b'42'103+ with app.test_client() as c:104+ rv = c.get('/')105+ assert rv.headers['Location'] == 'http://localhost/test'106+ rv = c.get('/test')107+ assert rv.data == b'42'