mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Update test_descrtut.py from 3.14.3 (#7149)
Co-authored-by: CPython Developers <>
This commit is contained in:
1 parent
1adf9258fc
commit
c1a327d38b
1 file changed
+20
-21
Vendored
+20
-21
@@ -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.support import sortdict # noqa: F401
|
||||
import doctest
|
||||
import unittest
|
||||
|
||||
@@ -34,22 +34,21 @@ class defaultdict(dict):
|
||||
if key not in self:
|
||||
self[key] = other[key]
|
||||
|
||||
|
||||
test_1 = """
|
||||
|
||||
Here's the new type at work:
|
||||
|
||||
>>> print(defaultdict) # show our type
|
||||
<class 'test.test_descrtut.defaultdict'>
|
||||
<class '%(modname)s.defaultdict'>
|
||||
>>> print(type(defaultdict)) # its metatype
|
||||
<class 'type'>
|
||||
>>> a = defaultdict(default=0.0) # create an instance
|
||||
>>> print(a) # show the instance
|
||||
{}
|
||||
>>> print(type(a)) # show its type
|
||||
<class 'test.test_descrtut.defaultdict'>
|
||||
<class '%(modname)s.defaultdict'>
|
||||
>>> print(a.__class__) # show its class
|
||||
<class 'test.test_descrtut.defaultdict'>
|
||||
<class '%(modname)s.defaultdict'>
|
||||
>>> print(type(a) is a.__class__) # its type is its class
|
||||
True
|
||||
>>> a[1] = 3.25 # modify the instance
|
||||
@@ -100,7 +99,7 @@ just like classic classes:
|
||||
>>> print(sortdict(a.__dict__))
|
||||
{'default': -1000, 'x1': 100, 'x2': 200}
|
||||
>>>
|
||||
"""
|
||||
""" % {'modname': __name__}
|
||||
|
||||
class defaultdict2(dict):
|
||||
__slots__ = ['default']
|
||||
@@ -137,10 +136,10 @@ instance variables cannot be assigned to:
|
||||
>>> a.default = -1
|
||||
>>> a[1]
|
||||
-1
|
||||
>>> a.x1 = 1
|
||||
>>> a.x1 = 1 # TODO: RUSTPYTHON; # doctest: +EXPECTED_FAILURE
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in ?
|
||||
AttributeError: 'defaultdict2' object has no attribute 'x1'
|
||||
AttributeError: 'defaultdict2' object has no attribute 'x1' and no __dict__ for setting new attributes
|
||||
>>>
|
||||
|
||||
"""
|
||||
@@ -265,19 +264,19 @@ implicit first argument that is the *class* for which they are invoked.
|
||||
... print("classmethod", cls, y)
|
||||
|
||||
>>> C.foo(1)
|
||||
classmethod <class 'test.test_descrtut.C'> 1
|
||||
classmethod <class '%(modname)s.C'> 1
|
||||
>>> c = C()
|
||||
>>> c.foo(1)
|
||||
classmethod <class 'test.test_descrtut.C'> 1
|
||||
classmethod <class '%(modname)s.C'> 1
|
||||
|
||||
>>> class D(C):
|
||||
... pass
|
||||
|
||||
>>> D.foo(1)
|
||||
classmethod <class 'test.test_descrtut.D'> 1
|
||||
classmethod <class '%(modname)s.D'> 1
|
||||
>>> d = D()
|
||||
>>> d.foo(1)
|
||||
classmethod <class 'test.test_descrtut.D'> 1
|
||||
classmethod <class '%(modname)s.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 +292,18 @@ But notice this:
|
||||
|
||||
>>> E.foo(1)
|
||||
E.foo() called
|
||||
classmethod <class 'test.test_descrtut.C'> 1
|
||||
classmethod <class '%(modname)s.C'> 1
|
||||
>>> e = E()
|
||||
>>> e.foo(1)
|
||||
E.foo() called
|
||||
classmethod <class 'test.test_descrtut.C'> 1
|
||||
classmethod <class '%(modname)s.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
|
||||
specifies the class C. But it stresses the difference between these class
|
||||
methods and methods defined in metaclasses (where an upcall to a metamethod
|
||||
would pass the target class as an explicit first argument).
|
||||
"""
|
||||
""" % {'modname': __name__}
|
||||
|
||||
test_5 = """
|
||||
|
||||
@@ -465,18 +464,18 @@ called A.foo()
|
||||
called A.foo()
|
||||
"""
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
__test__ = {# "tut1": test_1,
|
||||
# "tut2": test_2,
|
||||
# "tut3": test_3,
|
||||
# "tut4": test_4,
|
||||
__test__ = {"tut1": test_1,
|
||||
"tut2": test_2,
|
||||
"tut3": test_3,
|
||||
"tut4": test_4,
|
||||
"tut5": test_5,
|
||||
"tut6": test_6,
|
||||
"tut7": test_7,
|
||||
"tut8": test_8}
|
||||
|
||||
def load_tests(loader, tests, pattern):
|
||||
tests.addTest(doctest.DocTestSuite())
|
||||
from test.support.rustpython import DocTestChecker # TODO: RUSTPYTHON
|
||||
tests.addTest(doctest.DocTestSuite(checker=DocTestChecker())) # TODO: RUSTPYTHON
|
||||
return tests
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user