summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-06-06 15:45:22 (GMT)
committerGitHub <noreply@github.com>2017-06-06 15:45:22 (GMT)
commit5eb788bf7f54a8e04429e18fc332db858edd64b6 (patch)
treeff7ea360d2765c1ec18ad02fcfc1de473a1d7b65 /Lib
parent5cefb6cfdd089d237ba6724bb5311ee4f04be59f (diff)
downloadcpython-5eb788bf7f54a8e04429e18fc332db858edd64b6.zip
cpython-5eb788bf7f54a8e04429e18fc332db858edd64b6.tar.gz
cpython-5eb788bf7f54a8e04429e18fc332db858edd64b6.tar.bz2
bpo-30534: Fixed error messages when pass keyword arguments (#1901)
to functions implemented in C that don't support this. Also unified error messages for functions that don't take positional or keyword arguments.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_call.py60
-rw-r--r--Lib/test/test_itertools.py2
2 files changed, 58 insertions, 4 deletions
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py
index e2b8e0f..0992a0e 100644
--- a/Lib/test/test_call.py
+++ b/Lib/test/test_call.py
@@ -1,4 +1,5 @@
import unittest
+from test.support import cpython_only
# The test cases here cover several paths through the function calling
# code. They depend on the METH_XXX flag that is used to define a C
@@ -33,9 +34,6 @@ class CFunctionCalls(unittest.TestCase):
else:
raise RuntimeError
- def test_varargs0_kw(self):
- self.assertRaises(TypeError, {}.__contains__, x=2)
-
def test_varargs1_kw(self):
self.assertRaises(TypeError, {}.__contains__, x=2)
@@ -122,5 +120,61 @@ class CFunctionCalls(unittest.TestCase):
self.assertRaises(TypeError, [].count, x=2, y=2)
+@cpython_only
+class CFunctionCallsErrorMessages(unittest.TestCase):
+
+ def test_varargs0(self):
+ msg = r"__contains__\(\) takes exactly one argument \(0 given\)"
+ self.assertRaisesRegex(TypeError, msg, {}.__contains__)
+
+ def test_varargs2(self):
+ msg = r"__contains__\(\) takes exactly one argument \(2 given\)"
+ self.assertRaisesRegex(TypeError, msg, {}.__contains__, 0, 1)
+
+ def test_varargs1_kw(self):
+ msg = r"__contains__\(\) takes no keyword arguments"
+ self.assertRaisesRegex(TypeError, msg, {}.__contains__, x=2)
+
+ def test_varargs2_kw(self):
+ msg = r"__contains__\(\) takes no keyword arguments"
+ self.assertRaisesRegex(TypeError, msg, {}.__contains__, x=2, y=2)
+
+ def test_oldargs0_1(self):
+ msg = r"keys\(\) takes no arguments \(1 given\)"
+ self.assertRaisesRegex(TypeError, msg, {}.keys, 0)
+
+ def test_oldargs0_2(self):
+ msg = r"keys\(\) takes no arguments \(2 given\)"
+ self.assertRaisesRegex(TypeError, msg, {}.keys, 0, 1)
+
+ def test_oldargs0_1_kw(self):
+ msg = r"keys\(\) takes no keyword arguments"
+ self.assertRaisesRegex(TypeError, msg, {}.keys, x=2)
+
+ def test_oldargs0_2_kw(self):
+ msg = r"keys\(\) takes no keyword arguments"
+ self.assertRaisesRegex(TypeError, msg, {}.keys, x=2, y=2)
+
+ def test_oldargs1_0(self):
+ msg = r"count\(\) takes exactly one argument \(0 given\)"
+ self.assertRaisesRegex(TypeError, msg, [].count)
+
+ def test_oldargs1_2(self):
+ msg = r"count\(\) takes exactly one argument \(2 given\)"
+ self.assertRaisesRegex(TypeError, msg, [].count, 1, 2)
+
+ def test_oldargs1_0_kw(self):
+ msg = r"count\(\) takes no keyword arguments"
+ self.assertRaisesRegex(TypeError, msg, [].count, x=2)
+
+ def test_oldargs1_1_kw(self):
+ msg = r"count\(\) takes no keyword arguments"
+ self.assertRaisesRegex(TypeError, msg, [].count, {}, x=2)
+
+ def test_oldargs1_2_kw(self):
+ msg = r"count\(\) takes no keyword arguments"
+ self.assertRaisesRegex(TypeError, msg, [].count, x=2, y=2)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index c431f0d..f525255 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -1996,7 +1996,7 @@ class SubclassWithKwargsTest(unittest.TestCase):
Subclass(newarg=1)
except TypeError as err:
# we expect type errors because of wrong argument count
- self.assertNotIn("does not take keyword arguments", err.args[0])
+ self.assertNotIn("keyword arguments", err.args[0])
@support.cpython_only
class SizeofTest(unittest.TestCase):