1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
import pytest
from litestar.utils.path import join_paths, normalize_path
@pytest.mark.parametrize(
"base,fragment, expected",
(
("/path/", "sub", "/path/sub"),
("/path/", "/sub/", "/path/sub"),
("path/", "sub", "/path/sub"),
("path", "sub", "/path/sub"),
("/path/", "sub/", "/path/sub"),
("path/", "sub/", "/path/sub"),
("path", "sub/", "/path/sub"),
("/", "/root/sub", "/root/sub"),
),
)
def test_join_url_fragments(base: str, fragment: str, expected: str) -> None:
assert join_paths([base, fragment]) == expected
def test_join_empty_list() -> None:
assert join_paths([]) == "/"
def test_join_single() -> None:
assert join_paths([""]) == "/"
assert join_paths(["/"]) == "/"
assert join_paths(["root"]) == "/root"
assert join_paths(["root//other"]) == "/root/other"
@pytest.mark.parametrize(
"base,expected",
[
("", "/"),
("/path", "/path"),
("path/", "/path"),
("path", "/path"),
("path////path", "/path/path"),
("path//", "/path"),
("///", "/"),
],
)
def test_normalize_path(base: str, expected: str) -> None:
assert normalize_path(base) == expected
|