Home / File/ test_converters.py — flask Source File

test_converters.py — flask Source File

Architecture documentation for test_converters.py, a python file in the flask codebase. 2 imports, 0 dependents.

File python ApplicationCore ExtensionRegistry 2 imports 2 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  007e113d_b6a4_380c_c8c6_bfe1084a255a["test_converters.py"]
  e2a72d84_5c89_bb0d_3a69_5d24eacd9d7c["werkzeug.routing"]
  007e113d_b6a4_380c_c8c6_bfe1084a255a --> e2a72d84_5c89_bb0d_3a69_5d24eacd9d7c
  8c762fc5_c0b6_0d4d_3889_896d80fbf225["flask"]
  007e113d_b6a4_380c_c8c6_bfe1084a255a --> 8c762fc5_c0b6_0d4d_3889_896d80fbf225
  style 007e113d_b6a4_380c_c8c6_bfe1084a255a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from werkzeug.routing import BaseConverter

from flask import request
from flask import session
from flask import url_for


def test_custom_converters(app, client):
    class ListConverter(BaseConverter):
        def to_python(self, value):
            return value.split(",")

        def to_url(self, value):
            base_to_url = super().to_url
            return ",".join(base_to_url(x) for x in value)

    app.url_map.converters["list"] = ListConverter

    @app.route("/<list:args>")
    def index(args):
        return "|".join(args)

    assert client.get("/1,2,3").data == b"1|2|3"

    with app.test_request_context():
        assert url_for("index", args=[4, 5, 6]) == "/4,5,6"


def test_context_available(app, client):
    class ContextConverter(BaseConverter):
        def to_python(self, value):
            assert request is not None
            assert session is not None
            return value

    app.url_map.converters["ctx"] = ContextConverter

    @app.get("/<ctx:name>")
    def index(name):
        return name

    assert client.get("/admin").data == b"admin"

Subdomains

Dependencies

  • flask
  • werkzeug.routing

Frequently Asked Questions

What does test_converters.py do?
test_converters.py is a source file in the flask codebase, written in python. It belongs to the ApplicationCore domain, ExtensionRegistry subdomain.
What functions are defined in test_converters.py?
test_converters.py defines 2 function(s): test_context_available, test_custom_converters.
What does test_converters.py depend on?
test_converters.py imports 2 module(s): flask, werkzeug.routing.
Where is test_converters.py in the architecture?
test_converters.py is located at tests/test_converters.py (domain: ApplicationCore, subdomain: ExtensionRegistry, directory: tests).

Analyze Your Own Codebase

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

Try Supermodel Free