Added descriptive pytest.param IDs to all parametrized placeholder tests.
This commit is contained in:
+140
-116
@@ -80,30 +80,33 @@ class TestSimpleSubstitution:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,kwargs,expected",
|
"template,kwargs,expected",
|
||||||
[
|
[
|
||||||
("Just a plain message.", {}, "Just a plain message."),
|
pytest.param("Just a plain message.", {}, "Just a plain message.", id="plain-text"),
|
||||||
("", {}, ""),
|
pytest.param("", {}, "", id="empty-string"),
|
||||||
(" ", {}, " "),
|
pytest.param(" ", {}, " ", id="whitespace-only"),
|
||||||
(
|
pytest.param(
|
||||||
"Hello, $(user)! Welcome to the stream.",
|
"Hello, $(user)! Welcome to the stream.",
|
||||||
{},
|
{},
|
||||||
"Hello, Alice! Welcome to the stream.",
|
"Hello, Alice! Welcome to the stream.",
|
||||||
|
id="user-in-sentence",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"The hype train has been called $(count) times! HYPE!",
|
"The hype train has been called $(count) times! HYPE!",
|
||||||
{"use_count": 7},
|
{"use_count": 7},
|
||||||
"The hype train has been called 7 times! HYPE!",
|
"The hype train has been called 7 times! HYPE!",
|
||||||
|
id="count-in-sentence",
|
||||||
),
|
),
|
||||||
("$(count)", {"use_count": 0}, "0"),
|
pytest.param("$(count)", {"use_count": 0}, "0", id="count-zero"),
|
||||||
(
|
pytest.param(
|
||||||
"Go check out $(1)! They're awesome.",
|
"Go check out $(1)! They're awesome.",
|
||||||
{"args": ["Bob"]},
|
{"args": ["Bob"]},
|
||||||
"Go check out Bob! They're awesome.",
|
"Go check out Bob! They're awesome.",
|
||||||
|
id="arg-in-sentence",
|
||||||
),
|
),
|
||||||
("$(user)", {}, "Alice"),
|
pytest.param("$(user)", {}, "Alice", id="user-only"),
|
||||||
("$(1)$(2)$(3)", {"args": ["a", "b", "c"]}, "abc"),
|
pytest.param("$(1)$(2)$(3)", {"args": ["a", "b", "c"]}, "abc", id="three-args-adjacent"),
|
||||||
("$(user) likes $(1)", {"args": ["cats"]}, "Alice likes cats"),
|
pytest.param("$(user) likes $(1)", {"args": ["cats"]}, "Alice likes cats", id="user-and-arg"),
|
||||||
("Hello $(user)!", {"user": "O'Brien [MOD]"}, "Hello O'Brien [MOD]!"),
|
pytest.param("Hello $(user)!", {"user": "O'Brien [MOD]"}, "Hello O'Brien [MOD]!", id="special-chars-in-user"),
|
||||||
("$(1)", {"args": ["hello world & goodbye"]}, "hello world & goodbye"),
|
pytest.param("$(1)", {"args": ["hello world & goodbye"]}, "hello world & goodbye", id="special-chars-in-arg"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_substitution(self, template, kwargs, expected):
|
async def test_substitution(self, template, kwargs, expected):
|
||||||
@@ -129,15 +132,16 @@ class TestArgPlaceholders:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,args,expected",
|
"template,args,expected",
|
||||||
[
|
[
|
||||||
(
|
pytest.param(
|
||||||
"$(1)$(2)$(3)$(4)$(5)$(6)$(7)$(8)$(9)",
|
"$(1)$(2)$(3)$(4)$(5)$(6)$(7)$(8)$(9)",
|
||||||
["a", "b", "c", "d", "e", "f", "g", "h", "i"],
|
["a", "b", "c", "d", "e", "f", "g", "h", "i"],
|
||||||
"abcdefghi",
|
"abcdefghi",
|
||||||
|
id="all-nine-args",
|
||||||
),
|
),
|
||||||
("Hello $(1) and $(2)", ["Alice"], "Hello Alice and "),
|
pytest.param("Hello $(1) and $(2)", ["Alice"], "Hello Alice and ", id="missing-arg-empty"),
|
||||||
("[$(1)] [$(2)] [$(3)]", [], "[] [] []"),
|
pytest.param("[$(1)] [$(2)] [$(3)]", [], "[] [] []", id="all-args-empty"),
|
||||||
("$(1)", [""], ""),
|
pytest.param("$(1)", [""], "", id="empty-string-arg"),
|
||||||
("Hello $(1)world", [""], "Hello world"),
|
pytest.param("Hello $(1)world", [""], "Hello world", id="empty-arg-adjacent-text"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_arg_substitution(self, template, args, expected):
|
async def test_arg_substitution(self, template, args, expected):
|
||||||
@@ -147,9 +151,9 @@ class TestArgPlaceholders:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,args,expected",
|
"template,args,expected",
|
||||||
[
|
[
|
||||||
("$(0)", ["first"], "$(0)"),
|
pytest.param("$(0)", ["first"], "$(0)", id="index-zero"),
|
||||||
("$(10)", ["a"] * 10, "$(10)"),
|
pytest.param("$(10)", ["a"] * 10, "$(10)", id="index-ten"),
|
||||||
("$(99)", [], "$(99)"),
|
pytest.param("$(99)", [], "$(99)", id="index-ninety-nine"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_invalid_arg_index_passthrough(self, template, args, expected):
|
async def test_invalid_arg_index_passthrough(self, template, args, expected):
|
||||||
@@ -160,8 +164,8 @@ class TestArgPlaceholders:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,args,expected",
|
"template,args,expected",
|
||||||
[
|
[
|
||||||
("$(1 extra)", ["hello"], "Invalid $(1): does not accept arguments"),
|
pytest.param("$(1 extra)", ["hello"], "Invalid $(1): does not accept arguments", id="arg1-with-extra"),
|
||||||
("$(9 extra)", [], "Invalid $(9): does not accept arguments"),
|
pytest.param("$(9 extra)", [], "Invalid $(9): does not accept arguments", id="arg9-with-extra"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_arg_extra_args_error(self, template, args, expected):
|
async def test_arg_extra_args_error(self, template, args, expected):
|
||||||
@@ -202,17 +206,18 @@ class TestNamedCounters:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"counter_values,template,expected,db_name,db_value",
|
"counter_values,template,expected,db_name,db_value",
|
||||||
[
|
[
|
||||||
(
|
pytest.param(
|
||||||
{"deaths": 10},
|
{"deaths": 10},
|
||||||
"$(count deaths 0) deaths. Counter reset!",
|
"$(count deaths 0) deaths. Counter reset!",
|
||||||
"0 deaths. Counter reset!",
|
"0 deaths. Counter reset!",
|
||||||
"deaths",
|
"deaths",
|
||||||
0,
|
0,
|
||||||
|
id="reset-to-zero",
|
||||||
),
|
),
|
||||||
({}, "$(count score 5)", "5", "score", 5),
|
pytest.param({}, "$(count score 5)", "5", "score", 5, id="set-absolute"),
|
||||||
({"x": 7}, "$(count x +0)", "7", "x", 7),
|
pytest.param({"x": 7}, "$(count x +0)", "7", "x", 7, id="plus-zero"),
|
||||||
({"x": 7}, "$(count x -0)", "7", "x", 7),
|
pytest.param({"x": 7}, "$(count x -0)", "7", "x", 7, id="minus-zero"),
|
||||||
({"x": 0}, "$(count x -1)", "-1", "x", -1),
|
pytest.param({"x": 0}, "$(count x -1)", "-1", "x", -1, id="negative-result"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_count_with_db_check(
|
async def test_count_with_db_check(
|
||||||
@@ -230,10 +235,10 @@ class TestNamedCounters:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"counter_values,template,expected",
|
"counter_values,template,expected",
|
||||||
[
|
[
|
||||||
({}, "$(count deaths +5)", "5"),
|
pytest.param({}, "$(count deaths +5)", "5", id="plus-five"),
|
||||||
({"lives": 3}, "$(count lives -1) lives remaining", "2 lives remaining"),
|
pytest.param({"lives": 3}, "$(count lives -1) lives remaining", "2 lives remaining", id="decrement"),
|
||||||
({}, "$(getcount missing)", "0"),
|
pytest.param({}, "$(getcount missing)", "0", id="getcount-missing"),
|
||||||
({}, "$(count boss_2_kills)", "1"),
|
pytest.param({}, "$(count boss_2_kills)", "1", id="underscore-in-name"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_count_simple(self, counter_values, template, expected):
|
async def test_count_simple(self, counter_values, template, expected):
|
||||||
@@ -295,7 +300,10 @@ class TestNamedCounters:
|
|||||||
)
|
)
|
||||||
assert result == "42 -> 42"
|
assert result == "42 -> 42"
|
||||||
|
|
||||||
@pytest.mark.parametrize("sign", ["+", "-"])
|
@pytest.mark.parametrize("sign", [
|
||||||
|
pytest.param("+", id="plus"),
|
||||||
|
pytest.param("-", id="minus"),
|
||||||
|
])
|
||||||
async def test_bare_sign_rejected(self, sign):
|
async def test_bare_sign_rejected(self, sign):
|
||||||
"""$(count x +) and $(count x -) report an error."""
|
"""$(count x +) and $(count x -) report an error."""
|
||||||
result = await process(f"$(count x {sign})")
|
result = await process(f"$(count x {sign})")
|
||||||
@@ -310,8 +318,8 @@ class TestCounterNameValidation:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,expected,db_name,db_value",
|
"template,expected,db_name,db_value",
|
||||||
[
|
[
|
||||||
("$(count Deaths)", "1", "deaths", 1),
|
pytest.param("$(count Deaths)", "1", "deaths", 1, id="uppercase-name"),
|
||||||
("$(count 123)", "1", "123", 1),
|
pytest.param("$(count 123)", "1", "123", 1, id="numeric-name"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_count_name_normalized(self, template, expected, db_name, db_value):
|
async def test_count_name_normalized(self, template, expected, db_name, db_value):
|
||||||
@@ -324,7 +332,12 @@ class TestCounterNameValidation:
|
|||||||
)
|
)
|
||||||
assert row["value"] == db_value
|
assert row["value"] == db_value
|
||||||
|
|
||||||
@pytest.mark.parametrize("name", ["boss-kills", "boss.kills", "+5", "-3"])
|
@pytest.mark.parametrize("name", [
|
||||||
|
pytest.param("boss-kills", id="hyphen"),
|
||||||
|
pytest.param("boss.kills", id="dot"),
|
||||||
|
pytest.param("+5", id="leading-plus"),
|
||||||
|
pytest.param("-3", id="leading-minus"),
|
||||||
|
])
|
||||||
async def test_count_invalid_name_rejected(self, name):
|
async def test_count_invalid_name_rejected(self, name):
|
||||||
"""Names with hyphens, dots, or leading +/- are rejected."""
|
"""Names with hyphens, dots, or leading +/- are rejected."""
|
||||||
result = await process(f"$(count {name})")
|
result = await process(f"$(count {name})")
|
||||||
@@ -369,9 +382,9 @@ class TestRand:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,expected",
|
"template,expected",
|
||||||
[
|
[
|
||||||
("$(rand 5 5)", "5"),
|
pytest.param("$(rand 5 5)", "5", id="equal-bounds"),
|
||||||
("$(rand 0 0)", "0"),
|
pytest.param("$(rand 0 0)", "0", id="zero-bounds"),
|
||||||
("$(rand 1 1)", "1"),
|
pytest.param("$(rand 1 1)", "1", id="extra-whitespace"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_rand_deterministic(self, template, expected):
|
async def test_rand_deterministic(self, template, expected):
|
||||||
@@ -436,9 +449,9 @@ class TestCountdownCountup:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template",
|
"template",
|
||||||
[
|
[
|
||||||
"$(countdown Jan 1 2000 12:00:00 AM UTC)",
|
pytest.param("$(countdown Jan 1 2000 12:00:00 AM UTC)", id="countdown-past"),
|
||||||
"$(countup Dec 25 2099 12:00:00 AM UTC)",
|
pytest.param("$(countup Dec 25 2099 12:00:00 AM UTC)", id="countup-future"),
|
||||||
"$(countdown Jan 1 2000 12:00:00 AM utc)",
|
pytest.param("$(countdown Jan 1 2000 12:00:00 AM utc)", id="lowercase-tz"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_zero_seconds(self, template):
|
async def test_zero_seconds(self, template):
|
||||||
@@ -448,11 +461,11 @@ class TestCountdownCountup:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"placeholder,bad_date",
|
"placeholder,bad_date",
|
||||||
[
|
[
|
||||||
("countdown", "not a real date"),
|
pytest.param("countdown", "not a real date", id="gibberish"),
|
||||||
("countdown", "monday"),
|
pytest.param("countdown", "monday", id="weekday-only"),
|
||||||
("countdown", "Dec 25 2099 12:00:00 AM XYZ"),
|
pytest.param("countdown", "Dec 25 2099 12:00:00 AM XYZ", id="unknown-tz"),
|
||||||
("countup", "not a real date"),
|
pytest.param("countup", "not a real date", id="countup-gibberish"),
|
||||||
("countdown", "not a valid date UTC"),
|
pytest.param("countdown", "not a valid date UTC", id="gibberish-with-tz"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_invalid_date(self, placeholder, bad_date):
|
async def test_invalid_date(self, placeholder, bad_date):
|
||||||
@@ -476,20 +489,20 @@ class TestCountdownCountup:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"seconds,expected",
|
"seconds,expected",
|
||||||
[
|
[
|
||||||
(0, "0 seconds"),
|
pytest.param(0, "0 seconds", id="zero"),
|
||||||
(1, "1 second"),
|
pytest.param(1, "1 second", id="one-second"),
|
||||||
(2, "2 seconds"),
|
pytest.param(2, "2 seconds", id="two-seconds"),
|
||||||
(60, "1 minute"),
|
pytest.param(60, "1 minute", id="one-minute"),
|
||||||
(120, "2 minutes"),
|
pytest.param(120, "2 minutes", id="two-minutes"),
|
||||||
(3600, "1 hour"),
|
pytest.param(3600, "1 hour", id="one-hour"),
|
||||||
(7200, "2 hours"),
|
pytest.param(7200, "2 hours", id="two-hours"),
|
||||||
(86400, "1 day"),
|
pytest.param(86400, "1 day", id="one-day"),
|
||||||
(172800, "2 days"),
|
pytest.param(172800, "2 days", id="two-days"),
|
||||||
(3601, "1 hour 1 second"),
|
pytest.param(3601, "1 hour 1 second", id="hour-and-second"),
|
||||||
(86401, "1 day 1 second"),
|
pytest.param(86401, "1 day 1 second", id="day-and-second"),
|
||||||
(86460, "1 day 1 minute"),
|
pytest.param(86460, "1 day 1 minute", id="day-and-minute"),
|
||||||
(90061, "1 day 1 hour 1 minute 1 second"),
|
pytest.param(90061, "1 day 1 hour 1 minute 1 second", id="all-units-singular"),
|
||||||
(180183, "2 days 2 hours 3 minutes 3 seconds"),
|
pytest.param(180183, "2 days 2 hours 3 minutes 3 seconds", id="all-units-plural"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_format_duration(self, seconds, expected):
|
async def test_format_duration(self, seconds, expected):
|
||||||
@@ -585,9 +598,9 @@ class TestNesting:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,args",
|
"template,args",
|
||||||
[
|
[
|
||||||
("$(rand $(1) $(2))", []),
|
pytest.param("$(rand $(1) $(2))", [], id="no-args"),
|
||||||
("$(rand $(1) $(2))", ["5"]),
|
pytest.param("$(rand $(1) $(2))", ["5"], id="one-arg"),
|
||||||
("$(rand $(1)$(2))", ["5", "10"]),
|
pytest.param("$(rand $(1)$(2))", ["5", "10"], id="no-space-between"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_nested_too_few_args(self, template, args):
|
async def test_nested_too_few_args(self, template, args):
|
||||||
@@ -609,23 +622,24 @@ class TestEscaping:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,kwargs,expected",
|
"template,kwargs,expected",
|
||||||
[
|
[
|
||||||
(
|
pytest.param(
|
||||||
r"Use \$(user) to insert your name.",
|
r"Use \$(user) to insert your name.",
|
||||||
{},
|
{},
|
||||||
"Use $(user) to insert your name.",
|
"Use $(user) to insert your name.",
|
||||||
|
id="escaped-user",
|
||||||
),
|
),
|
||||||
(r"\$(user) and \$(count)", {}, "$(user) and $(count)"),
|
pytest.param(r"\$(user) and \$(count)", {}, "$(user) and $(count)", id="two-escaped"),
|
||||||
(r"\$(user) said hello to $(user)", {}, "$(user) said hello to Alice"),
|
pytest.param(r"\$(user) said hello to $(user)", {}, "$(user) said hello to Alice", id="escaped-and-live"),
|
||||||
(r"path\to\file", {}, "path\\to\\file"),
|
pytest.param(r"path\to\file", {}, "path\\to\\file", id="backslash-in-text"),
|
||||||
("\\\\$(user)", {}, "\\$(user)"),
|
pytest.param("\\\\$(user)", {}, "\\$(user)", id="double-backslash"),
|
||||||
("before \\$(unclosed", {}, "before \\$(unclosed"),
|
pytest.param("before \\$(unclosed", {}, "before \\$(unclosed", id="escaped-unclosed"),
|
||||||
("\\$(rand $(1) $(2))", {"args": ["5", "10"]}, "$(rand $(1) $(2))"),
|
pytest.param("\\$(rand $(1) $(2))", {"args": ["5", "10"]}, "$(rand $(1) $(2))", id="escaped-nested"),
|
||||||
(r"\$()", {}, "$()"),
|
pytest.param(r"\$()", {}, "$()", id="escaped-empty-parens"),
|
||||||
("text \\$(", {}, "text \\$("),
|
pytest.param("text \\$(", {}, "text \\$(", id="trailing-escaped-dollar"),
|
||||||
(r"\$(rand 1)", {}, "$(rand 1)"),
|
pytest.param(r"\$(rand 1)", {}, "$(rand 1)", id="escaped-with-body"),
|
||||||
("hello\\", {}, "hello\\"),
|
pytest.param("hello\\", {}, "hello\\", id="trailing-backslash"),
|
||||||
("\\\\\\$(user)", {}, "\\\\$(user)"),
|
pytest.param("\\\\\\$(user)", {}, "\\\\$(user)", id="triple-backslash"),
|
||||||
("\\$5", {}, "\\$5"),
|
pytest.param("\\$5", {}, "\\$5", id="dollar-number"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_escaping(self, template, kwargs, expected):
|
async def test_escaping(self, template, kwargs, expected):
|
||||||
@@ -639,11 +653,11 @@ class TestCaseInsensitivity:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,kwargs,expected",
|
"template,kwargs,expected",
|
||||||
[
|
[
|
||||||
("$(USER)", {}, "Alice"),
|
pytest.param("$(USER)", {}, "Alice", id="all-upper-user"),
|
||||||
("$(User)", {}, "Alice"),
|
pytest.param("$(User)", {}, "Alice", id="title-case-user"),
|
||||||
("$(Rand 1 1)", {}, "1"),
|
pytest.param("$(Rand 1 1)", {}, "1", id="title-case-rand"),
|
||||||
("$(COUNT)", {"use_count": 5}, "5"),
|
pytest.param("$(COUNT)", {"use_count": 5}, "5", id="all-upper-count"),
|
||||||
("$(COUNTDOWN Jan 1 2000 12:00:00 AM UTC)", {}, "0 seconds"),
|
pytest.param("$(COUNTDOWN Jan 1 2000 12:00:00 AM UTC)", {}, "0 seconds", id="all-upper-countdown"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_placeholder_name_case_ignored(self, template, kwargs, expected):
|
async def test_placeholder_name_case_ignored(self, template, kwargs, expected):
|
||||||
@@ -733,20 +747,20 @@ class TestParserBoundaries:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,expected",
|
"template,expected",
|
||||||
[
|
[
|
||||||
("$(rand 1", "$(rand 1"),
|
pytest.param("$(rand 1", "$(rand 1", id="unclosed-rand"),
|
||||||
("before $(rand 1 after", "before $(rand 1 after"),
|
pytest.param("before $(rand 1 after", "before $(rand 1 after", id="unclosed-in-text"),
|
||||||
("$()", "$()"),
|
pytest.param("$()", "$()", id="empty-parens"),
|
||||||
("$", "$"),
|
pytest.param("$", "$", id="lone-dollar"),
|
||||||
("Price: $5", "Price: $5"),
|
pytest.param("Price: $5", "Price: $5", id="dollar-amount"),
|
||||||
("$x $y $z", "$x $y $z"),
|
pytest.param("$x $y $z", "$x $y $z", id="dollar-variables"),
|
||||||
("Hello :) world", "Hello :) world"),
|
pytest.param("Hello :) world", "Hello :) world", id="smiley-face"),
|
||||||
(":) :) :)", ":) :) :)"),
|
pytest.param(":) :) :)", ":) :) :)", id="multiple-smileys"),
|
||||||
("hello $(", "hello $("),
|
pytest.param("hello $(", "hello $(", id="trailing-dollar-paren"),
|
||||||
("hello $(user", "hello $(user"),
|
pytest.param("hello $(user", "hello $(user", id="unclosed-user"),
|
||||||
("$( )", "$( )"),
|
pytest.param("$( )", "$( )", id="space-only-parens"),
|
||||||
("$(rand$(user))", "$(randAlice)"),
|
pytest.param("$(rand$(user))", "$(randAlice)", id="no-space-after-name"),
|
||||||
("$(rand$5)", "$(rand$5)"),
|
pytest.param("$(rand$5)", "$(rand$5)", id="dollar-in-name"),
|
||||||
("$(rand$", "$(rand$"),
|
pytest.param("$(rand$", "$(rand$", id="trailing-dollar-in-name"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_parser_boundary(self, template, expected):
|
async def test_parser_boundary(self, template, expected):
|
||||||
@@ -760,12 +774,12 @@ class TestUnknownPlaceholders:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,expected",
|
"template,expected",
|
||||||
[
|
[
|
||||||
("$(madeup stuff)", "$(madeup stuff)"),
|
pytest.param("$(madeup stuff)", "$(madeup stuff)", id="with-args"),
|
||||||
("$(banana)", "$(banana)"),
|
pytest.param("$(banana)", "$(banana)", id="bare-name"),
|
||||||
("$(madeup lots of space)", "$(madeup lots of space)"),
|
pytest.param("$(madeup lots of space)", "$(madeup lots of space)", id="extra-spaces"),
|
||||||
("$(madeup)", "$(madeup)"),
|
pytest.param("$(madeup)", "$(madeup)", id="no-args"),
|
||||||
("$(café)", "$(café)"),
|
pytest.param("$(café)", "$(café)", id="unicode-name"),
|
||||||
("$(café latte)", "$(café latte)"),
|
pytest.param("$(café latte)", "$(café latte)", id="unicode-with-args"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_unknown_placeholder_passthrough(self, template, expected):
|
async def test_unknown_placeholder_passthrough(self, template, expected):
|
||||||
@@ -780,9 +794,9 @@ class TestEvaluationSafety:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,kwargs,expected",
|
"template,kwargs,expected",
|
||||||
[
|
[
|
||||||
("$(1)", {"args": ["$(user)"]}, "$(user)"),
|
pytest.param("$(1)", {"args": ["$(user)"]}, "$(user)", id="arg-contains-user"),
|
||||||
("$(1)", {"args": ["$(rand 1 100)"]}, "$(rand 1 100)"),
|
pytest.param("$(1)", {"args": ["$(rand 1 100)"]}, "$(rand 1 100)", id="arg-contains-rand"),
|
||||||
("$(user)", {"user": "$(rand 1 100)"}, "$(rand 1 100)"),
|
pytest.param("$(user)", {"user": "$(rand 1 100)"}, "$(rand 1 100)", id="user-contains-rand"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_resolved_text_not_reparsed(self, template, kwargs, expected):
|
async def test_resolved_text_not_reparsed(self, template, kwargs, expected):
|
||||||
@@ -807,50 +821,60 @@ class TestRuntimeErrors:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"template,expected_error",
|
"template,expected_error",
|
||||||
[
|
[
|
||||||
(
|
pytest.param(
|
||||||
"$(rand 1)",
|
"$(rand 1)",
|
||||||
"Invalid $(rand): too few arguments, expected $(rand start stop)",
|
"Invalid $(rand): too few arguments, expected $(rand start stop)",
|
||||||
|
id="rand-too-few",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(rand)",
|
"$(rand)",
|
||||||
"Invalid $(rand): too few arguments, expected $(rand start stop)",
|
"Invalid $(rand): too few arguments, expected $(rand start stop)",
|
||||||
|
id="rand-no-args",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(rand 1 2 3)",
|
"$(rand 1 2 3)",
|
||||||
"Invalid $(rand): too many arguments, expected $(rand start stop)",
|
"Invalid $(rand): too many arguments, expected $(rand start stop)",
|
||||||
|
id="rand-too-many",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(rand a b)",
|
"$(rand a b)",
|
||||||
"Invalid $(rand): arguments must be integers, e.g., $(rand 1 100)",
|
"Invalid $(rand): arguments must be integers, e.g., $(rand 1 100)",
|
||||||
|
id="rand-non-integer",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(rand 1.5 2.5)",
|
"$(rand 1.5 2.5)",
|
||||||
"Invalid $(rand): arguments must be integers, e.g., $(rand 1 100)",
|
"Invalid $(rand): arguments must be integers, e.g., $(rand 1 100)",
|
||||||
|
id="rand-float-args",
|
||||||
),
|
),
|
||||||
("$(user extra)", "Invalid $(user): does not accept arguments"),
|
pytest.param("$(user extra)", "Invalid $(user): does not accept arguments", id="user-extra-args"),
|
||||||
("$(getcount)", "Invalid $(getcount): a counter name is required"),
|
pytest.param("$(getcount)", "Invalid $(getcount): a counter name is required", id="getcount-no-name"),
|
||||||
(
|
pytest.param(
|
||||||
"$(getcount deaths extra)",
|
"$(getcount deaths extra)",
|
||||||
"Invalid $(getcount): too many arguments, expected $(getcount name)",
|
"Invalid $(getcount): too many arguments, expected $(getcount name)",
|
||||||
|
id="getcount-too-many",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(count deaths abc)",
|
"$(count deaths abc)",
|
||||||
"Invalid $(count): modifier must be an integer (e.g., +5, -1, 0)",
|
"Invalid $(count): modifier must be an integer (e.g., +5, -1, 0)",
|
||||||
|
id="count-bad-modifier",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(count deaths +1 extra)",
|
"$(count deaths +1 extra)",
|
||||||
"Invalid $(count): too many arguments,"
|
"Invalid $(count): too many arguments,"
|
||||||
" expected $(count name [modifier])",
|
" expected $(count name [modifier])",
|
||||||
|
id="count-too-many",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(countdown)",
|
"$(countdown)",
|
||||||
"Invalid $(countdown): missing date,"
|
"Invalid $(countdown): missing date,"
|
||||||
" expected $(countdown Dec 25 2025 12:00:00 AM EST)",
|
" expected $(countdown Dec 25 2025 12:00:00 AM EST)",
|
||||||
|
id="countdown-no-date",
|
||||||
),
|
),
|
||||||
(
|
pytest.param(
|
||||||
"$(countup)",
|
"$(countup)",
|
||||||
"Invalid $(countup): missing date,"
|
"Invalid $(countup): missing date,"
|
||||||
" expected $(countup Dec 25 2025 12:00:00 AM EST)",
|
" expected $(countup Dec 25 2025 12:00:00 AM EST)",
|
||||||
|
id="countup-no-date",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user