Download flask_debugtoolbar/tests/test_utils.py from Dorothydu/gitrepo_top_sample_50: direct link, hf CLI and curl.
- Browser
- Download file 4.46 kB
-
https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/flask_debugtoolbar/tests/test_utils.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_top_sample_50/flask_debugtoolbar/tests/test_utils.py
-
curl -L -o test_utils.py https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/flask_debugtoolbar/tests/test_utils.py
4.46 kB
| from __future__ import annotations | |
| import ntpath | |
| import posixpath | |
| from types import ModuleType | |
| import pytest | |
| from markupsafe import escape | |
| from markupsafe import Markup | |
| from flask_debugtoolbar.utils import _relative_paths | |
| from flask_debugtoolbar.utils import _shortest_relative_path | |
| from flask_debugtoolbar.utils import decode_text | |
| from flask_debugtoolbar.utils import format_sql | |
| from flask_debugtoolbar.utils import HAVE_PYGMENTS | |
| def test_relative_paths( | |
| value: str, paths: list[str], expected: list[str], path_module: ModuleType | |
| ) -> None: | |
| assert list(_relative_paths(value, paths, path_module)) == expected | |
| def test_shortest_relative_path( | |
| value: str, paths: list[str], expected: str, path_module: ModuleType | |
| ) -> None: | |
| assert _shortest_relative_path(value, paths, path_module) == expected | |
| def test_decode_text_unicode() -> None: | |
| value = "\uffff" | |
| decoded = decode_text(value) | |
| assert decoded == value | |
| def test_decode_text_ascii() -> None: | |
| value = "abc" | |
| assert decode_text(value.encode("ascii")) == value | |
| def test_decode_text_non_ascii() -> None: | |
| value = b"abc \xff xyz" | |
| assert isinstance(value, bytes) | |
| decoded = decode_text(value) | |
| assert not isinstance(decoded, bytes) | |
| assert decoded.startswith("abc") | |
| assert decoded.endswith("xyz") | |
| def no_pygments(monkeypatch: pytest.MonkeyPatch) -> None: | |
| monkeypatch.setattr("flask_debugtoolbar.utils.HAVE_PYGMENTS", False) | |
| def test_format_sql_no_pygments() -> None: | |
| sql = "select 1" | |
| assert format_sql(sql, {}) == sql | |
| def test_format_sql_no_pygments_non_ascii() -> None: | |
| sql = b"select '\xff'" | |
| formatted = format_sql(sql, {}) | |
| assert formatted.startswith("select '") | |
| def test_format_sql_no_pygments_escape_html() -> None: | |
| sql = "select x < 1" | |
| formatted = format_sql(sql, {}) | |
| assert not isinstance(formatted, Markup) | |
| assert escape(formatted) == "select x < 1" | |
| def test_format_sql_pygments() -> None: | |
| sql = "select 1" | |
| html = format_sql(sql, {}) | |
| assert isinstance(html, Markup) | |
| assert html.startswith("<div") | |
| assert "select" in html | |
| assert "1" in html | |
| def test_format_sql_pygments_non_ascii() -> None: | |
| sql = b"select 'abc \xff xyz'" | |
| html = format_sql(sql, {}) | |
| assert isinstance(html, Markup) | |
| assert html.startswith("<div") | |
| assert "select" in html | |
| assert "abc" in html | |
| assert "xyz" in html | |