aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_extcall.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_extcall.py')
-rw-r--r--Lib/test/test_extcall.py65
1 files changed, 22 insertions, 43 deletions
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 80e09a0ec2f..1f7f63042e7 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -1,25 +1,24 @@
-# -*- coding: utf-8 -*-
"""Doctest for method/function calls.
We're going the use these types for extra testing
- >>> from UserList import UserList
- >>> from UserDict import UserDict
+ >>> from collections import UserList
+ >>> from collections import UserDict
We're defining four helper functions
>>> def e(a,b):
- ... print a, b
+ ... print(a, b)
>>> def f(*a, **k):
- ... print a, test_support.sortdict(k)
+ ... print(a, support.sortdict(k))
>>> def g(x, *y, **z):
- ... print x, y, test_support.sortdict(z)
+ ... print(x, y, support.sortdict(z))
>>> def h(j=1, a=2, h=3):
- ... print j, a, h
+ ... print(j, a, h)
Argument list examples
@@ -93,7 +92,7 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
Traceback (most recent call last):
...
- TypeError: g() argument after * must be a sequence, not instance
+ TypeError: g() argument after * must be a sequence, not Nothing
>>> class Nothing:
... def __len__(self): return 5
@@ -102,7 +101,7 @@ Verify clearing of SF bug #733667
>>> g(*Nothing())
Traceback (most recent call last):
...
- TypeError: g() argument after * must be a sequence, not instance
+ TypeError: g() argument after * must be a sequence, not Nothing
>>> class Nothing():
... def __len__(self): return 5
@@ -117,7 +116,7 @@ Verify clearing of SF bug #733667
>>> class Nothing:
... def __init__(self): self.c = 0
... def __iter__(self): return self
- ... def next(self):
+ ... def __next__(self):
... if self.c == 4:
... raise StopIteration
... c = self.c
@@ -208,7 +207,7 @@ Another helper function
>>> d = {}
- >>> for i in xrange(512):
+ >>> for i in range(512):
... key = 'k%d' % i
... d[key] = i
>>> a, b = f2(1, *(2,3), **d)
@@ -225,16 +224,9 @@ Another helper function
>>> Foo.method(x, *(1, 2))
3
>>> Foo.method(*(1, 2, 3))
- Traceback (most recent call last):
- ...
- TypeError: unbound method method() must be called with Foo instance as \
-first argument (got int instance instead)
-
+ 5
>>> Foo.method(1, *[2, 3])
- Traceback (most recent call last):
- ...
- TypeError: unbound method method() must be called with Foo instance as \
-first argument (got int instance instead)
+ 5
A PyCFunction that takes only positional parameters should allow an
empty keyword dictionary to pass without a complaint, but raise a
@@ -267,7 +259,7 @@ the function call setup. See <http://bugs.python.org/issue2016>.
>>> x = {Name("a"):1, Name("b"):2}
>>> def f(a, b):
- ... print a,b
+ ... print(a,b)
>>> f(**x)
1 2
@@ -287,33 +279,20 @@ The number of arguments passed in includes keywords:
>>> f(6, a=4, *(1, 2, 3))
Traceback (most recent call last):
...
- TypeError: f() takes exactly 1 argument (5 given)
+ TypeError: f() takes exactly 1 positional argument (5 given)
+ >>> def f(a, *, kw):
+ ... pass
+ >>> f(6, 4, kw=4)
+ Traceback (most recent call last):
+ ...
+ TypeError: f() takes exactly 1 positional argument (3 given)
"""
-import unittest
import sys
-from test import test_support
-
-
-class ExtCallTest(unittest.TestCase):
-
- def test_unicode_keywords(self):
- def f(a):
- return a
- self.assertEqual(f(**{u'a': 4}), 4)
- self.assertRaises(TypeError, f, **{u'stören': 4})
- self.assertRaises(TypeError, f, **{u'someLongString':2})
- try:
- f(a=4, **{u'a': 4})
- except TypeError:
- pass
- else:
- self.fail("duplicate arguments didn't raise")
-
+from test import support
def test_main():
- test_support.run_doctest(sys.modules[__name__], True)
- test_support.run_unittest(ExtCallTest)
+ support.run_doctest(sys.modules[__name__], True)
if __name__ == '__main__':
test_main()