File: test_exception_custom_html.py

package info (click to toggle)
markupsafe 3.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 424 kB
  • sloc: python: 580; ansic: 177; makefile: 16
file content (23 lines) | stat: -rw-r--r-- 530 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from __future__ import annotations

import pytest

from markupsafe import escape


class CustomHtmlThatRaises:
    def __html__(self) -> str:
        raise ValueError(123)


def test_exception_custom_html() -> None:
    """Checks whether exceptions in custom __html__ implementations are
    propagated correctly.

    There was a bug in the native implementation at some point:
    https://github.com/pallets/markupsafe/issues/108
    """
    obj = CustomHtmlThatRaises()

    with pytest.raises(ValueError):
        escape(obj)