Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f68404

Browse files
miss-islingtonerlend-aaslandAlexWaygood
authored
[3.12]gh-106368: Add tests for formatting helpers in Argument Clinic (GH-106415) (#106438)
gh-106368: Add tests for formatting helpers in Argument Clinic (GH-106415)(cherry picked from commit2fb9480)Co-authored-by: Erlend E. Aasland <erlend@python.org>Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parentd5ed72b commit6f68404

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

‎Lib/test/test_clinic.py‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,5 +1692,169 @@ def test_permute_optional_groups(self):
16921692
self.assertEqual(actual,expected)
16931693

16941694

1695+
classFormatHelperTests(unittest.TestCase):
1696+
1697+
deftest_strip_leading_and_trailing_blank_lines(self):
1698+
dataset= (
1699+
# Input lines, expected output.
1700+
("a\nb","a\nb"),
1701+
("a\nb\n","a\nb"),
1702+
("a\nb ","a\nb"),
1703+
("\na\nb\n\n","a\nb"),
1704+
("\n\na\nb\n\n","a\nb"),
1705+
("\n\na\n\nb\n\n","a\n\nb"),
1706+
# Note, leading whitespace is preserved:
1707+
(" a\nb"," a\nb"),
1708+
(" a\nb "," a\nb"),
1709+
("\n\n a\nb\n\n "," a\nb"),
1710+
)
1711+
forlines,expectedindataset:
1712+
withself.subTest(lines=lines,expected=expected):
1713+
out=clinic.strip_leading_and_trailing_blank_lines(lines)
1714+
self.assertEqual(out,expected)
1715+
1716+
deftest_normalize_snippet(self):
1717+
snippet="""
1718+
one
1719+
two
1720+
three
1721+
"""
1722+
1723+
# Expected outputs:
1724+
zero_indent= (
1725+
"one\n"
1726+
"two\n"
1727+
"three"
1728+
)
1729+
four_indent= (
1730+
" one\n"
1731+
" two\n"
1732+
" three"
1733+
)
1734+
eight_indent= (
1735+
" one\n"
1736+
" two\n"
1737+
" three"
1738+
)
1739+
expected_outputs= {0:zero_indent,4:four_indent,8:eight_indent}
1740+
forindent,expectedinexpected_outputs.items():
1741+
withself.subTest(indent=indent):
1742+
actual=clinic.normalize_snippet(snippet,indent=indent)
1743+
self.assertEqual(actual,expected)
1744+
1745+
deftest_accumulator(self):
1746+
acc=clinic.text_accumulator()
1747+
self.assertEqual(acc.output(),"")
1748+
acc.append("a")
1749+
self.assertEqual(acc.output(),"a")
1750+
self.assertEqual(acc.output(),"")
1751+
acc.append("b")
1752+
self.assertEqual(acc.output(),"b")
1753+
self.assertEqual(acc.output(),"")
1754+
acc.append("c")
1755+
acc.append("d")
1756+
self.assertEqual(acc.output(),"cd")
1757+
self.assertEqual(acc.output(),"")
1758+
1759+
deftest_quoted_for_c_string(self):
1760+
dataset= (
1761+
# input, expected
1762+
(r"abc",r"abc"),
1763+
(r"\abc",r"\\abc"),
1764+
(r"\a\bc",r"\\a\\bc"),
1765+
(r"\a\\bc",r"\\a\\\\bc"),
1766+
(r'"abc"',r'\"abc\"'),
1767+
(r"'a'",r"\'a\'"),
1768+
)
1769+
forline,expectedindataset:
1770+
withself.subTest(line=line,expected=expected):
1771+
out=clinic.quoted_for_c_string(line)
1772+
self.assertEqual(out,expected)
1773+
1774+
deftest_rstrip_lines(self):
1775+
lines= (
1776+
"a\n"
1777+
"b\n"
1778+
" c\n"
1779+
" d\n"
1780+
)
1781+
expected= (
1782+
"a\n"
1783+
"b\n"
1784+
" c\n"
1785+
" d\n"
1786+
)
1787+
out=clinic.rstrip_lines(lines)
1788+
self.assertEqual(out,expected)
1789+
1790+
deftest_format_escape(self):
1791+
line="{}, {a}"
1792+
expected="{{}}, {{a}}"
1793+
out=clinic.format_escape(line)
1794+
self.assertEqual(out,expected)
1795+
1796+
deftest_indent_all_lines(self):
1797+
# Blank lines are expected to be unchanged.
1798+
self.assertEqual(clinic.indent_all_lines("",prefix="bar"),"")
1799+
1800+
lines= (
1801+
"one\n"
1802+
"two"# The missing newline is deliberate.
1803+
)
1804+
expected= (
1805+
"barone\n"
1806+
"bartwo"
1807+
)
1808+
out=clinic.indent_all_lines(lines,prefix="bar")
1809+
self.assertEqual(out,expected)
1810+
1811+
# If last line is empty, expect it to be unchanged.
1812+
lines= (
1813+
"\n"
1814+
"one\n"
1815+
"two\n"
1816+
""
1817+
)
1818+
expected= (
1819+
"bar\n"
1820+
"barone\n"
1821+
"bartwo\n"
1822+
""
1823+
)
1824+
out=clinic.indent_all_lines(lines,prefix="bar")
1825+
self.assertEqual(out,expected)
1826+
1827+
deftest_suffix_all_lines(self):
1828+
# Blank lines are expected to be unchanged.
1829+
self.assertEqual(clinic.suffix_all_lines("",suffix="foo"),"")
1830+
1831+
lines= (
1832+
"one\n"
1833+
"two"# The missing newline is deliberate.
1834+
)
1835+
expected= (
1836+
"onefoo\n"
1837+
"twofoo"
1838+
)
1839+
out=clinic.suffix_all_lines(lines,suffix="foo")
1840+
self.assertEqual(out,expected)
1841+
1842+
# If last line is empty, expect it to be unchanged.
1843+
lines= (
1844+
"\n"
1845+
"one\n"
1846+
"two\n"
1847+
""
1848+
)
1849+
expected= (
1850+
"foo\n"
1851+
"onefoo\n"
1852+
"twofoo\n"
1853+
""
1854+
)
1855+
out=clinic.suffix_all_lines(lines,suffix="foo")
1856+
self.assertEqual(out,expected)
1857+
1858+
16951859
if__name__=="__main__":
16961860
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp