|
|
|
@ -19,14 +19,10 @@ import threading
|
|
|
|
|
from werkzeug.exceptions import NotFound |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_gc_lock = threading.Lock() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _NoLeakAsserter(object): |
|
|
|
|
|
|
|
|
|
def __init__(self, testcase): |
|
|
|
|
self.testcase = testcase |
|
|
|
|
class assert_no_leak(object): |
|
|
|
|
|
|
|
|
|
def __enter__(self): |
|
|
|
|
gc.disable() |
|
|
|
@ -47,7 +43,7 @@ class _NoLeakAsserter(object):
|
|
|
|
|
gc.collect() |
|
|
|
|
new_objects = len(gc.get_objects()) |
|
|
|
|
if new_objects > self.old_objects: |
|
|
|
|
self.testcase.fail('Example code leaked') |
|
|
|
|
pytest.fail('Example code leaked') |
|
|
|
|
_gc_lock.release() |
|
|
|
|
gc.enable() |
|
|
|
|
|
|
|
|
@ -56,12 +52,7 @@ class _NoLeakAsserter(object):
|
|
|
|
|
# ported Flask to Python 3. |
|
|
|
|
@pytest.mark.skipif(os.environ.get('RUN_FLASK_MEMORY_TESTS') != '1', |
|
|
|
|
reason='Turned off due to envvar.') |
|
|
|
|
class TestMemory(object): |
|
|
|
|
|
|
|
|
|
def assert_no_leak(self): |
|
|
|
|
return _NoLeakAsserter(self) |
|
|
|
|
|
|
|
|
|
def test_memory_consumption(self): |
|
|
|
|
def test_memory_consumption(): |
|
|
|
|
app = flask.Flask(__name__) |
|
|
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
@ -80,19 +71,18 @@ class TestMemory(object):
|
|
|
|
|
# This test only works on CPython 2.7. |
|
|
|
|
if sys.version_info >= (2, 7) and \ |
|
|
|
|
not hasattr(sys, 'pypy_translation_info'): |
|
|
|
|
with self.assert_no_leak(): |
|
|
|
|
with assert_no_leak(): |
|
|
|
|
for x in range(10): |
|
|
|
|
fire() |
|
|
|
|
|
|
|
|
|
def test_safe_join_toplevel_pardir(self): |
|
|
|
|
|
|
|
|
|
def test_safe_join_toplevel_pardir(): |
|
|
|
|
from flask.helpers import safe_join |
|
|
|
|
with pytest.raises(NotFound): |
|
|
|
|
safe_join('/foo', '..') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestException(object): |
|
|
|
|
|
|
|
|
|
def test_aborting(self): |
|
|
|
|
def test_aborting(): |
|
|
|
|
class Foo(Exception): |
|
|
|
|
whatever = 42 |
|
|
|
|
app = flask.Flask(__name__) |
|
|
|
|