From: <pj...@us...> - 2008-08-01 22:28:55
|
Revision: 5048 http://jython.svn.sourceforge.net/jython/?rev=5048&view=rev Author: pjenvey Date: 2008-08-01 22:28:52 +0000 (Fri, 01 Aug 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_descrtut.py@38295 Modified Paths: -------------- branches/asm/Lib/test/test_descrtut.py Modified: branches/asm/Lib/test/test_descrtut.py =================================================================== --- branches/asm/Lib/test/test_descrtut.py 2008-08-01 22:28:33 UTC (rev 5047) +++ branches/asm/Lib/test/test_descrtut.py 2008-08-01 22:28:52 UTC (rev 5048) @@ -8,7 +8,7 @@ # of much interest anymore), and a few were fiddled to make the output # deterministic. -from test_support import sortdict +from test.test_support import sortdict import pprint class defaultdict(dict): @@ -37,18 +37,18 @@ Here's the new type at work: >>> print defaultdict # show our type - <class 'test_descrtut.defaultdict'> + <class 'test.test_descrtut.defaultdict'> >>> print type(defaultdict) # its metatype <type 'type'> >>> a = defaultdict(default=0.0) # create an instance >>> print a # show the instance {} >>> print type(a) # show its type - <class 'test_descrtut.defaultdict'> + <class 'test.test_descrtut.defaultdict'> >>> print a.__class__ # show its class - <class 'test_descrtut.defaultdict'> + <class 'test.test_descrtut.defaultdict'> >>> print type(a) is a.__class__ # its type is its class - 1 + True >>> a[1] = 3.25 # modify the instance >>> print a # show the new value {1: 3.25} @@ -73,17 +73,11 @@ >>> exec "x = 3; print x" in a 3 >>> print sorted(a.keys()) - [1, 2, 'x'] + [1, 2, '__builtins__', 'x'] >>> print a['x'] 3 >>> -This work in Jython - - >>> exec "print foo" in a - 0.0 - >>> - Now I'll show that defaultdict instances have dynamic instance variables, just like classic classes: @@ -94,14 +88,14 @@ >>> print a["noway"] -1000 >>> 'default' in dir(a) - 1 + True >>> a.x1 = 100 >>> a.x2 = 200 >>> print a.x1 100 >>> d = dir(a) >>> 'default' in d and 'x1' in d and 'x2' in d - 1 + True >>> print sortdict(a.__dict__) {'default': -1000, 'x1': 100, 'x2': 200} >>> @@ -163,11 +157,11 @@ >>> list <type 'list'> >>> isinstance([], list) - 1 + True >>> isinstance([], dict) - 0 + False >>> isinstance([], object) - 1 + True >>> Under the new proposal, the __methods__ attribute no longer exists: @@ -198,22 +192,22 @@ '__iadd__', '__imul__', '__init__', + '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', - '__nonzero__', - '__radd__', '__reduce__', + '__reduce_ex__', '__repr__', + '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__str__', - '__unicode__', 'append', 'count', 'extend', @@ -224,7 +218,6 @@ 'reverse', 'sort'] - The new introspection API gives more information than the old one: in addition to the regular methods, it also shows the methods that are normally invoked through special notations, e.g. __iadd__ (+=), __len__ @@ -253,9 +246,9 @@ >>> class C: ... + ... @staticmethod ... def foo(x, y): ... print "staticmethod", x, y - ... foo = staticmethod(foo) >>> C.foo(1, 2) staticmethod 1 2 @@ -267,24 +260,24 @@ implicit first argument that is the *class* for which they are invoked. >>> class C: + ... @classmethod ... def foo(cls, y): ... print "classmethod", cls, y - ... foo = classmethod(foo) >>> C.foo(1) - classmethod test_descrtut.C 1 + classmethod test.test_descrtut.C 1 >>> c = C() >>> c.foo(1) - classmethod test_descrtut.C 1 + classmethod test.test_descrtut.C 1 >>> class D(C): ... pass >>> D.foo(1) - classmethod test_descrtut.D 1 + classmethod test.test_descrtut.D 1 >>> d = D() >>> d.foo(1) - classmethod test_descrtut.D 1 + classmethod test.test_descrtut.D 1 This prints "classmethod __main__.D 1" both times; in other words, the class passed as the first argument of foo() is the class involved in the @@ -293,18 +286,18 @@ But notice this: >>> class E(C): + ... @classmethod ... def foo(cls, y): # override C.foo ... print "E.foo() called" ... C.foo(y) - ... foo = classmethod(foo) >>> E.foo(1) E.foo() called - classmethod test_descrtut.C 1 + classmethod test.test_descrtut.C 1 >>> e = E() >>> e.foo(1) E.foo() called - classmethod test_descrtut.C 1 + classmethod test.test_descrtut.C 1 In this example, the call to C.foo() from E.foo() will see class C as its first argument, not class E. This is to be expected, since the call @@ -475,7 +468,7 @@ """ __test__ = {"tut1": test_1, - #"tut2": test_2, no slots right now + "tut2": test_2, "tut3": test_3, "tut4": test_4, "tut5": test_5, @@ -493,7 +486,7 @@ # into the doctest examples, and unless the full test.test_descrtut # business is used the name can change depending on how the test is # invoked. - import test_support, test_descrtut + from test import test_support, test_descrtut test_support.run_doctest(test_descrtut, verbose) # This part isn't needed for regrtest, but for running the test directly. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |