Home / Class/ TestStreaming Class — flask Architecture

TestStreaming Class — flask Architecture

Architecture documentation for the TestStreaming class in test_helpers.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  76c30621_3053_d7e5_0aa1_daf0facdcd3e["TestStreaming"]
  d5d22f74_a243_4ea9_9dfe_aaec71d26288["test_helpers.py"]
  76c30621_3053_d7e5_0aa1_daf0facdcd3e -->|defined in| d5d22f74_a243_4ea9_9dfe_aaec71d26288
  a4f8079d_ce69_8fd8_a3b0_6df9f6625194["test_streaming_with_context()"]
  76c30621_3053_d7e5_0aa1_daf0facdcd3e -->|method| a4f8079d_ce69_8fd8_a3b0_6df9f6625194
  cd82b66d_9bf2_aa4d_a1f9_a0c7b030b16c["test_streaming_with_context_as_decorator()"]
  76c30621_3053_d7e5_0aa1_daf0facdcd3e -->|method| cd82b66d_9bf2_aa4d_a1f9_a0c7b030b16c
  ab1fcaf7_105a_6929_1302_ada274415208["test_streaming_with_context_and_custom_close()"]
  76c30621_3053_d7e5_0aa1_daf0facdcd3e -->|method| ab1fcaf7_105a_6929_1302_ada274415208
  93e1b356_e2ec_8e37_17ea_d2c9877fd643["test_stream_keeps_session()"]
  76c30621_3053_d7e5_0aa1_daf0facdcd3e -->|method| 93e1b356_e2ec_8e37_17ea_d2c9877fd643
  8ab12aac_112d_9251_1183_9266c865cb37["test_async_view()"]
  76c30621_3053_d7e5_0aa1_daf0facdcd3e -->|method| 8ab12aac_112d_9251_1183_9266c865cb37

Relationship Graph

Source Code

tests/test_helpers.py lines 236–330

class TestStreaming:
    def test_streaming_with_context(self, app, client):
        @app.route("/")
        def index():
            def generate():
                yield "Hello "
                yield flask.request.args["name"]
                yield "!"

            return flask.Response(flask.stream_with_context(generate()))

        rv = client.get("/?name=World")
        assert rv.data == b"Hello World!"

    def test_streaming_with_context_as_decorator(self, app, client):
        @app.route("/")
        def index():
            @flask.stream_with_context
            def generate(hello):
                yield hello
                yield flask.request.args["name"]
                yield "!"

            return flask.Response(generate("Hello "))

        rv = client.get("/?name=World")
        assert rv.data == b"Hello World!"

    def test_streaming_with_context_and_custom_close(self, app, client):
        called = []

        class Wrapper:
            def __init__(self, gen):
                self._gen = gen

            def __iter__(self):
                return self

            def close(self):
                called.append(42)

            def __next__(self):
                return next(self._gen)

            next = __next__

        @app.route("/")
        def index():
            def generate():
                yield "Hello "
                yield flask.request.args["name"]
                yield "!"

            return flask.Response(flask.stream_with_context(Wrapper(generate())))

        rv = client.get("/?name=World")
        assert rv.data == b"Hello World!"
        assert called == [42]

    def test_stream_keeps_session(self, app, client):
        @app.route("/")
        def index():
            flask.session["test"] = "flask"

            @flask.stream_with_context
            def gen():
                yield flask.session["test"]

            return flask.Response(gen())

        rv = client.get("/")
        assert rv.data == b"flask"

    def test_async_view(self, app, client):
        @app.route("/")
        async def index():
            flask.session["test"] = "flask"

            @flask.stream_with_context
            def gen():
                yield flask.session["test"]

Frequently Asked Questions

What is the TestStreaming class?
TestStreaming is a class in the flask codebase, defined in tests/test_helpers.py.
Where is TestStreaming defined?
TestStreaming is defined in tests/test_helpers.py at line 236.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free