summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-01-21 10:28:43 (GMT)
committerGeorg Brandl <georg@python.org>2007-01-21 10:28:43 (GMT)
commitb84c13792db49abdfac97663badfeda0bba11279 (patch)
tree9a6099e4f7800a7a2cbaf4218c3039939263bf40 /Lib/test
parentaef4c6bc00f1b49b4a92b362ef1b60e7c5af5e86 (diff)
downloadcpython-b84c13792db49abdfac97663badfeda0bba11279.zip
cpython-b84c13792db49abdfac97663badfeda0bba11279.tar.gz
cpython-b84c13792db49abdfac97663badfeda0bba11279.tar.bz2
Bug #1486663: don't reject keyword arguments for subclasses of builtin
types.
Diffstat (limited to 'Lib/test')
-rwxr-xr-xLib/test/test_array.py7
-rw-r--r--Lib/test/test_deque.py11
-rw-r--r--Lib/test/test_itertools.py18
-rw-r--r--Lib/test/test_random.py8
4 files changed, 43 insertions, 1 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 06f13cd..63e7f4e 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -12,6 +12,10 @@ from cPickle import loads, dumps
class ArraySubclass(array.array):
pass
+class ArraySubclassWithKwargs(array.array):
+ def __init__(self, typecode, newarg=None):
+ array.array.__init__(typecode)
+
tests = [] # list to accumulate all tests
typecodes = "cubBhHiIlLfd"
@@ -683,6 +687,9 @@ class BaseTest(unittest.TestCase):
b = array.array('B', range(64))
self.assertEqual(rc, sys.getrefcount(10))
+ def test_subclass_with_kwargs(self):
+ # SF bug #1486663 -- this used to erroneously raise a TypeError
+ ArraySubclassWithKwargs('b', newarg=1)
class StringTest(BaseTest):
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 35e1536..1d996ee 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -486,6 +486,16 @@ class TestSubclass(unittest.TestCase):
d1 == d2 # not clear if this is supposed to be True or False,
# but it used to give a SystemError
+
+class SubclassWithKwargs(deque):
+ def __init__(self, newarg=1):
+ deque.__init__(self)
+
+class TestSubclassWithKwargs(unittest.TestCase):
+ def test_subclass_with_kwargs(self):
+ # SF bug #1486663 -- this used to erroneously raise a TypeError
+ SubclassWithKwargs(newarg=1)
+
#==============================================================================
libreftest = """
@@ -599,6 +609,7 @@ def test_main(verbose=None):
TestBasic,
TestVariousIteratorArgs,
TestSubclass,
+ TestSubclassWithKwargs,
)
test_support.run_unittest(*test_classes)
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 2baa507..5e375c9 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -740,6 +740,21 @@ class RegressionTests(unittest.TestCase):
self.assertRaises(AssertionError, list, cycle(gen1()))
self.assertEqual(hist, [0,1])
+class SubclassWithKwargsTest(unittest.TestCase):
+ def test_keywords_in_subclass(self):
+ # count is not subclassable...
+ for cls in (repeat, izip, ifilter, ifilterfalse, chain, imap,
+ starmap, islice, takewhile, dropwhile, cycle):
+ class Subclass(cls):
+ def __init__(self, newarg=None, *args):
+ cls.__init__(self, *args)
+ try:
+ Subclass(newarg=1)
+ except TypeError, err:
+ # we expect type errors because of wrong argument count
+ self.failIf("does not take keyword arguments" in err.args[0])
+
+
libreftest = """ Doctest for examples in the library reference: libitertools.tex
@@ -934,7 +949,8 @@ __test__ = {'libreftest' : libreftest}
def test_main(verbose=None):
test_classes = (TestBasicOps, TestVariousIteratorArgs, TestGC,
- RegressionTests, LengthTransparency)
+ RegressionTests, LengthTransparency,
+ SubclassWithKwargsTest)
test_support.run_unittest(*test_classes)
# verify reference counting
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index ddbcc2f..77bccf6 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -515,6 +515,14 @@ class TestModule(unittest.TestCase):
# tests validity but not completeness of the __all__ list
self.failUnless(set(random.__all__) <= set(dir(random)))
+ def test_random_subclass_with_kwargs(self):
+ # SF bug #1486663 -- this used to erroneously raise a TypeError
+ class Subclass(random.Random):
+ def __init__(self, newarg=None):
+ random.Random.__init__(self)
+ Subclass(newarg=1)
+
+
def test_main(verbose=None):
testclasses = [WichmannHill_TestBasicOps,
MersenneTwister_TestBasicOps,