Home / File/ test_user_error_handler.py — flask Source File

test_user_error_handler.py — flask Source File

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

File python ApplicationCore ExtensionRegistry 3 imports 5 functions 8 classes

Entity Profile

Dependency Diagram

graph LR
  f3be1606_1a20_1a1b_2703_48b5b295bc8d["test_user_error_handler.py"]
  da94d511_b8b8_a450_f67f_fc28ea9b648a["pytest"]
  f3be1606_1a20_1a1b_2703_48b5b295bc8d --> da94d511_b8b8_a450_f67f_fc28ea9b648a
  9b468bc7_cc0b_fef2_ed71_07b4f027fb55["werkzeug.exceptions"]
  f3be1606_1a20_1a1b_2703_48b5b295bc8d --> 9b468bc7_cc0b_fef2_ed71_07b4f027fb55
  8c762fc5_c0b6_0d4d_3889_896d80fbf225["flask"]
  f3be1606_1a20_1a1b_2703_48b5b295bc8d --> 8c762fc5_c0b6_0d4d_3889_896d80fbf225
  style f3be1606_1a20_1a1b_2703_48b5b295bc8d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import pytest
from werkzeug.exceptions import Forbidden
from werkzeug.exceptions import HTTPException
from werkzeug.exceptions import InternalServerError
from werkzeug.exceptions import NotFound

import flask


def test_error_handler_no_match(app, client):
    class CustomException(Exception):
        pass

    @app.errorhandler(CustomException)
    def custom_exception_handler(e):
        assert isinstance(e, CustomException)
        return "custom"

    with pytest.raises(TypeError) as exc_info:
        app.register_error_handler(CustomException(), None)

    assert "CustomException() is an instance, not a class." in str(exc_info.value)

    with pytest.raises(ValueError) as exc_info:
        app.register_error_handler(list, None)

    assert "'list' is not a subclass of Exception." in str(exc_info.value)

    @app.errorhandler(500)
    def handle_500(e):
        assert isinstance(e, InternalServerError)

        if e.original_exception is not None:
            return f"wrapped {type(e.original_exception).__name__}"

        return "direct"

    with pytest.raises(ValueError) as exc_info:
        app.register_error_handler(999, None)

    assert "Use a subclass of HTTPException" in str(exc_info.value)

    @app.route("/custom")
    def custom_test():
        raise CustomException()

    @app.route("/keyerror")
    def key_error():
        raise KeyError()

    @app.route("/abort")
    def do_abort():
        flask.abort(500)

    app.testing = False
    assert client.get("/custom").data == b"custom"
    assert client.get("/keyerror").data == b"wrapped KeyError"
    assert client.get("/abort").data == b"direct"


// ... (236 more lines)

Subdomains

Dependencies

  • flask
  • pytest
  • werkzeug.exceptions

Frequently Asked Questions

What does test_user_error_handler.py do?
test_user_error_handler.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_user_error_handler.py?
test_user_error_handler.py defines 5 function(s): test_default_error_handler, test_error_handler_blueprint, test_error_handler_http_subclass, test_error_handler_no_match, test_error_handler_subclass.
What does test_user_error_handler.py depend on?
test_user_error_handler.py imports 3 module(s): flask, pytest, werkzeug.exceptions.
Where is test_user_error_handler.py in the architecture?
test_user_error_handler.py is located at tests/test_user_error_handler.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