summaryrefslogtreecommitdiffstats
path: root/tests/test_utils.py
blob: e1dc87e050bbd59d17f2965a576f0676ba249363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from typing import Sequence, Union

import pytest

from debputy.util import escape_shell


@pytest.mark.parametrize(
    "arg,expected",
    [
        ("foo bar", '"foo bar"'),
        ("a'b", r"""a\'b"""),
        ("foo=bar and baz", 'foo="bar and baz"'),
        ("--foo=bar and baz", '--foo="bar and baz"'),
        ("--foo with spaces=bar and baz", '"--foo with spaces=bar and baz"'),
    ],
)
def test_symlink_normalization(arg: Union[str, Sequence[str]], expected: str) -> None:
    actual = escape_shell(arg) if isinstance(arg, str) else escape_shell(*arg)
    assert actual == expected