summaryrefslogtreecommitdiffstats
path: root/Tools/clinic/clinic_test.py
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2014-02-09 06:15:29 (GMT)
committerLarry Hastings <larry@hastings.org>2014-02-09 06:15:29 (GMT)
commit2623c8c23cead505a78ec416072223552e94727e (patch)
tree9ac129d693fd98eb33d548bc836d89e006bbb937 /Tools/clinic/clinic_test.py
parent09f08fe2483aaefba367c6b0b4654c3490a32c42 (diff)
downloadcpython-2623c8c23cead505a78ec416072223552e94727e.zip
cpython-2623c8c23cead505a78ec416072223552e94727e.tar.gz
cpython-2623c8c23cead505a78ec416072223552e94727e.tar.bz2
Issue #20530: Argument Clinic's signature format has been revised again.
The new syntax is highly human readable while still preventing false positives. The syntax also extends Python syntax to denote "self" and positional-only parameters, allowing inspect.Signature objects to be totally accurate for all supported builtins in Python 3.4.
Diffstat (limited to 'Tools/clinic/clinic_test.py')
-rw-r--r--Tools/clinic/clinic_test.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/Tools/clinic/clinic_test.py b/Tools/clinic/clinic_test.py
index 67b0eb9..cd21000 100644
--- a/Tools/clinic/clinic_test.py
+++ b/Tools/clinic/clinic_test.py
@@ -359,7 +359,9 @@ os.stat as os_stat_fn
Perform a stat system call on the given path.""")
self.assertEqual("""
-sig=($module, path)
+stat($module, /, path)
+--
+
Perform a stat system call on the given path.
path
@@ -379,7 +381,9 @@ This is the documentation for foo.
Okay, we're done here.
""")
self.assertEqual("""
-sig=($module, x, y)
+bar($module, /, x, y)
+--
+
This is the documentation for foo.
x
@@ -395,7 +399,7 @@ os.stat
path: str
This/used to break Clinic!
""")
- self.assertEqual("sig=($module, path)\n\nThis/used to break Clinic!", function.docstring)
+ self.assertEqual("stat($module, /, path)\n--\n\nThis/used to break Clinic!", function.docstring)
def test_c_name(self):
function = self.parse_function("module os\nos.stat as os_stat_fn")
@@ -504,7 +508,8 @@ curses.imaginary
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
self.assertEqual(function.docstring.strip(), """
-imaginary([[y1, y2,] x1, x2,] ch, [attr1, attr2, attr3, [attr4, attr5, attr6]])
+imaginary([[y1, y2,] x1, x2,] ch, [attr1, attr2, attr3, [attr4, attr5,
+ attr6]])
y1
@@ -624,9 +629,23 @@ foo.bar
Docstring
""")
- self.assertEqual("sig=($module)\nDocstring", function.docstring)
+ self.assertEqual("bar($module, /)\n--\n\nDocstring", function.docstring)
self.assertEqual(1, len(function.parameters)) # self!
+ def test_init_with_no_parameters(self):
+ function = self.parse_function("""
+module foo
+class foo.Bar "unused" "notneeded"
+foo.Bar.__init__
+
+Docstring
+
+""", signatures_in_block=3, function_index=2)
+ # self is not in the signature
+ self.assertEqual("Bar()\n--\n\nDocstring", function.docstring)
+ # but it *is* a parameter
+ self.assertEqual(1, len(function.parameters))
+
def test_illegal_module_line(self):
self.parse_function_should_fail("""
module foo
@@ -719,7 +738,9 @@ foo.bar
Not at column 0!
""")
self.assertEqual("""
-sig=($module, x, *, y)
+bar($module, /, x, *, y)
+--
+
Not at column 0!
x
@@ -733,7 +754,7 @@ os.stat
path: str
This/used to break Clinic!
""")
- self.assertEqual("sig=($module, path)\nThis/used to break Clinic!", function.docstring)
+ self.assertEqual("stat($module, /, path)\n--\n\nThis/used to break Clinic!", function.docstring)
def test_directive(self):
c = FakeClinic()
@@ -756,13 +777,13 @@ This/used to break Clinic!
parser.parse(block)
return block
- def parse_function(self, text):
+ def parse_function(self, text, signatures_in_block=2, function_index=1):
block = self.parse(text)
s = block.signatures
- self.assertEqual(len(s), 2)
+ self.assertEqual(len(s), signatures_in_block)
assert isinstance(s[0], clinic.Module)
- assert isinstance(s[1], clinic.Function)
- return s[1]
+ assert isinstance(s[function_index], clinic.Function)
+ return s[function_index]
def test_scaffolding(self):
# test repr on special values