Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
21f6aac6
Kaydet (Commit)
21f6aac6
authored
Mar 26, 2009
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
apply the second part of #4242's patch; classify all the implementation details in test_descr
üst
47d9738b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
45 deletions
+109
-45
test_descr.py
Lib/test/test_descr.py
+109
-45
No files found.
Lib/test/test_descr.py
Dosyayı görüntüle @
21f6aac6
...
@@ -75,8 +75,9 @@ class OperatorsTest(unittest.TestCase):
...
@@ -75,8 +75,9 @@ class OperatorsTest(unittest.TestCase):
# Find method in parent class
# Find method in parent class
while
meth
not
in
t
.
__dict__
:
while
meth
not
in
t
.
__dict__
:
t
=
t
.
__bases__
[
0
]
t
=
t
.
__bases__
[
0
]
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
self
.
assertEqual
(
m
,
t
.
__dict__
[
meth
])
# method object; the getattr() below obtains its underlying function.
self
.
assertEqual
(
getattr
(
m
,
'im_func'
,
m
),
t
.
__dict__
[
meth
])
self
.
assertEqual
(
m
(
a
),
res
)
self
.
assertEqual
(
m
(
a
),
res
)
bm
=
getattr
(
a
,
meth
)
bm
=
getattr
(
a
,
meth
)
self
.
assertEqual
(
bm
(),
res
)
self
.
assertEqual
(
bm
(),
res
)
...
@@ -95,7 +96,9 @@ class OperatorsTest(unittest.TestCase):
...
@@ -95,7 +96,9 @@ class OperatorsTest(unittest.TestCase):
m
=
getattr
(
t
,
meth
)
m
=
getattr
(
t
,
meth
)
while
meth
not
in
t
.
__dict__
:
while
meth
not
in
t
.
__dict__
:
t
=
t
.
__bases__
[
0
]
t
=
t
.
__bases__
[
0
]
self
.
assertEqual
(
m
,
t
.
__dict__
[
meth
])
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
# method object; the getattr() below obtains its underlying function.
self
.
assertEqual
(
getattr
(
m
,
'im_func'
,
m
),
t
.
__dict__
[
meth
])
self
.
assertEqual
(
m
(
a
,
b
),
res
)
self
.
assertEqual
(
m
(
a
,
b
),
res
)
bm
=
getattr
(
a
,
meth
)
bm
=
getattr
(
a
,
meth
)
self
.
assertEqual
(
bm
(
b
),
res
)
self
.
assertEqual
(
bm
(
b
),
res
)
...
@@ -107,7 +110,9 @@ class OperatorsTest(unittest.TestCase):
...
@@ -107,7 +110,9 @@ class OperatorsTest(unittest.TestCase):
m
=
getattr
(
t
,
meth
)
m
=
getattr
(
t
,
meth
)
while
meth
not
in
t
.
__dict__
:
while
meth
not
in
t
.
__dict__
:
t
=
t
.
__bases__
[
0
]
t
=
t
.
__bases__
[
0
]
self
.
assertEqual
(
m
,
t
.
__dict__
[
meth
])
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
# method object; the getattr() below obtains its underlying function.
self
.
assertEqual
(
getattr
(
m
,
'im_func'
,
m
),
t
.
__dict__
[
meth
])
self
.
assertEqual
(
m
(
a
,
b
,
c
),
res
)
self
.
assertEqual
(
m
(
a
,
b
,
c
),
res
)
bm
=
getattr
(
a
,
meth
)
bm
=
getattr
(
a
,
meth
)
self
.
assertEqual
(
bm
(
b
,
c
),
res
)
self
.
assertEqual
(
bm
(
b
,
c
),
res
)
...
@@ -120,7 +125,9 @@ class OperatorsTest(unittest.TestCase):
...
@@ -120,7 +125,9 @@ class OperatorsTest(unittest.TestCase):
m
=
getattr
(
t
,
meth
)
m
=
getattr
(
t
,
meth
)
while
meth
not
in
t
.
__dict__
:
while
meth
not
in
t
.
__dict__
:
t
=
t
.
__bases__
[
0
]
t
=
t
.
__bases__
[
0
]
self
.
assertEqual
(
m
,
t
.
__dict__
[
meth
])
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
# method object; the getattr() below obtains its underlying function.
self
.
assertEqual
(
getattr
(
m
,
'im_func'
,
m
),
t
.
__dict__
[
meth
])
d
[
'a'
]
=
deepcopy
(
a
)
d
[
'a'
]
=
deepcopy
(
a
)
m
(
d
[
'a'
],
b
)
m
(
d
[
'a'
],
b
)
self
.
assertEqual
(
d
[
'a'
],
res
)
self
.
assertEqual
(
d
[
'a'
],
res
)
...
@@ -137,7 +144,9 @@ class OperatorsTest(unittest.TestCase):
...
@@ -137,7 +144,9 @@ class OperatorsTest(unittest.TestCase):
m
=
getattr
(
t
,
meth
)
m
=
getattr
(
t
,
meth
)
while
meth
not
in
t
.
__dict__
:
while
meth
not
in
t
.
__dict__
:
t
=
t
.
__bases__
[
0
]
t
=
t
.
__bases__
[
0
]
self
.
assertEqual
(
m
,
t
.
__dict__
[
meth
])
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
# method object; the getattr() below obtains its underlying function.
self
.
assertEqual
(
getattr
(
m
,
'im_func'
,
m
),
t
.
__dict__
[
meth
])
d
[
'a'
]
=
deepcopy
(
a
)
d
[
'a'
]
=
deepcopy
(
a
)
m
(
d
[
'a'
],
b
,
c
)
m
(
d
[
'a'
],
b
,
c
)
self
.
assertEqual
(
d
[
'a'
],
res
)
self
.
assertEqual
(
d
[
'a'
],
res
)
...
@@ -154,7 +163,9 @@ class OperatorsTest(unittest.TestCase):
...
@@ -154,7 +163,9 @@ class OperatorsTest(unittest.TestCase):
while
meth
not
in
t
.
__dict__
:
while
meth
not
in
t
.
__dict__
:
t
=
t
.
__bases__
[
0
]
t
=
t
.
__bases__
[
0
]
m
=
getattr
(
t
,
meth
)
m
=
getattr
(
t
,
meth
)
self
.
assertEqual
(
m
,
t
.
__dict__
[
meth
])
# in some implementations (e.g. PyPy), 'm' can be a regular unbound
# method object; the getattr() below obtains its underlying function.
self
.
assertEqual
(
getattr
(
m
,
'im_func'
,
m
),
t
.
__dict__
[
meth
])
dictionary
[
'a'
]
=
deepcopy
(
a
)
dictionary
[
'a'
]
=
deepcopy
(
a
)
m
(
dictionary
[
'a'
],
b
,
c
,
d
)
m
(
dictionary
[
'a'
],
b
,
c
,
d
)
self
.
assertEqual
(
dictionary
[
'a'
],
res
)
self
.
assertEqual
(
dictionary
[
'a'
],
res
)
...
@@ -182,7 +193,10 @@ class OperatorsTest(unittest.TestCase):
...
@@ -182,7 +193,10 @@ class OperatorsTest(unittest.TestCase):
def
test_dicts
(
self
):
def
test_dicts
(
self
):
# Testing dict operations...
# Testing dict operations...
self
.
binop_test
({
1
:
2
},
{
2
:
1
},
-
1
,
"cmp(a,b)"
,
"__cmp__"
)
if
hasattr
(
dict
,
'__cmp__'
):
# PyPy has only rich comparison on dicts
self
.
binop_test
({
1
:
2
},
{
2
:
1
},
-
1
,
"cmp(a,b)"
,
"__cmp__"
)
else
:
self
.
binop_test
({
1
:
2
},
{
2
:
1
},
True
,
"a < b"
,
"__lt__"
)
self
.
binop_test
({
1
:
2
,
3
:
4
},
1
,
1
,
"b in a"
,
"__contains__"
)
self
.
binop_test
({
1
:
2
,
3
:
4
},
1
,
1
,
"b in a"
,
"__contains__"
)
self
.
binop_test
({
1
:
2
,
3
:
4
},
2
,
0
,
"b in a"
,
"__contains__"
)
self
.
binop_test
({
1
:
2
,
3
:
4
},
2
,
0
,
"b in a"
,
"__contains__"
)
self
.
binop_test
({
1
:
2
,
3
:
4
},
1
,
2
,
"a[b]"
,
"__getitem__"
)
self
.
binop_test
({
1
:
2
,
3
:
4
},
1
,
2
,
"a[b]"
,
"__getitem__"
)
...
@@ -293,6 +307,7 @@ class OperatorsTest(unittest.TestCase):
...
@@ -293,6 +307,7 @@ class OperatorsTest(unittest.TestCase):
self
.
assertEqual
(
repr
(
a
),
"234.5"
)
self
.
assertEqual
(
repr
(
a
),
"234.5"
)
self
.
assertEqual
(
a
.
prec
,
12
)
self
.
assertEqual
(
a
.
prec
,
12
)
@test_support.impl_detail
(
"the module 'xxsubtype' is internal"
)
def
test_spam_lists
(
self
):
def
test_spam_lists
(
self
):
# Testing spamlist operations...
# Testing spamlist operations...
import
copy
,
xxsubtype
as
spam
import
copy
,
xxsubtype
as
spam
...
@@ -336,6 +351,7 @@ class OperatorsTest(unittest.TestCase):
...
@@ -336,6 +351,7 @@ class OperatorsTest(unittest.TestCase):
a
.
setstate
(
42
)
a
.
setstate
(
42
)
self
.
assertEqual
(
a
.
getstate
(),
42
)
self
.
assertEqual
(
a
.
getstate
(),
42
)
@test_support.impl_detail
(
"the module 'xxsubtype' is internal"
)
def
test_spam_dicts
(
self
):
def
test_spam_dicts
(
self
):
# Testing spamdict operations...
# Testing spamdict operations...
import
copy
,
xxsubtype
as
spam
import
copy
,
xxsubtype
as
spam
...
@@ -891,8 +907,11 @@ order (MRO) for bases """
...
@@ -891,8 +907,11 @@ order (MRO) for bases """
try
:
try
:
callable
(
*
args
)
callable
(
*
args
)
except
exc
,
msg
:
except
exc
,
msg
:
if
not
str
(
msg
)
.
startswith
(
expected
):
# the exact msg is generally considered an impl detail
self
.
fail
(
"Message
%
r, expected
%
r"
%
(
str
(
msg
),
expected
))
if
test_support
.
check_impl_detail
():
if
not
str
(
msg
)
.
startswith
(
expected
):
self
.
fail
(
"Message
%
r, expected
%
r"
%
(
str
(
msg
),
expected
))
else
:
else
:
self
.
fail
(
"Expected
%
s"
%
exc
)
self
.
fail
(
"Expected
%
s"
%
exc
)
...
@@ -1085,6 +1104,7 @@ order (MRO) for bases """
...
@@ -1085,6 +1104,7 @@ order (MRO) for bases """
x
.
c
=
Counted
()
x
.
c
=
Counted
()
self
.
assertEqual
(
Counted
.
counter
,
3
)
self
.
assertEqual
(
Counted
.
counter
,
3
)
del
x
del
x
test_support
.
gc_collect
()
self
.
assertEqual
(
Counted
.
counter
,
0
)
self
.
assertEqual
(
Counted
.
counter
,
0
)
class
D
(
C
):
class
D
(
C
):
pass
pass
...
@@ -1093,6 +1113,7 @@ order (MRO) for bases """
...
@@ -1093,6 +1113,7 @@ order (MRO) for bases """
x
.
z
=
Counted
()
x
.
z
=
Counted
()
self
.
assertEqual
(
Counted
.
counter
,
2
)
self
.
assertEqual
(
Counted
.
counter
,
2
)
del
x
del
x
test_support
.
gc_collect
()
self
.
assertEqual
(
Counted
.
counter
,
0
)
self
.
assertEqual
(
Counted
.
counter
,
0
)
class
E
(
D
):
class
E
(
D
):
__slots__
=
[
'e'
]
__slots__
=
[
'e'
]
...
@@ -1102,6 +1123,7 @@ order (MRO) for bases """
...
@@ -1102,6 +1123,7 @@ order (MRO) for bases """
x
.
e
=
Counted
()
x
.
e
=
Counted
()
self
.
assertEqual
(
Counted
.
counter
,
3
)
self
.
assertEqual
(
Counted
.
counter
,
3
)
del
x
del
x
test_support
.
gc_collect
()
self
.
assertEqual
(
Counted
.
counter
,
0
)
self
.
assertEqual
(
Counted
.
counter
,
0
)
# Test cyclical leaks [SF bug 519621]
# Test cyclical leaks [SF bug 519621]
...
@@ -1112,22 +1134,23 @@ order (MRO) for bases """
...
@@ -1112,22 +1134,23 @@ order (MRO) for bases """
s
.
a
=
[
Counted
(),
s
]
s
.
a
=
[
Counted
(),
s
]
self
.
assertEqual
(
Counted
.
counter
,
1
)
self
.
assertEqual
(
Counted
.
counter
,
1
)
s
=
None
s
=
None
import
gc
test_support
.
gc_collect
()
gc
.
collect
()
self
.
assertEqual
(
Counted
.
counter
,
0
)
self
.
assertEqual
(
Counted
.
counter
,
0
)
# Test lookup leaks [SF bug 572567]
# Test lookup leaks [SF bug 572567]
import
sys
,
gc
import
sys
,
gc
class
G
(
object
):
if
hasattr
(
gc
,
'get_objects'
):
def
__cmp__
(
self
,
other
):
class
G
(
object
):
return
0
def
__cmp__
(
self
,
other
):
__hash__
=
None
# Silence Py3k warning
return
0
g
=
G
()
__hash__
=
None
# Silence Py3k warning
orig_objects
=
len
(
gc
.
get_objects
())
g
=
G
()
for
i
in
xrange
(
10
):
orig_objects
=
len
(
gc
.
get_objects
())
g
==
g
for
i
in
xrange
(
10
):
new_objects
=
len
(
gc
.
get_objects
())
g
==
g
self
.
assertEqual
(
orig_objects
,
new_objects
)
new_objects
=
len
(
gc
.
get_objects
())
self
.
assertEqual
(
orig_objects
,
new_objects
)
class
H
(
object
):
class
H
(
object
):
__slots__
=
[
'a'
,
'b'
]
__slots__
=
[
'a'
,
'b'
]
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -1382,6 +1405,7 @@ order (MRO) for bases """
...
@@ -1382,6 +1405,7 @@ order (MRO) for bases """
else
:
else
:
self
.
fail
(
"classmethod shouldn't accept keyword args"
)
self
.
fail
(
"classmethod shouldn't accept keyword args"
)
@test_support.impl_detail
(
"the module 'xxsubtype' is internal"
)
def
test_classmethods_in_c
(
self
):
def
test_classmethods_in_c
(
self
):
# Testing C-based class methods...
# Testing C-based class methods...
import
xxsubtype
as
spam
import
xxsubtype
as
spam
...
@@ -1413,6 +1437,7 @@ order (MRO) for bases """
...
@@ -1413,6 +1437,7 @@ order (MRO) for bases """
self
.
assertEqual
(
d
.
foo
(
1
),
(
d
,
1
))
self
.
assertEqual
(
d
.
foo
(
1
),
(
d
,
1
))
self
.
assertEqual
(
D
.
foo
(
d
,
1
),
(
d
,
1
))
self
.
assertEqual
(
D
.
foo
(
d
,
1
),
(
d
,
1
))
@test_support.impl_detail
(
"the module 'xxsubtype' is internal"
)
def
test_staticmethods_in_c
(
self
):
def
test_staticmethods_in_c
(
self
):
# Testing C-based static methods...
# Testing C-based static methods...
import
xxsubtype
as
spam
import
xxsubtype
as
spam
...
@@ -1529,6 +1554,14 @@ order (MRO) for bases """
...
@@ -1529,6 +1554,14 @@ order (MRO) for bases """
class
__metaclass__
(
type
):
class
__metaclass__
(
type
):
def
mro
(
self
):
def
mro
(
self
):
return
[
self
,
dict
,
object
]
return
[
self
,
dict
,
object
]
# In CPython, the class creation above already raises
# TypeError, as a protection against the fact that
# instances of X would segfault it. In other Python
# implementations it would be ok to let the class X
# be created, but instead get a clean TypeError on the
# __setitem__ below.
x
=
object
.
__new__
(
X
)
x
[
5
]
=
6
except
TypeError
:
except
TypeError
:
pass
pass
else
:
else
:
...
@@ -1766,6 +1799,10 @@ order (MRO) for bases """
...
@@ -1766,6 +1799,10 @@ order (MRO) for bases """
# Safety test for __cmp__
# Safety test for __cmp__
def
unsafecmp
(
a
,
b
):
def
unsafecmp
(
a
,
b
):
if
not
hasattr
(
a
,
'__cmp__'
):
return
# some types don't have a __cmp__ any more (so the
# test doesn't make sense any more), or maybe they
# never had a __cmp__ at all, e.g. in PyPy
try
:
try
:
a
.
__class__
.
__cmp__
(
a
,
b
)
a
.
__class__
.
__cmp__
(
a
,
b
)
except
TypeError
:
except
TypeError
:
...
@@ -1781,7 +1818,8 @@ order (MRO) for bases """
...
@@ -1781,7 +1818,8 @@ order (MRO) for bases """
unsafecmp
(
1
,
1L
)
unsafecmp
(
1
,
1L
)
unsafecmp
(
1L
,
1
)
unsafecmp
(
1L
,
1
)
def
test_recursions
(
self
):
@test_support.impl_detail
(
"custom logic for printing to real file objects"
)
def
test_recursions_1
(
self
):
# Testing recursion checks ...
# Testing recursion checks ...
class
Letter
(
str
):
class
Letter
(
str
):
def
__new__
(
cls
,
letter
):
def
__new__
(
cls
,
letter
):
...
@@ -1806,6 +1844,7 @@ order (MRO) for bases """
...
@@ -1806,6 +1844,7 @@ order (MRO) for bases """
finally
:
finally
:
sys
.
stdout
=
test_stdout
sys
.
stdout
=
test_stdout
def
test_recursions_2
(
self
):
# Bug #1202533.
# Bug #1202533.
class
A
(
object
):
class
A
(
object
):
pass
pass
...
@@ -1826,6 +1865,7 @@ order (MRO) for bases """
...
@@ -1826,6 +1865,7 @@ order (MRO) for bases """
r
=
weakref
.
ref
(
c
)
r
=
weakref
.
ref
(
c
)
self
.
assertEqual
(
r
(),
c
)
self
.
assertEqual
(
r
(),
c
)
del
c
del
c
test_support
.
gc_collect
()
self
.
assertEqual
(
r
(),
None
)
self
.
assertEqual
(
r
(),
None
)
del
r
del
r
class
NoWeak
(
object
):
class
NoWeak
(
object
):
...
@@ -1843,6 +1883,7 @@ order (MRO) for bases """
...
@@ -1843,6 +1883,7 @@ order (MRO) for bases """
r
=
weakref
.
ref
(
yes
)
r
=
weakref
.
ref
(
yes
)
self
.
assertEqual
(
r
(),
yes
)
self
.
assertEqual
(
r
(),
yes
)
del
yes
del
yes
test_support
.
gc_collect
()
self
.
assertEqual
(
r
(),
None
)
self
.
assertEqual
(
r
(),
None
)
del
r
del
r
...
@@ -2179,7 +2220,10 @@ order (MRO) for bases """
...
@@ -2179,7 +2220,10 @@ order (MRO) for bases """
# Two essentially featureless objects, just inheriting stuff from
# Two essentially featureless objects, just inheriting stuff from
# object.
# object.
self
.
assertEqual
(
dir
(
None
),
dir
(
Ellipsis
))
self
.
assertEqual
(
dir
(
NotImplemented
),
dir
(
Ellipsis
))
if
test_support
.
check_impl_detail
():
# None differs in PyPy: it has a __nonzero__
self
.
assertEqual
(
dir
(
None
),
dir
(
Ellipsis
))
# Nasty test case for proxied objects
# Nasty test case for proxied objects
class
Wrapper
(
object
):
class
Wrapper
(
object
):
...
@@ -2893,7 +2937,7 @@ order (MRO) for bases """
...
@@ -2893,7 +2937,7 @@ order (MRO) for bases """
self
.
fail
(
"shouldn't allow
%
r.__class__ =
%
r"
%
(
x
,
C
))
self
.
fail
(
"shouldn't allow
%
r.__class__ =
%
r"
%
(
x
,
C
))
try
:
try
:
delattr
(
x
,
"__class__"
)
delattr
(
x
,
"__class__"
)
except
TypeError
:
except
(
TypeError
,
AttributeError
)
:
pass
pass
else
:
else
:
self
.
fail
(
"shouldn't allow del
%
r.__class__"
%
x
)
self
.
fail
(
"shouldn't allow del
%
r.__class__"
%
x
)
...
@@ -3027,6 +3071,16 @@ order (MRO) for bases """
...
@@ -3027,6 +3071,16 @@ order (MRO) for bases """
mod
.
__dict__
[
"spam"
]
=
"eggs"
mod
.
__dict__
[
"spam"
]
=
"eggs"
# Exception's __dict__ can be replaced, but not deleted
# Exception's __dict__ can be replaced, but not deleted
# (at least not any more than regular exception's __dict__ can
# be deleted; on CPython it is not the case, whereas on PyPy they
# can, just like any other new-style instance's __dict__.)
def
can_delete_dict
(
e
):
try
:
del
e
.
__dict__
except
(
TypeError
,
AttributeError
):
return
False
else
:
return
True
class
Exception1
(
Exception
,
Base
):
class
Exception1
(
Exception
,
Base
):
pass
pass
class
Exception2
(
Base
,
Exception
):
class
Exception2
(
Base
,
Exception
):
...
@@ -3035,12 +3089,7 @@ order (MRO) for bases """
...
@@ -3035,12 +3089,7 @@ order (MRO) for bases """
e
=
ExceptionType
()
e
=
ExceptionType
()
e
.
__dict__
=
{
"a"
:
1
}
e
.
__dict__
=
{
"a"
:
1
}
self
.
assertEqual
(
e
.
a
,
1
)
self
.
assertEqual
(
e
.
a
,
1
)
try
:
self
.
assertEqual
(
can_delete_dict
(
e
),
can_delete_dict
(
ValueError
()))
del
e
.
__dict__
except
(
TypeError
,
AttributeError
):
pass
else
:
self
.
fail
(
"
%
r's __dict__ can be deleted"
%
e
)
def
test_pickles
(
self
):
def
test_pickles
(
self
):
# Testing pickling and copying new-style classes and objects...
# Testing pickling and copying new-style classes and objects...
...
@@ -3339,7 +3388,7 @@ order (MRO) for bases """
...
@@ -3339,7 +3388,7 @@ order (MRO) for bases """
class
B
(
A
):
class
B
(
A
):
pass
pass
del
B
del
B
gc
.
collect
()
test_support
.
gc_
collect
()
A
.
__setitem__
=
lambda
*
a
:
None
# crash
A
.
__setitem__
=
lambda
*
a
:
None
# crash
def
test_buffer_inheritance
(
self
):
def
test_buffer_inheritance
(
self
):
...
@@ -3431,6 +3480,7 @@ order (MRO) for bases """
...
@@ -3431,6 +3480,7 @@ order (MRO) for bases """
c
=
C
()
c
=
C
()
self
.
assertEqual
(
log
,
[])
self
.
assertEqual
(
log
,
[])
del
c
del
c
test_support
.
gc_collect
()
self
.
assertEqual
(
log
,
[
1
])
self
.
assertEqual
(
log
,
[
1
])
class
D
(
object
):
pass
class
D
(
object
):
pass
...
@@ -3526,7 +3576,7 @@ order (MRO) for bases """
...
@@ -3526,7 +3576,7 @@ order (MRO) for bases """
self
.
assertEqual
(
hasattr
(
m
,
"__name__"
),
0
)
self
.
assertEqual
(
hasattr
(
m
,
"__name__"
),
0
)
self
.
assertEqual
(
hasattr
(
m
,
"__file__"
),
0
)
self
.
assertEqual
(
hasattr
(
m
,
"__file__"
),
0
)
self
.
assertEqual
(
hasattr
(
m
,
"foo"
),
0
)
self
.
assertEqual
(
hasattr
(
m
,
"foo"
),
0
)
self
.
assert
Equal
(
m
.
__dict__
,
None
)
self
.
assert
False
(
m
.
__dict__
)
# None or {} are both reasonable answers
m
.
foo
=
1
m
.
foo
=
1
self
.
assertEqual
(
m
.
__dict__
,
{
"foo"
:
1
})
self
.
assertEqual
(
m
.
__dict__
,
{
"foo"
:
1
})
...
@@ -3661,17 +3711,23 @@ order (MRO) for bases """
...
@@ -3661,17 +3711,23 @@ order (MRO) for bases """
c
=
C
()
c
=
C
()
c
.
attr
=
42
c
.
attr
=
42
# The most interesting thing here is whether this blows up, due to flawed
# The most interesting thing here is whether this blows up, due to
# GC tracking logic in typeobject.c's call_finalizer() (a 2.2.1 bug).
# flawed GC tracking logic in typeobject.c's call_finalizer() (a 2.2.1
# bug).
del
c
del
c
# If that didn't blow up, it's also interesting to see whether clearing
# If that didn't blow up, it's also interesting to see whether clearing
# the last container slot works: that will attempt to delete c again,
# the last container slot works: that will attempt to delete c again,
# which will cause c to get appended back to the container again "during"
# which will cause c to get appended back to the container again
# the del.
# "during" the del. (On non-CPython implementations, however, __del__
del
C
.
container
[
-
1
]
# is typically not called again.)
test_support
.
gc_collect
()
self
.
assertEqual
(
len
(
C
.
container
),
1
)
self
.
assertEqual
(
len
(
C
.
container
),
1
)
self
.
assertEqual
(
C
.
container
[
-
1
]
.
attr
,
42
)
del
C
.
container
[
-
1
]
if
test_support
.
check_impl_detail
():
test_support
.
gc_collect
()
self
.
assertEqual
(
len
(
C
.
container
),
1
)
self
.
assertEqual
(
C
.
container
[
-
1
]
.
attr
,
42
)
# Make c mortal again, so that the test framework with -l doesn't report
# Make c mortal again, so that the test framework with -l doesn't report
# it as a leak.
# it as a leak.
...
@@ -3697,7 +3753,8 @@ order (MRO) for bases """
...
@@ -3697,7 +3753,8 @@ order (MRO) for bases """
pass
pass
class
C
(
A
,
B
)
:
class
C
(
A
,
B
)
:
__slots__
=
()
__slots__
=
()
self
.
assertEqual
(
C
.
__basicsize__
,
B
.
__basicsize__
)
if
test_support
.
check_impl_detail
():
self
.
assertEqual
(
C
.
__basicsize__
,
B
.
__basicsize__
)
self
.
assert_
(
hasattr
(
C
,
'__dict__'
))
self
.
assert_
(
hasattr
(
C
,
'__dict__'
))
self
.
assert_
(
hasattr
(
C
,
'__weakref__'
))
self
.
assert_
(
hasattr
(
C
,
'__weakref__'
))
C
()
.
x
=
2
C
()
.
x
=
2
...
@@ -3780,7 +3837,7 @@ order (MRO) for bases """
...
@@ -3780,7 +3837,7 @@ order (MRO) for bases """
try
:
try
:
del
D
.
__bases__
del
D
.
__bases__
except
TypeError
:
except
(
TypeError
,
AttributeError
)
:
pass
pass
else
:
else
:
self
.
fail
(
"shouldn't be able to delete .__bases__"
)
self
.
fail
(
"shouldn't be able to delete .__bases__"
)
...
@@ -3981,6 +4038,7 @@ order (MRO) for bases """
...
@@ -3981,6 +4038,7 @@ order (MRO) for bases """
self
.
assertEqual
(
E
()
//
C
(),
"C.__floordiv__"
)
self
.
assertEqual
(
E
()
//
C
(),
"C.__floordiv__"
)
self
.
assertEqual
(
C
()
//
E
(),
"C.__floordiv__"
)
# This one would fail
self
.
assertEqual
(
C
()
//
E
(),
"C.__floordiv__"
)
# This one would fail
@test_support.impl_detail
(
"testing an internal kind of method object"
)
def
test_meth_class_get
(
self
):
def
test_meth_class_get
(
self
):
# Testing __get__ method of METH_CLASS C methods...
# Testing __get__ method of METH_CLASS C methods...
# Full coverage of descrobject.c::classmethod_get()
# Full coverage of descrobject.c::classmethod_get()
...
@@ -4166,7 +4224,7 @@ order (MRO) for bases """
...
@@ -4166,7 +4224,7 @@ order (MRO) for bases """
self
.
assertEqual
(
c
.
attr
,
1
)
self
.
assertEqual
(
c
.
attr
,
1
)
# this makes a crash more likely:
# this makes a crash more likely:
import
gc
;
gc
.
collect
()
test_support
.
gc_
collect
()
self
.
assertEqual
(
hasattr
(
c
,
'attr'
),
False
)
self
.
assertEqual
(
hasattr
(
c
,
'attr'
),
False
)
def
test_init
(
self
):
def
test_init
(
self
):
...
@@ -4191,8 +4249,14 @@ order (MRO) for bases """
...
@@ -4191,8 +4249,14 @@ order (MRO) for bases """
self
.
assert_
(
l
.
__add__
!=
[
5
]
.
__add__
)
self
.
assert_
(
l
.
__add__
!=
[
5
]
.
__add__
)
self
.
assert_
(
l
.
__add__
!=
l
.
__mul__
)
self
.
assert_
(
l
.
__add__
!=
l
.
__mul__
)
self
.
assert_
(
l
.
__add__
.
__name__
==
'__add__'
)
self
.
assert_
(
l
.
__add__
.
__name__
==
'__add__'
)
self
.
assert_
(
l
.
__add__
.
__self__
is
l
)
if
hasattr
(
l
.
__add__
,
'__self__'
):
self
.
assert_
(
l
.
__add__
.
__objclass__
is
list
)
# CPython
self
.
assert_
(
l
.
__add__
.
__self__
is
l
)
self
.
assert_
(
l
.
__add__
.
__objclass__
is
list
)
else
:
# Python implementations where [].__add__ is a normal bound method
self
.
assert_
(
l
.
__add__
.
im_self
is
l
)
self
.
assert_
(
l
.
__add__
.
im_class
is
list
)
self
.
assertEqual
(
l
.
__add__
.
__doc__
,
list
.
__add__
.
__doc__
)
self
.
assertEqual
(
l
.
__add__
.
__doc__
,
list
.
__add__
.
__doc__
)
try
:
try
:
hash
(
l
.
__add__
)
hash
(
l
.
__add__
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment