forked from tox-dev/tox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_replace_posargs.py
84 lines (65 loc) · 2.5 KB
/
test_replace_posargs.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from __future__ import annotations
import sys
import pytest
from tests.config.loader.ini.replace.conftest import ReplaceOne
@pytest.mark.parametrize("syntax", ["{posargs}", "[]"])
def test_replace_pos_args_none_sys_argv(syntax: str, replace_one: ReplaceOne) -> None:
result = replace_one(syntax, None)
assert result == ""
@pytest.mark.parametrize("syntax", ["{posargs}", "[]"])
def test_replace_pos_args_empty_sys_argv(syntax: str, replace_one: ReplaceOne) -> None:
result = replace_one(syntax, [])
assert result == ""
@pytest.mark.parametrize("syntax", ["{posargs}", "[]"])
def test_replace_pos_args_extra_sys_argv(syntax: str, replace_one: ReplaceOne) -> None:
result = replace_one(syntax, [sys.executable, "magic"])
assert result == f"{sys.executable} magic"
@pytest.mark.parametrize("syntax", ["{posargs}", "[]"])
def test_replace_pos_args(syntax: str, replace_one: ReplaceOne) -> None:
result = replace_one(syntax, ["ok", "what", " yes "])
quote = '"' if sys.platform == "win32" else "'"
assert result == f"ok what {quote} yes {quote}"
@pytest.mark.parametrize(
("value", "result"),
[
("magic", "magic"),
("magic:colon", "magic:colon"),
("magic\n b c", "magic\nb c"), # an unescaped newline keeps the newline
("magi\\\n c d", "magic d"), # an escaped newline merges the lines
("\\{a\\}", "{a}"), # escaped curly braces
],
)
def test_replace_pos_args_default(replace_one: ReplaceOne, value: str, result: str) -> None:
outcome = replace_one(f"{{posargs:{value}}}", None)
assert result == outcome
@pytest.mark.parametrize(
"value",
[
"\\{posargs}",
"{posargs\\}",
"\\{posargs\\}",
"{\\{posargs}",
"{\\{posargs}{}",
"\\[]",
"[\\]",
"\\[\\]",
],
)
def test_replace_pos_args_escaped(replace_one: ReplaceOne, value: str) -> None:
result = replace_one(value, None)
outcome = value.replace("\\", "")
assert result == outcome
@pytest.mark.parametrize(
("value", "result"),
[
("[]-{posargs}", "foo-foo"),
("{posargs}-[]", "foo-foo"),
],
)
def test_replace_mixed_brackets_and_braces(replace_one: ReplaceOne, value: str, result: str) -> None:
outcome = replace_one(value, ["foo"])
assert result == outcome
def test_half_escaped_braces(replace_one: ReplaceOne) -> None:
"""See https://github.com/tox-dev/tox/issues/1956"""
outcome = replace_one(r"\{posargs} {posargs}", ["foo"])
assert "{posargs} foo" == outcome