Skip to content
Myr

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

1 file+43 added−53 removed

modified:tests/test_regression.py+43 added-53 removed
17 unmodified lines
18import threading19from werkzeug.exceptions import NotFound20212222_gc_lock = threading.Lock()232426class _NoLeakAsserter(object):25class assert_no_leak(object):2628 def __init__(self, testcase):29 self.testcase = testcase3027 def __enter__(self):28 gc.disable()29 _gc_lock.acquire()30 loc = flask._request_ctx_stack._local
11 unmodified lines
42 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()495051# 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.')59class TestMemory(object):55def test_memory_consumption():56 app = flask.Flask(__name__)5761 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)6164 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>'6767 @app.route('/')68 def index():69 return flask.render_template('simple_template.html', whiskey=42)68 # Trigger caches69 fire()7071 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()7777 # Trigger caches78 fire()7880 # 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()79def test_safe_join_toplevel_pardir():80 from flask.helpers import safe_join81 with pytest.raises(NotFound):82 safe_join('/foo', '..')8387 def test_safe_join_toplevel_pardir(self):88 from flask.helpers import safe_join89 with pytest.raises(NotFound):90 safe_join('/foo', '..')8485def test_aborting():86 class Foo(Exception):87 whatever = 4288 app = flask.Flask(__name__)89 app.testing = True9093class TestException(object):91 @app.errorhandler(Foo)92 def handle_foo(e):93 return str(e.whatever)9495 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')))98101 @app.errorhandler(Foo)102 def handle_foo(e):103 return str(e.whatever)99 @app.route('/test')100 def test():101 raise Foo()102105 @app.route('/')106 def index():107 raise flask.abort(flask.redirect(flask.url_for('test')))108109 @app.route('/test')110 def test():111 raise Foo()112113 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'