File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1252,8 +1252,33 @@ def test_optional_ne() -> None:
12521252
12531253[case testConstantFoldFormatArgs]
12541254from typing import Final
1255+ from testutil import assertRaises
12551256
12561257FMT: Final = "{} {}"
1258+ FMT_S: Final = "{:s}"
1259+ FMT_S_PAIR: Final = "{:s} {:s}"
1260+ FMT_D_S: Final = "{:d} {:s}"
1261+ FMT_S_NAMED: Final = "{name:s}"
12571262
12581263def test_format() -> None:
1259- assert FMT.format(400 + 20, "roll" + "up") == "420 rollup"
1264+ assert FMT.format(400 + 20, "roll" + "up") == "420 rollup"
1265+
1266+ def test_format_s_str() -> None:
1267+ assert FMT_S.format("420") == "420"
1268+
1269+ def test_format_s_str_var() -> None:
1270+ value = "4" + "20"
1271+ assert FMT_S.format(value) == "420"
1272+
1273+ def test_format_s_pair() -> None:
1274+ assert FMT_S_PAIR.format("foo", "bar") == "foo bar"
1275+
1276+ def test_format_d_s() -> None:
1277+ assert FMT_D_S.format(400 + 20, "roll" + "up") == "420 rollup"
1278+
1279+ def test_format_s_named() -> None:
1280+ assert FMT_S_NAMED.format(name="mypy") == "mypy"
1281+
1282+ def test_format_s_non_str() -> None:
1283+ with assertRaises(ValueError):
1284+ FMT_S.format(400 + 20)
You can’t perform that action at this time.
0 commit comments