Skip to content
Myr

test_regression.py

This file

Path

tests/test_regression.py

98 lines · 2.3 KiB · Python

Last changed by

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

History of this file

Take it

The walk stopped after 200 commits: lines older than c74f469 point at it.

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 1–7why, one step back
1# -*- coding: utf-8 -*-
2"""3 tests.regression4 ~~~~~~~~~~~~~~~~~~~~~~~~~~56 Tests regressions.7

Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c

line 8why, one step back
8 :copyright: © 2010 by the Pallets team.

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 9–33why, one step back
9 :license: BSD, see LICENSE for more details.
10"""1112import gc13import sys14import threading1516import pytest17from werkzeug.exceptions import NotFound1819import flask2021_gc_lock = threading.Lock()222324class assert_no_leak(object):25 def __enter__(self):26 gc.disable()27 _gc_lock.acquire()28 loc = flask._request_ctx_stack._local2930 # Force Python to track this dictionary at all times.31 # This is necessary since Python only starts tracking32 # dicts if they contain mutable objects. It's a horrible,33 # horrible hack but makes this kinda testable.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 34why, one step back
34 loc.__storage__["FOOO"] = [1, 2, 3]

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 35–42why, one step back
35
36 gc.collect()37 self.old_objects = len(gc.get_objects())3839 def __exit__(self, exc_type, exc_value, tb):40 gc.collect()41 new_objects = len(gc.get_objects())42 if new_objects > self.old_objects:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 43why, one step back
43 pytest.fail("Example code leaked")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 44–50why, one step back
44 _gc_lock.release()
45 gc.enable()464748def test_memory_consumption():49 app = flask.Flask(__name__)50

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 51why, one step back
51 @app.route("/")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 52why, one step back
52 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 53why, one step back
53 return flask.render_template("simple_template.html", whiskey=42)

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 54–56why, one step back
54
55 def fire():56 with app.test_client() as c:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 57why, one step back
57 rv = c.get("/")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 58why, one step back
58 assert rv.status_code == 200

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 59why, one step back
59 assert rv.data == b"<h1>42</h1>"

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 60–64why, one step back
60
61 # Trigger caches62 fire()6364 # This test only works on CPython 2.7.

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 65why, one step back
65 if sys.version_info >= (2, 7) and not hasattr(sys, "pypy_translation_info"):

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 66–72why, one step back
66 with assert_no_leak():
67 for x in range(10):68 fire()697071def test_safe_join_toplevel_pardir():72 from flask.helpers import safe_join

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 73why, one step back
73

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 74why, one step back
74 with pytest.raises(NotFound):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 75why, one step back
75 safe_join("/foo", "..")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 76–85why, one step back
76
7778def test_aborting(app):79 class Foo(Exception):80 whatever = 428182 @app.errorhandler(Foo)83 def handle_foo(e):84 return str(e.whatever)85

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 86why, one step back
86 @app.route("/")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 87why, one step back
87 def index():

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 88why, one step back
88 raise flask.abort(flask.redirect(flask.url_for("test")))

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

line 89why, one step back
89

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 90why, one step back
90 @app.route("/test")

Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469

lines 91–94why, one step back
91 def test():
92 raise Foo()9394 with app.test_client() as c:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 95–98why, one step back
95 rv = c.get("/")
96 assert rv.headers["Location"] == "http://localhost/test"97 rv = c.get("/test")98 assert rv.data == b"42"