10000 gh-106368: Clean up Argument Clinic tests by erlend-aasland · Pull Request #106373 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-106368: Clean up Argument Clinic tests #106373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
10000
Diff view
Prev Previous commit
Add checkDocstring helper
  • Loading branch information
erlend-aasland committed Jul 3, 2023
commit 39b09d4f2800bb6ffc64089ecb53c89f94bb19c4
34 changes: 17 additions & 17 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ def test_clinic_1(self):


class ClinicParserTest(TestCase):
def checkDocstring(self, fn, expected):
self.assertTrue(hasattr(fn, "docstring"))
self.assertEqual(fn.docstring.strip(),
dedent(expected).strip())

def test_trivial(self):
parser = DSLParser(FakeClinic())
block = clinic.Block("""
Expand Down Expand Up @@ -407,16 +412,15 @@ def test_function_docstring(self):

Perform a stat system call on the given path.
""")
expected = dedent("""
self.checkDocstring(function, """
stat($module, /, path)
--

Perform a stat system call on the given path.

path
Path to be examined
""").strip()
self.assertEqual(function.docstring, expected)
""")

def test_explicit_parameters_in_docstring(self):
function = self.parse_function(dedent("""
Expand All @@ -430,7 +434,7 @@ def test_explicit_parameters_in_docstring(self):

Okay, we're done here.
"""))
expected = dedent("""
self.checkDocstring(function, """
bar($module, /, x, y)
--

Expand All @@ -440,8 +444,7 @@ def test_explicit_parameters_in_docstring(self):
Documentation for x.

Okay, we're done here.
""").strip()
self.assertEqual(function.docstring, expected)
""")

def test_parser_regression_special_character_in_parameter_column_of_docstring_first_line(self):
function = self.parse_function(dedent("""
Expand All @@ -450,13 +453,12 @@ def test_parser_regression_special_character_in_parameter_column_of_docstring_fi
path: str
This/used to break Clinic!
"""))
expected = dedent("""
self.checkDocstring(function, """
stat($module, /, path)
--

This/used to break Clinic!
""").strip()
self.assertEqual(function.docstring, expected)
""")

def test_c_name(self):
function = self.parse_function("""
Expand Down Expand Up @@ -523,7 +525,7 @@ def test_left_group(self):
p = function.parameters[name]
self.assertEqual(p.group, group)
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
expected = dedent("""
self.checkDocstring(function, """
addch([y, x,] ch, [attr])


Expand All @@ -535,8 +537,7 @@ def test_left_group(self):
Character to add.
attr
Attributes for the character.
""").strip()
self.assertEqual(function.docstring.strip(), expected)
""")

def test_nested_groups(self):
function = self.parse_function("""
Expand Down Expand Up @@ -587,7 +588,7 @@ def test_nested_groups(self):
self.assertEqual(p.group, group)
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)

expected = dedent("""
self.checkDocstring(function, """
imaginary([[y1, y2,] x1, x2,] ch, [attr1, attr2, attr3, [attr4, attr5,
attr6]])

Expand All @@ -614,8 +615,7 @@ def test_nested_groups(self):
Attributes for the character.
attr6
Attributes for the character.
""").strip()
self.assertEqual(function.docstring.strip(), expected)
""")

def parse_function_should_fail(self, s):
with support.captured_stdout() as stdout:
Expand Down Expand Up @@ -835,15 +835,15 @@ def test_function_not_at_column_0(self):
y: str
Not at column 0!
""")
self.assertEqual(dedent("""
self.checkDocstring(function, """
bar($module, /, x, *, y)
--

Not at column 0!

x
Nested docstring here, goeth.
""").strip(), function.docstring)
""")

def test_directive(self):
c = FakeClinic()
Expand Down
3971
0