From bee325387b21b859054002a052149646399b52de Mon Sep 17 00:00:00 2001 From: Alexandre Vassalotti Date: Fri, 16 May 2008 18:15:12 +0000 Subject: Merged revisions 63361-63373,63375,63377-63380 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63361 | alexandre.vassalotti | 2008-05-16 03:14:08 -0400 (Fri, 16 May 2008) | 2 lines Rename the test file of reprlib. ........ r63364 | georg.brandl | 2008-05-16 05:34:48 -0400 (Fri, 16 May 2008) | 2 lines Make generator repr consistent with function and code object repr. ........ r63365 | georg.brandl | 2008-05-16 05:47:29 -0400 (Fri, 16 May 2008) | 2 lines #2869: remove parameter from signature. ........ r63366 | christian.heimes | 2008-05-16 06:23:31 -0400 (Fri, 16 May 2008) | 1 line Fixed #2870: cmathmodule.c compile error ........ r63367 | christian.heimes | 2008-05-16 07:28:56 -0400 (Fri, 16 May 2008) | 1 line Following Amaury's advice ........ r63368 | georg.brandl | 2008-05-16 09:10:15 -0400 (Fri, 16 May 2008) | 2 lines #2890: support os.O_ASYNC and fcntl.FASYNC. ........ r63369 | georg.brandl | 2008-05-16 09:18:50 -0400 (Fri, 16 May 2008) | 2 lines #2845: fix copy2's docs. ........ r63370 | georg.brandl | 2008-05-16 09:24:29 -0400 (Fri, 16 May 2008) | 2 lines Don't allow keyword arguments to reversed(). ........ r63373 | georg.brandl | 2008-05-16 09:41:26 -0400 (Fri, 16 May 2008) | 2 lines Document O_ASYNC addition. ........ r63380 | georg.brandl | 2008-05-16 13:33:13 -0400 (Fri, 16 May 2008) | 2 lines Fix reprlib docs. ........ --- Lib/test/test_enumerate.py | 2 + Lib/test/test_generators.py | 2 +- Lib/test/test_genexps.py | 2 +- Lib/test/test_repr.py | 312 -------------------------------------------- Lib/test/test_reprlib.py | 312 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 316 insertions(+), 314 deletions(-) delete mode 100644 Lib/test/test_repr.py create mode 100644 Lib/test/test_reprlib.py (limited to 'Lib') diff --git a/Lib/test/test_enumerate.py b/Lib/test/test_enumerate.py index 8cebf44469..f5c568995b 100644 --- a/Lib/test/test_enumerate.py +++ b/Lib/test/test_enumerate.py @@ -138,6 +138,8 @@ class TestReversed(unittest.TestCase): for data in 'abc', range(5), tuple(enumerate('abc')), A(), range(1,17,5): self.assertEqual(list(data)[::-1], list(reversed(data))) self.assertRaises(TypeError, reversed, {}) + # don't allow keyword arguments + self.assertRaises(TypeError, reversed, [], a=1) def test_range_optimization(self): x = range(1) diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index e27eaddaae..56f23db042 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -927,7 +927,7 @@ Test the __name__ attribute and the repr() >>> g.__name__ 'f' >>> repr(g) # doctest: +ELLIPSIS -'' +'' """ # conjoin is a simple backtracking generator, named in honor of Icon's diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py index c8abbccb0c..593c1c5b57 100644 --- a/Lib/test/test_genexps.py +++ b/Lib/test/test_genexps.py @@ -92,7 +92,7 @@ Verify that parenthesis are required when used as a keyword argument value Verify that parenthesis are required when used as a keyword argument value >>> dict(a = (i for i in range(10))) #doctest: +ELLIPSIS - {'a': < generator object at ...>} + {'a': at ...>} Verify early binding for the outermost for-expression diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py deleted file mode 100644 index 442c0482c7..0000000000 --- a/Lib/test/test_repr.py +++ /dev/null @@ -1,312 +0,0 @@ -""" - Test cases for the repr module - Nick Mathewson -""" - -import sys -import os -import shutil -import unittest - -from test.test_support import run_unittest -from reprlib import repr as r # Don't shadow builtin repr -from reprlib import Repr - - -def nestedTuple(nesting): - t = () - for i in range(nesting): - t = (t,) - return t - -class ReprTests(unittest.TestCase): - - def test_string(self): - eq = self.assertEquals - eq(r("abc"), "'abc'") - eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'") - - s = "a"*30+"b"*30 - expected = repr(s)[:13] + "..." + repr(s)[-14:] - eq(r(s), expected) - - eq(r("\"'"), repr("\"'")) - s = "\""*30+"'"*100 - expected = repr(s)[:13] + "..." + repr(s)[-14:] - eq(r(s), expected) - - def test_tuple(self): - eq = self.assertEquals - eq(r((1,)), "(1,)") - - t3 = (1, 2, 3) - eq(r(t3), "(1, 2, 3)") - - r2 = Repr() - r2.maxtuple = 2 - expected = repr(t3)[:-2] + "...)" - eq(r2.repr(t3), expected) - - def test_container(self): - from array import array - from collections import deque - - eq = self.assertEquals - # Tuples give up after 6 elements - eq(r(()), "()") - eq(r((1,)), "(1,)") - eq(r((1, 2, 3)), "(1, 2, 3)") - eq(r((1, 2, 3, 4, 5, 6)), "(1, 2, 3, 4, 5, 6)") - eq(r((1, 2, 3, 4, 5, 6, 7)), "(1, 2, 3, 4, 5, 6, ...)") - - # Lists give up after 6 as well - eq(r([]), "[]") - eq(r([1]), "[1]") - eq(r([1, 2, 3]), "[1, 2, 3]") - eq(r([1, 2, 3, 4, 5, 6]), "[1, 2, 3, 4, 5, 6]") - eq(r([1, 2, 3, 4, 5, 6, 7]), "[1, 2, 3, 4, 5, 6, ...]") - - # Sets give up after 6 as well - eq(r(set([])), "set([])") - eq(r(set([1])), "set([1])") - eq(r(set([1, 2, 3])), "set([1, 2, 3])") - eq(r(set([1, 2, 3, 4, 5, 6])), "set([1, 2, 3, 4, 5, 6])") - eq(r(set([1, 2, 3, 4, 5, 6, 7])), "set([1, 2, 3, 4, 5, 6, ...])") - - # Frozensets give up after 6 as well - eq(r(frozenset([])), "frozenset([])") - eq(r(frozenset([1])), "frozenset([1])") - eq(r(frozenset([1, 2, 3])), "frozenset([1, 2, 3])") - eq(r(frozenset([1, 2, 3, 4, 5, 6])), "frozenset([1, 2, 3, 4, 5, 6])") - eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "frozenset([1, 2, 3, 4, 5, 6, ...])") - - # collections.deque after 6 - eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])") - - # Dictionaries give up after 4. - eq(r({}), "{}") - d = {'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4} - eq(r(d), "{'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}") - d['arthur'] = 1 - eq(r(d), "{'alice': 1, 'arthur': 1, 'bob': 2, 'charles': 3, ...}") - - # array.array after 5. - eq(r(array('i')), "array('i', [])") - eq(r(array('i', [1])), "array('i', [1])") - eq(r(array('i', [1, 2])), "array('i', [1, 2])") - eq(r(array('i', [1, 2, 3])), "array('i', [1, 2, 3])") - eq(r(array('i', [1, 2, 3, 4])), "array('i', [1, 2, 3, 4])") - eq(r(array('i', [1, 2, 3, 4, 5])), "array('i', [1, 2, 3, 4, 5])") - eq(r(array('i', [1, 2, 3, 4, 5, 6])), - "array('i', [1, 2, 3, 4, 5, ...])") - - def test_numbers(self): - eq = self.assertEquals - eq(r(123), repr(123)) - eq(r(123), repr(123)) - eq(r(1.0/3), repr(1.0/3)) - - n = 10**100 - expected = repr(n)[:18] + "..." + repr(n)[-19:] - eq(r(n), expected) - - def test_instance(self): - eq = self.assertEquals - i1 = ClassWithRepr("a") - eq(r(i1), repr(i1)) - - i2 = ClassWithRepr("x"*1000) - expected = repr(i2)[:13] + "..." + repr(i2)[-14:] - eq(r(i2), expected) - - i3 = ClassWithFailingRepr() - eq(r(i3), (""%id(i3))) - - s = r(ClassWithFailingRepr) - self.failUnless(s.startswith("")) - self.failUnless(s.find("...") in [12, 13]) - - def test_lambda(self): - self.failUnless(repr(lambda x: x).startswith( - "') - # Methods - self.failUnless(repr(''.split).startswith( - '") - # XXX member descriptors - # XXX attribute descriptors - # XXX slot descriptors - # static and class methods - class C: - def foo(cls): pass - x = staticmethod(C.foo) - self.failUnless(repr(x).startswith('" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__)) - eq(repr(sys), "") - - def test_type(self): - eq = self.assertEquals - touch(os.path.join(self.subpkgname, 'foo.py'), '''\ -class foo(object): - pass -''') - from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo - eq(repr(foo.foo), - "" % foo.__name__) - - def test_object(self): - # XXX Test the repr of a type with a really long tp_name but with no - # tp_repr. WIBNI we had ::Inline? :) - pass - - def test_class(self): - touch(os.path.join(self.subpkgname, 'bar.py'), '''\ -class bar: - pass -''') - from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar - # Module name may be prefixed with "test.", depending on how run. - self.assertEquals(repr(bar.bar), "" % bar.__name__) - - def test_instance(self): - touch(os.path.join(self.subpkgname, 'baz.py'), '''\ -class baz: - pass -''') - from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz - ibaz = baz.baz() - self.failUnless(repr(ibaz).startswith( - "<%s.baz object at 0x" % baz.__name__)) - - def test_method(self): - eq = self.assertEquals - touch(os.path.join(self.subpkgname, 'qux.py'), '''\ -class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: - def amethod(self): pass -''') - from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux - # Unbound methods first - self.failUnless(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod).startswith( - '"%id(i3))) + + s = r(ClassWithFailingRepr) + self.failUnless(s.startswith("")) + self.failUnless(s.find("...") in [12, 13]) + + def test_lambda(self): + self.failUnless(repr(lambda x: x).startswith( + "') + # Methods + self.failUnless(repr(''.split).startswith( + '") + # XXX member descriptors + # XXX attribute descriptors + # XXX slot descriptors + # static and class methods + class C: + def foo(cls): pass + x = staticmethod(C.foo) + self.failUnless(repr(x).startswith('" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__)) + eq(repr(sys), "") + + def test_type(self): + eq = self.assertEquals + touch(os.path.join(self.subpkgname, 'foo.py'), '''\ +class foo(object): + pass +''') + from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo + eq(repr(foo.foo), + "" % foo.__name__) + + def test_object(self): + # XXX Test the repr of a type with a really long tp_name but with no + # tp_repr. WIBNI we had ::Inline? :) + pass + + def test_class(self): + touch(os.path.join(self.subpkgname, 'bar.py'), '''\ +class bar: + pass +''') + from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar + # Module name may be prefixed with "test.", depending on how run. + self.assertEquals(repr(bar.bar), "" % bar.__name__) + + def test_instance(self): + touch(os.path.join(self.subpkgname, 'baz.py'), '''\ +class baz: + pass +''') + from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz + ibaz = baz.baz() + self.failUnless(repr(ibaz).startswith( + "<%s.baz object at 0x" % baz.__name__)) + + def test_method(self): + eq = self.assertEquals + touch(os.path.join(self.subpkgname, 'qux.py'), '''\ +class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: + def amethod(self): pass +''') + from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux + # Unbound methods first + self.failUnless(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod).startswith( + '