Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
19d34954
Commit
19d34954
authored
Nov 17, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19603: Use specific asserts in test_decr.
parent
76ae0226
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
168 additions
and
157 deletions
+168
-157
Lib/test/test_descr.py
Lib/test/test_descr.py
+168
-157
No files found.
Lib/test/test_descr.py
View file @
19d34954
...
@@ -388,13 +388,21 @@ class OperatorsTest(unittest.TestCase):
...
@@ -388,13 +388,21 @@ class OperatorsTest(unittest.TestCase):
class
ClassPropertiesAndMethods
(
unittest
.
TestCase
):
class
ClassPropertiesAndMethods
(
unittest
.
TestCase
):
def
assertHasAttr
(
self
,
obj
,
name
):
self
.
assertTrue
(
hasattr
(
obj
,
name
),
'%r has no attribute %r'
%
(
obj
,
name
))
def
assertNotHasAttr
(
self
,
obj
,
name
):
self
.
assertFalse
(
hasattr
(
obj
,
name
),
'%r has unexpected attribute %r'
%
(
obj
,
name
))
def
test_python_dicts
(
self
):
def
test_python_dicts
(
self
):
# Testing Python subclass of dict...
# Testing Python subclass of dict...
self
.
assertTrue
(
issubclass
(
dict
,
dict
))
self
.
assertTrue
(
issubclass
(
dict
,
dict
))
self
.
assertIsInstance
({},
dict
)
self
.
assertIsInstance
({},
dict
)
d
=
dict
()
d
=
dict
()
self
.
assertEqual
(
d
,
{})
self
.
assertEqual
(
d
,
{})
self
.
assert
True
(
d
.
__class__
is
dict
)
self
.
assert
Is
(
d
.
__class__
,
dict
)
self
.
assertIsInstance
(
d
,
dict
)
self
.
assertIsInstance
(
d
,
dict
)
class
C
(
dict
):
class
C
(
dict
):
state
=
-
1
state
=
-
1
...
@@ -572,7 +580,7 @@ class ClassPropertiesAndMethods(unittest.TestCase):
...
@@ -572,7 +580,7 @@ class ClassPropertiesAndMethods(unittest.TestCase):
def
_set_x
(
self
,
x
):
def
_set_x
(
self
,
x
):
self
.
__x
=
-
x
self
.
__x
=
-
x
a
=
A
()
a
=
A
()
self
.
assert
True
(
not
hasattr
(
a
,
"x"
)
)
self
.
assert
NotHasAttr
(
a
,
"x"
)
a
.
x
=
12
a
.
x
=
12
self
.
assertEqual
(
a
.
x
,
12
)
self
.
assertEqual
(
a
.
x
,
12
)
self
.
assertEqual
(
a
.
_A__x
,
-
12
)
self
.
assertEqual
(
a
.
_A__x
,
-
12
)
...
@@ -998,14 +1006,14 @@ order (MRO) for bases """
...
@@ -998,14 +1006,14 @@ order (MRO) for bases """
self
.
assertEqual
(
type
(
a
),
object
)
self
.
assertEqual
(
type
(
a
),
object
)
b
=
object
()
b
=
object
()
self
.
assertNotEqual
(
a
,
b
)
self
.
assertNotEqual
(
a
,
b
)
self
.
assert
False
(
hasattr
(
a
,
"foo"
)
)
self
.
assert
NotHasAttr
(
a
,
"foo"
)
try
:
try
:
a
.
foo
=
12
a
.
foo
=
12
except
(
AttributeError
,
TypeError
):
except
(
AttributeError
,
TypeError
):
pass
pass
else
:
else
:
self
.
fail
(
"object() should not allow setting a foo attribute"
)
self
.
fail
(
"object() should not allow setting a foo attribute"
)
self
.
assert
False
(
hasattr
(
object
(),
"__dict__"
)
)
self
.
assert
NotHasAttr
(
object
(),
"__dict__"
)
class
Cdict
(
object
):
class
Cdict
(
object
):
pass
pass
...
@@ -1020,28 +1028,28 @@ order (MRO) for bases """
...
@@ -1020,28 +1028,28 @@ order (MRO) for bases """
class
C0
(
object
):
class
C0
(
object
):
__slots__
=
[]
__slots__
=
[]
x
=
C0
()
x
=
C0
()
self
.
assert
False
(
hasattr
(
x
,
"__dict__"
)
)
self
.
assert
NotHasAttr
(
x
,
"__dict__"
)
self
.
assert
False
(
hasattr
(
x
,
"foo"
)
)
self
.
assert
NotHasAttr
(
x
,
"foo"
)
class
C1
(
object
):
class
C1
(
object
):
__slots__
=
[
'a'
]
__slots__
=
[
'a'
]
x
=
C1
()
x
=
C1
()
self
.
assert
False
(
hasattr
(
x
,
"__dict__"
)
)
self
.
assert
NotHasAttr
(
x
,
"__dict__"
)
self
.
assert
False
(
hasattr
(
x
,
"a"
)
)
self
.
assert
NotHasAttr
(
x
,
"a"
)
x
.
a
=
1
x
.
a
=
1
self
.
assertEqual
(
x
.
a
,
1
)
self
.
assertEqual
(
x
.
a
,
1
)
x
.
a
=
None
x
.
a
=
None
self
.
assertEqual
(
x
.
a
,
None
)
self
.
assertEqual
(
x
.
a
,
None
)
del
x
.
a
del
x
.
a
self
.
assert
False
(
hasattr
(
x
,
"a"
)
)
self
.
assert
NotHasAttr
(
x
,
"a"
)
class
C3
(
object
):
class
C3
(
object
):
__slots__
=
[
'a'
,
'b'
,
'c'
]
__slots__
=
[
'a'
,
'b'
,
'c'
]
x
=
C3
()
x
=
C3
()
self
.
assert
False
(
hasattr
(
x
,
"__dict__"
)
)
self
.
assert
NotHasAttr
(
x
,
"__dict__"
)
self
.
assert
False
(
hasattr
(
x
,
'a'
)
)
self
.
assert
NotHasAttr
(
x
,
'a'
)
self
.
assert
False
(
hasattr
(
x
,
'b'
)
)
self
.
assert
NotHasAttr
(
x
,
'b'
)
self
.
assert
False
(
hasattr
(
x
,
'c'
)
)
self
.
assert
NotHasAttr
(
x
,
'c'
)
x
.
a
=
1
x
.
a
=
1
x
.
b
=
2
x
.
b
=
2
x
.
c
=
3
x
.
c
=
3
...
@@ -1057,8 +1065,8 @@ order (MRO) for bases """
...
@@ -1057,8 +1065,8 @@ order (MRO) for bases """
def
get
(
self
):
def
get
(
self
):
return
self
.
__a
return
self
.
__a
x
=
C4
(
5
)
x
=
C4
(
5
)
self
.
assert
False
(
hasattr
(
x
,
'__dict__'
)
)
self
.
assert
NotHasAttr
(
x
,
'__dict__'
)
self
.
assert
False
(
hasattr
(
x
,
'__a'
)
)
self
.
assert
NotHasAttr
(
x
,
'__a'
)
self
.
assertEqual
(
x
.
get
(),
5
)
self
.
assertEqual
(
x
.
get
(),
5
)
try
:
try
:
x
.
__a
=
6
x
.
__a
=
6
...
@@ -1130,7 +1138,7 @@ order (MRO) for bases """
...
@@ -1130,7 +1138,7 @@ order (MRO) for bases """
x
=
C
()
x
=
C
()
x
.
foo
=
5
x
.
foo
=
5
self
.
assertEqual
(
x
.
foo
,
5
)
self
.
assertEqual
(
x
.
foo
,
5
)
self
.
assert
True
(
type
(
slots
[
0
])
is
str
)
self
.
assert
Is
(
type
(
slots
[
0
]),
str
)
# this used to leak references
# this used to leak references
try
:
try
:
class
C
(
object
):
class
C
(
object
):
...
@@ -1222,16 +1230,16 @@ order (MRO) for bases """
...
@@ -1222,16 +1230,16 @@ order (MRO) for bases """
class
D
(
object
):
class
D
(
object
):
__slots__
=
[
"__dict__"
]
__slots__
=
[
"__dict__"
]
a
=
D
()
a
=
D
()
self
.
assert
True
(
hasattr
(
a
,
"__dict__"
)
)
self
.
assert
HasAttr
(
a
,
"__dict__"
)
self
.
assert
False
(
hasattr
(
a
,
"__weakref__"
)
)
self
.
assert
NotHasAttr
(
a
,
"__weakref__"
)
a
.
foo
=
42
a
.
foo
=
42
self
.
assertEqual
(
a
.
__dict__
,
{
"foo"
:
42
})
self
.
assertEqual
(
a
.
__dict__
,
{
"foo"
:
42
})
class
W
(
object
):
class
W
(
object
):
__slots__
=
[
"__weakref__"
]
__slots__
=
[
"__weakref__"
]
a
=
W
()
a
=
W
()
self
.
assert
True
(
hasattr
(
a
,
"__weakref__"
)
)
self
.
assert
HasAttr
(
a
,
"__weakref__"
)
self
.
assert
False
(
hasattr
(
a
,
"__dict__"
)
)
self
.
assert
NotHasAttr
(
a
,
"__dict__"
)
try
:
try
:
a
.
foo
=
42
a
.
foo
=
42
except
AttributeError
:
except
AttributeError
:
...
@@ -1242,16 +1250,16 @@ order (MRO) for bases """
...
@@ -1242,16 +1250,16 @@ order (MRO) for bases """
class
C1
(
W
,
D
):
class
C1
(
W
,
D
):
__slots__
=
[]
__slots__
=
[]
a
=
C1
()
a
=
C1
()
self
.
assert
True
(
hasattr
(
a
,
"__dict__"
)
)
self
.
assert
HasAttr
(
a
,
"__dict__"
)
self
.
assert
True
(
hasattr
(
a
,
"__weakref__"
)
)
self
.
assert
HasAttr
(
a
,
"__weakref__"
)
a
.
foo
=
42
a
.
foo
=
42
self
.
assertEqual
(
a
.
__dict__
,
{
"foo"
:
42
})
self
.
assertEqual
(
a
.
__dict__
,
{
"foo"
:
42
})
class
C2
(
D
,
W
):
class
C2
(
D
,
W
):
__slots__
=
[]
__slots__
=
[]
a
=
C2
()
a
=
C2
()
self
.
assert
True
(
hasattr
(
a
,
"__dict__"
)
)
self
.
assert
HasAttr
(
a
,
"__dict__"
)
self
.
assert
True
(
hasattr
(
a
,
"__weakref__"
)
)
self
.
assert
HasAttr
(
a
,
"__weakref__"
)
a
.
foo
=
42
a
.
foo
=
42
self
.
assertEqual
(
a
.
__dict__
,
{
"foo"
:
42
})
self
.
assertEqual
(
a
.
__dict__
,
{
"foo"
:
42
})
...
@@ -1289,7 +1297,7 @@ order (MRO) for bases """
...
@@ -1289,7 +1297,7 @@ order (MRO) for bases """
class
C
(
object
):
class
C
(
object
):
pass
pass
a
=
C
()
a
=
C
()
self
.
assert
False
(
hasattr
(
a
,
"foobar"
)
)
self
.
assert
NotHasAttr
(
a
,
"foobar"
)
C
.
foobar
=
2
C
.
foobar
=
2
self
.
assertEqual
(
a
.
foobar
,
2
)
self
.
assertEqual
(
a
.
foobar
,
2
)
C
.
method
=
lambda
self
:
42
C
.
method
=
lambda
self
:
42
...
@@ -1299,7 +1307,7 @@ order (MRO) for bases """
...
@@ -1299,7 +1307,7 @@ order (MRO) for bases """
C
.
__int__
=
lambda
self
:
100
C
.
__int__
=
lambda
self
:
100
self
.
assertEqual
(
int
(
a
),
100
)
self
.
assertEqual
(
int
(
a
),
100
)
self
.
assertEqual
(
a
.
foobar
,
2
)
self
.
assertEqual
(
a
.
foobar
,
2
)
self
.
assert
False
(
hasattr
(
a
,
"spam"
)
)
self
.
assert
NotHasAttr
(
a
,
"spam"
)
def
mygetattr
(
self
,
name
):
def
mygetattr
(
self
,
name
):
if
name
==
"spam"
:
if
name
==
"spam"
:
return
"spam"
return
"spam"
...
@@ -1450,7 +1458,7 @@ order (MRO) for bases """
...
@@ -1450,7 +1458,7 @@ order (MRO) for bases """
self
.
assertEqual
(
cm
.
x
,
42
)
self
.
assertEqual
(
cm
.
x
,
42
)
self
.
assertEqual
(
cm
.
__dict__
,
{
"x"
:
42
})
self
.
assertEqual
(
cm
.
__dict__
,
{
"x"
:
42
})
del
cm
.
x
del
cm
.
x
self
.
assert
False
(
hasattr
(
cm
,
"x"
)
)
self
.
assert
NotHasAttr
(
cm
,
"x"
)
@
support
.
impl_detail
(
"the module 'xxsubtype' is internal"
)
@
support
.
impl_detail
(
"the module 'xxsubtype' is internal"
)
def
test_classmethods_in_c
(
self
):
def
test_classmethods_in_c
(
self
):
...
@@ -1505,7 +1513,7 @@ order (MRO) for bases """
...
@@ -1505,7 +1513,7 @@ order (MRO) for bases """
self
.
assertEqual
(
sm
.
x
,
42
)
self
.
assertEqual
(
sm
.
x
,
42
)
self
.
assertEqual
(
sm
.
__dict__
,
{
"x"
:
42
})
self
.
assertEqual
(
sm
.
__dict__
,
{
"x"
:
42
})
del
sm
.
x
del
sm
.
x
self
.
assert
False
(
hasattr
(
sm
,
"x"
)
)
self
.
assert
NotHasAttr
(
sm
,
"x"
)
@
support
.
impl_detail
(
"the module 'xxsubtype' is internal"
)
@
support
.
impl_detail
(
"the module 'xxsubtype' is internal"
)
def
test_staticmethods_in_c
(
self
):
def
test_staticmethods_in_c
(
self
):
...
@@ -1575,7 +1583,7 @@ order (MRO) for bases """
...
@@ -1575,7 +1583,7 @@ order (MRO) for bases """
self
.
assertEqual
(
a
.
x
,
10
)
self
.
assertEqual
(
a
.
x
,
10
)
self
.
assertEqual
(
a
.
x
,
11
)
self
.
assertEqual
(
a
.
x
,
11
)
del
a
.
x
del
a
.
x
self
.
assert
Equal
(
hasattr
(
a
,
'x'
),
0
)
self
.
assert
NotHasAttr
(
a
,
'x'
)
def
test_newslots
(
self
):
def
test_newslots
(
self
):
# Testing __new__ slot override...
# Testing __new__ slot override...
...
@@ -1845,17 +1853,17 @@ order (MRO) for bases """
...
@@ -1845,17 +1853,17 @@ order (MRO) for bases """
raise
IndexError
raise
IndexError
c1
=
C
()
c1
=
C
()
c2
=
C
()
c2
=
C
()
self
.
assert
True
(
not
not
c1
)
# What?
self
.
assert
False
(
not
c1
)
self
.
assertNotEqual
(
id
(
c1
),
id
(
c2
))
self
.
assertNotEqual
(
id
(
c1
),
id
(
c2
))
hash
(
c1
)
hash
(
c1
)
hash
(
c2
)
hash
(
c2
)
self
.
assertEqual
(
c1
,
c1
)
self
.
assertEqual
(
c1
,
c1
)
self
.
assertTrue
(
c1
!=
c2
)
self
.
assertTrue
(
c1
!=
c2
)
self
.
assert
True
(
not
c1
!=
c1
)
self
.
assert
False
(
c1
!=
c1
)
self
.
assert
True
(
not
c1
==
c2
)
self
.
assert
False
(
c1
==
c2
)
# Note that the module name appears in str/repr, and that varies
# Note that the module name appears in str/repr, and that varies
# depending on whether this test is run standalone or from a framework.
# depending on whether this test is run standalone or from a framework.
self
.
assert
True
(
str
(
c1
).
find
(
'C object at '
)
>=
0
)
self
.
assert
GreaterEqual
(
str
(
c1
).
find
(
'C object at '
),
0
)
self
.
assertEqual
(
str
(
c1
),
repr
(
c1
))
self
.
assertEqual
(
str
(
c1
),
repr
(
c1
))
self
.
assertNotIn
(
-
1
,
c1
)
self
.
assertNotIn
(
-
1
,
c1
)
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
@@ -1868,17 +1876,17 @@ order (MRO) for bases """
...
@@ -1868,17 +1876,17 @@ order (MRO) for bases """
raise
IndexError
raise
IndexError
d1
=
D
()
d1
=
D
()
d2
=
D
()
d2
=
D
()
self
.
assert
True
(
not
not
d1
)
self
.
assert
False
(
not
d1
)
self
.
assertNotEqual
(
id
(
d1
),
id
(
d2
))
self
.
assertNotEqual
(
id
(
d1
),
id
(
d2
))
hash
(
d1
)
hash
(
d1
)
hash
(
d2
)
hash
(
d2
)
self
.
assertEqual
(
d1
,
d1
)
self
.
assertEqual
(
d1
,
d1
)
self
.
assertNotEqual
(
d1
,
d2
)
self
.
assertNotEqual
(
d1
,
d2
)
self
.
assert
True
(
not
d1
!=
d1
)
self
.
assert
False
(
d1
!=
d1
)
self
.
assert
True
(
not
d1
==
d2
)
self
.
assert
False
(
d1
==
d2
)
# Note that the module name appears in str/repr, and that varies
# Note that the module name appears in str/repr, and that varies
# depending on whether this test is run standalone or from a framework.
# depending on whether this test is run standalone or from a framework.
self
.
assert
True
(
str
(
d1
).
find
(
'D object at '
)
>=
0
)
self
.
assert
GreaterEqual
(
str
(
d1
).
find
(
'D object at '
),
0
)
self
.
assertEqual
(
str
(
d1
),
repr
(
d1
))
self
.
assertEqual
(
str
(
d1
),
repr
(
d1
))
self
.
assertNotIn
(
-
1
,
d1
)
self
.
assertNotIn
(
-
1
,
d1
)
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
@@ -1914,11 +1922,11 @@ order (MRO) for bases """
...
@@ -1914,11 +1922,11 @@ order (MRO) for bases """
p1
=
Proxy
(
1
)
p1
=
Proxy
(
1
)
p_1
=
Proxy
(
-
1
)
p_1
=
Proxy
(
-
1
)
self
.
assertFalse
(
p0
)
self
.
assertFalse
(
p0
)
self
.
assert
True
(
not
not
p1
)
self
.
assert
False
(
not
p1
)
self
.
assertEqual
(
hash
(
p0
),
hash
(
0
))
self
.
assertEqual
(
hash
(
p0
),
hash
(
0
))
self
.
assertEqual
(
p0
,
p0
)
self
.
assertEqual
(
p0
,
p0
)
self
.
assertNotEqual
(
p0
,
p1
)
self
.
assertNotEqual
(
p0
,
p1
)
self
.
assert
True
(
not
p0
!=
p0
)
self
.
assert
False
(
p0
!=
p0
)
self
.
assertEqual
(
not
p0
,
p1
)
self
.
assertEqual
(
not
p0
,
p1
)
self
.
assertTrue
(
p0
<
p1
)
self
.
assertTrue
(
p0
<
p1
)
self
.
assertTrue
(
p0
<=
p1
)
self
.
assertTrue
(
p0
<=
p1
)
...
@@ -1950,7 +1958,7 @@ order (MRO) for bases """
...
@@ -1950,7 +1958,7 @@ order (MRO) for bases """
try
:
try
:
weakref
.
ref
(
no
)
weakref
.
ref
(
no
)
except
TypeError
as
msg
:
except
TypeError
as
msg
:
self
.
assert
True
(
str
(
msg
).
find
(
"weak reference"
)
>=
0
)
self
.
assert
In
(
"weak reference"
,
str
(
msg
)
)
else
:
else
:
self
.
fail
(
"weakref.ref(no) should be illegal"
)
self
.
fail
(
"weakref.ref(no) should be illegal"
)
class
Weak
(
object
):
class
Weak
(
object
):
...
@@ -1974,17 +1982,17 @@ order (MRO) for bases """
...
@@ -1974,17 +1982,17 @@ order (MRO) for bases """
del
self
.
__x
del
self
.
__x
x
=
property
(
getx
,
setx
,
delx
,
doc
=
"I'm the x property."
)
x
=
property
(
getx
,
setx
,
delx
,
doc
=
"I'm the x property."
)
a
=
C
()
a
=
C
()
self
.
assert
False
(
hasattr
(
a
,
"x"
)
)
self
.
assert
NotHasAttr
(
a
,
"x"
)
a
.
x
=
42
a
.
x
=
42
self
.
assertEqual
(
a
.
_C__x
,
42
)
self
.
assertEqual
(
a
.
_C__x
,
42
)
self
.
assertEqual
(
a
.
x
,
42
)
self
.
assertEqual
(
a
.
x
,
42
)
del
a
.
x
del
a
.
x
self
.
assert
False
(
hasattr
(
a
,
"x"
)
)
self
.
assert
NotHasAttr
(
a
,
"x"
)
self
.
assert
False
(
hasattr
(
a
,
"_C__x"
)
)
self
.
assert
NotHasAttr
(
a
,
"_C__x"
)
C
.
x
.
__set__
(
a
,
100
)
C
.
x
.
__set__
(
a
,
100
)
self
.
assertEqual
(
C
.
x
.
__get__
(
a
),
100
)
self
.
assertEqual
(
C
.
x
.
__get__
(
a
),
100
)
C
.
x
.
__delete__
(
a
)
C
.
x
.
__delete__
(
a
)
self
.
assert
False
(
hasattr
(
a
,
"x"
)
)
self
.
assert
NotHasAttr
(
a
,
"x"
)
raw
=
C
.
__dict__
[
'x'
]
raw
=
C
.
__dict__
[
'x'
]
self
.
assertIsInstance
(
raw
,
property
)
self
.
assertIsInstance
(
raw
,
property
)
...
@@ -1996,9 +2004,9 @@ order (MRO) for bases """
...
@@ -1996,9 +2004,9 @@ order (MRO) for bases """
self
.
assertIn
(
"fdel"
,
attrs
)
self
.
assertIn
(
"fdel"
,
attrs
)
self
.
assertEqual
(
raw
.
__doc__
,
"I'm the x property."
)
self
.
assertEqual
(
raw
.
__doc__
,
"I'm the x property."
)
self
.
assert
True
(
raw
.
fget
is
C
.
__dict__
[
'getx'
])
self
.
assert
Is
(
raw
.
fget
,
C
.
__dict__
[
'getx'
])
self
.
assert
True
(
raw
.
fset
is
C
.
__dict__
[
'setx'
])
self
.
assert
Is
(
raw
.
fset
,
C
.
__dict__
[
'setx'
])
self
.
assert
True
(
raw
.
fdel
is
C
.
__dict__
[
'delx'
])
self
.
assert
Is
(
raw
.
fdel
,
C
.
__dict__
[
'delx'
])
for
attr
in
"__doc__"
,
"fget"
,
"fset"
,
"fdel"
:
for
attr
in
"__doc__"
,
"fget"
,
"fset"
,
"fdel"
:
try
:
try
:
...
@@ -2062,14 +2070,14 @@ order (MRO) for bases """
...
@@ -2062,14 +2070,14 @@ order (MRO) for bases """
del
self
.
_foo
del
self
.
_foo
c
=
C
()
c
=
C
()
self
.
assertEqual
(
C
.
foo
.
__doc__
,
"hello"
)
self
.
assertEqual
(
C
.
foo
.
__doc__
,
"hello"
)
self
.
assert
False
(
hasattr
(
c
,
"foo"
)
)
self
.
assert
NotHasAttr
(
c
,
"foo"
)
c
.
foo
=
-
42
c
.
foo
=
-
42
self
.
assert
True
(
hasattr
(
c
,
'_foo'
)
)
self
.
assert
HasAttr
(
c
,
'_foo'
)
self
.
assertEqual
(
c
.
_foo
,
42
)
self
.
assertEqual
(
c
.
_foo
,
42
)
self
.
assertEqual
(
c
.
foo
,
42
)
self
.
assertEqual
(
c
.
foo
,
42
)
del
c
.
foo
del
c
.
foo
self
.
assert
False
(
hasattr
(
c
,
'_foo'
)
)
self
.
assert
NotHasAttr
(
c
,
'_foo'
)
self
.
assert
False
(
hasattr
(
c
,
"foo"
)
)
self
.
assert
NotHasAttr
(
c
,
"foo"
)
class
D
(
C
):
class
D
(
C
):
@
C
.
foo
.
deleter
@
C
.
foo
.
deleter
...
@@ -2421,13 +2429,13 @@ order (MRO) for bases """
...
@@ -2421,13 +2429,13 @@ order (MRO) for bases """
a
=
hexint
(
12345
)
a
=
hexint
(
12345
)
self
.
assertEqual
(
a
,
12345
)
self
.
assertEqual
(
a
,
12345
)
self
.
assertEqual
(
int
(
a
),
12345
)
self
.
assertEqual
(
int
(
a
),
12345
)
self
.
assert
True
(
int
(
a
).
__class__
is
int
)
self
.
assert
Is
(
int
(
a
).
__class__
,
int
)
self
.
assertEqual
(
hash
(
a
),
hash
(
12345
))
self
.
assertEqual
(
hash
(
a
),
hash
(
12345
))
self
.
assert
True
((
+
a
).
__class__
is
int
)
self
.
assert
Is
((
+
a
).
__class__
,
int
)
self
.
assert
True
((
a
>>
0
).
__class__
is
int
)
self
.
assert
Is
((
a
>>
0
).
__class__
,
int
)
self
.
assert
True
((
a
<<
0
).
__class__
is
int
)
self
.
assert
Is
((
a
<<
0
).
__class__
,
int
)
self
.
assert
True
((
hexint
(
0
)
<<
12
).
__class__
is
int
)
self
.
assert
Is
((
hexint
(
0
)
<<
12
).
__class__
,
int
)
self
.
assert
True
((
hexint
(
0
)
>>
12
).
__class__
is
int
)
self
.
assert
Is
((
hexint
(
0
)
>>
12
).
__class__
,
int
)
class
octlong
(
int
):
class
octlong
(
int
):
__slots__
=
[]
__slots__
=
[]
...
@@ -2444,31 +2452,31 @@ order (MRO) for bases """
...
@@ -2444,31 +2452,31 @@ order (MRO) for bases """
self
.
assertEqual
(
a
,
12345
)
self
.
assertEqual
(
a
,
12345
)
self
.
assertEqual
(
int
(
a
),
12345
)
self
.
assertEqual
(
int
(
a
),
12345
)
self
.
assertEqual
(
hash
(
a
),
hash
(
12345
))
self
.
assertEqual
(
hash
(
a
),
hash
(
12345
))
self
.
assert
True
(
int
(
a
).
__class__
is
int
)
self
.
assert
Is
(
int
(
a
).
__class__
,
int
)
self
.
assert
True
((
+
a
).
__class__
is
int
)
self
.
assert
Is
((
+
a
).
__class__
,
int
)
self
.
assert
True
((
-
a
).
__class__
is
int
)
self
.
assert
Is
((
-
a
).
__class__
,
int
)
self
.
assert
True
((
-
octlong
(
0
)).
__class__
is
int
)
self
.
assert
Is
((
-
octlong
(
0
)).
__class__
,
int
)
self
.
assert
True
((
a
>>
0
).
__class__
is
int
)
self
.
assert
Is
((
a
>>
0
).
__class__
,
int
)
self
.
assert
True
((
a
<<
0
).
__class__
is
int
)
self
.
assert
Is
((
a
<<
0
).
__class__
,
int
)
self
.
assert
True
((
a
-
0
).
__class__
is
int
)
self
.
assert
Is
((
a
-
0
).
__class__
,
int
)
self
.
assert
True
((
a
*
1
).
__class__
is
int
)
self
.
assert
Is
((
a
*
1
).
__class__
,
int
)
self
.
assert
True
((
a
**
1
).
__class__
is
int
)
self
.
assert
Is
((
a
**
1
).
__class__
,
int
)
self
.
assert
True
((
a
//
1
).
__class__
is
int
)
self
.
assert
Is
((
a
//
1
).
__class__
,
int
)
self
.
assert
True
((
1
*
a
).
__class__
is
int
)
self
.
assert
Is
((
1
*
a
).
__class__
,
int
)
self
.
assert
True
((
a
|
0
).
__class__
is
int
)
self
.
assert
Is
((
a
|
0
).
__class__
,
int
)
self
.
assert
True
((
a
^
0
).
__class__
is
int
)
self
.
assert
Is
((
a
^
0
).
__class__
,
int
)
self
.
assert
True
((
a
&
-
1
).
__class__
is
int
)
self
.
assert
Is
((
a
&
-
1
).
__class__
,
int
)
self
.
assert
True
((
octlong
(
0
)
<<
12
).
__class__
is
int
)
self
.
assert
Is
((
octlong
(
0
)
<<
12
).
__class__
,
int
)
self
.
assert
True
((
octlong
(
0
)
>>
12
).
__class__
is
int
)
self
.
assert
Is
((
octlong
(
0
)
>>
12
).
__class__
,
int
)
self
.
assert
True
(
abs
(
octlong
(
0
)).
__class__
is
int
)
self
.
assert
Is
(
abs
(
octlong
(
0
)).
__class__
,
int
)
# Because octlong overrides __add__, we can't check the absence of +0
# Because octlong overrides __add__, we can't check the absence of +0
# optimizations using octlong.
# optimizations using octlong.
class
longclone
(
int
):
class
longclone
(
int
):
pass
pass
a
=
longclone
(
1
)
a
=
longclone
(
1
)
self
.
assert
True
((
a
+
0
).
__class__
is
int
)
self
.
assert
Is
((
a
+
0
).
__class__
,
int
)
self
.
assert
True
((
0
+
a
).
__class__
is
int
)
self
.
assert
Is
((
0
+
a
).
__class__
,
int
)
# Check that negative clones don't segfault
# Check that negative clones don't segfault
a
=
longclone
(
-
1
)
a
=
longclone
(
-
1
)
...
@@ -2485,9 +2493,9 @@ order (MRO) for bases """
...
@@ -2485,9 +2493,9 @@ order (MRO) for bases """
a
=
precfloat
(
12345
)
a
=
precfloat
(
12345
)
self
.
assertEqual
(
a
,
12345.0
)
self
.
assertEqual
(
a
,
12345.0
)
self
.
assertEqual
(
float
(
a
),
12345.0
)
self
.
assertEqual
(
float
(
a
),
12345.0
)
self
.
assert
True
(
float
(
a
).
__class__
is
float
)
self
.
assert
Is
(
float
(
a
).
__class__
,
float
)
self
.
assertEqual
(
hash
(
a
),
hash
(
12345.0
))
self
.
assertEqual
(
hash
(
a
),
hash
(
12345.0
))
self
.
assert
True
((
+
a
).
__class__
is
float
)
self
.
assert
Is
((
+
a
).
__class__
,
float
)
class
madcomplex
(
complex
):
class
madcomplex
(
complex
):
def
__repr__
(
self
):
def
__repr__
(
self
):
...
@@ -2535,20 +2543,20 @@ order (MRO) for bases """
...
@@ -2535,20 +2543,20 @@ order (MRO) for bases """
self
.
assertEqual
(
v
,
t
)
self
.
assertEqual
(
v
,
t
)
a
=
madtuple
((
1
,
2
,
3
,
4
,
5
))
a
=
madtuple
((
1
,
2
,
3
,
4
,
5
))
self
.
assertEqual
(
tuple
(
a
),
(
1
,
2
,
3
,
4
,
5
))
self
.
assertEqual
(
tuple
(
a
),
(
1
,
2
,
3
,
4
,
5
))
self
.
assert
True
(
tuple
(
a
).
__class__
is
tuple
)
self
.
assert
Is
(
tuple
(
a
).
__class__
,
tuple
)
self
.
assertEqual
(
hash
(
a
),
hash
((
1
,
2
,
3
,
4
,
5
)))
self
.
assertEqual
(
hash
(
a
),
hash
((
1
,
2
,
3
,
4
,
5
)))
self
.
assert
True
(
a
[:].
__class__
is
tuple
)
self
.
assert
Is
(
a
[:].
__class__
,
tuple
)
self
.
assert
True
((
a
*
1
).
__class__
is
tuple
)
self
.
assert
Is
((
a
*
1
).
__class__
,
tuple
)
self
.
assert
True
((
a
*
0
).
__class__
is
tuple
)
self
.
assert
Is
((
a
*
0
).
__class__
,
tuple
)
self
.
assert
True
((
a
+
()).
__class__
is
tuple
)
self
.
assert
Is
((
a
+
()).
__class__
,
tuple
)
a
=
madtuple
(())
a
=
madtuple
(())
self
.
assertEqual
(
tuple
(
a
),
())
self
.
assertEqual
(
tuple
(
a
),
())
self
.
assert
True
(
tuple
(
a
).
__class__
is
tuple
)
self
.
assert
Is
(
tuple
(
a
).
__class__
,
tuple
)
self
.
assert
True
((
a
+
a
).
__class__
is
tuple
)
self
.
assert
Is
((
a
+
a
).
__class__
,
tuple
)
self
.
assert
True
((
a
*
0
).
__class__
is
tuple
)
self
.
assert
Is
((
a
*
0
).
__class__
,
tuple
)
self
.
assert
True
((
a
*
1
).
__class__
is
tuple
)
self
.
assert
Is
((
a
*
1
).
__class__
,
tuple
)
self
.
assert
True
((
a
*
2
).
__class__
is
tuple
)
self
.
assert
Is
((
a
*
2
).
__class__
,
tuple
)
self
.
assert
True
(
a
[:].
__class__
is
tuple
)
self
.
assert
Is
(
a
[:].
__class__
,
tuple
)
class
madstring
(
str
):
class
madstring
(
str
):
_rev
=
None
_rev
=
None
...
@@ -2570,48 +2578,48 @@ order (MRO) for bases """
...
@@ -2570,48 +2578,48 @@ order (MRO) for bases """
self
.
assertEqual
(
u
,
s
)
self
.
assertEqual
(
u
,
s
)
s
=
madstring
(
"12345"
)
s
=
madstring
(
"12345"
)
self
.
assertEqual
(
str
(
s
),
"12345"
)
self
.
assertEqual
(
str
(
s
),
"12345"
)
self
.
assert
True
(
str
(
s
).
__class__
is
str
)
self
.
assert
Is
(
str
(
s
).
__class__
,
str
)
base
=
"
\
x00
"
*
5
base
=
"
\
x00
"
*
5
s
=
madstring
(
base
)
s
=
madstring
(
base
)
self
.
assertEqual
(
s
,
base
)
self
.
assertEqual
(
s
,
base
)
self
.
assertEqual
(
str
(
s
),
base
)
self
.
assertEqual
(
str
(
s
),
base
)
self
.
assert
True
(
str
(
s
).
__class__
is
str
)
self
.
assert
Is
(
str
(
s
).
__class__
,
str
)
self
.
assertEqual
(
hash
(
s
),
hash
(
base
))
self
.
assertEqual
(
hash
(
s
),
hash
(
base
))
self
.
assertEqual
({
s
:
1
}[
base
],
1
)
self
.
assertEqual
({
s
:
1
}[
base
],
1
)
self
.
assertEqual
({
base
:
1
}[
s
],
1
)
self
.
assertEqual
({
base
:
1
}[
s
],
1
)
self
.
assert
True
((
s
+
""
).
__class__
is
str
)
self
.
assert
Is
((
s
+
""
).
__class__
,
str
)
self
.
assertEqual
(
s
+
""
,
base
)
self
.
assertEqual
(
s
+
""
,
base
)
self
.
assert
True
((
""
+
s
).
__class__
is
str
)
self
.
assert
Is
((
""
+
s
).
__class__
,
str
)
self
.
assertEqual
(
""
+
s
,
base
)
self
.
assertEqual
(
""
+
s
,
base
)
self
.
assert
True
((
s
*
0
).
__class__
is
str
)
self
.
assert
Is
((
s
*
0
).
__class__
,
str
)
self
.
assertEqual
(
s
*
0
,
""
)
self
.
assertEqual
(
s
*
0
,
""
)
self
.
assert
True
((
s
*
1
).
__class__
is
str
)
self
.
assert
Is
((
s
*
1
).
__class__
,
str
)
self
.
assertEqual
(
s
*
1
,
base
)
self
.
assertEqual
(
s
*
1
,
base
)
self
.
assert
True
((
s
*
2
).
__class__
is
str
)
self
.
assert
Is
((
s
*
2
).
__class__
,
str
)
self
.
assertEqual
(
s
*
2
,
base
+
base
)
self
.
assertEqual
(
s
*
2
,
base
+
base
)
self
.
assert
True
(
s
[:].
__class__
is
str
)
self
.
assert
Is
(
s
[:].
__class__
,
str
)
self
.
assertEqual
(
s
[:],
base
)
self
.
assertEqual
(
s
[:],
base
)
self
.
assert
True
(
s
[
0
:
0
].
__class__
is
str
)
self
.
assert
Is
(
s
[
0
:
0
].
__class__
,
str
)
self
.
assertEqual
(
s
[
0
:
0
],
""
)
self
.
assertEqual
(
s
[
0
:
0
],
""
)
self
.
assert
True
(
s
.
strip
().
__class__
is
str
)
self
.
assert
Is
(
s
.
strip
().
__class__
,
str
)
self
.
assertEqual
(
s
.
strip
(),
base
)
self
.
assertEqual
(
s
.
strip
(),
base
)
self
.
assert
True
(
s
.
lstrip
().
__class__
is
str
)
self
.
assert
Is
(
s
.
lstrip
().
__class__
,
str
)
self
.
assertEqual
(
s
.
lstrip
(),
base
)
self
.
assertEqual
(
s
.
lstrip
(),
base
)
self
.
assert
True
(
s
.
rstrip
().
__class__
is
str
)
self
.
assert
Is
(
s
.
rstrip
().
__class__
,
str
)
self
.
assertEqual
(
s
.
rstrip
(),
base
)
self
.
assertEqual
(
s
.
rstrip
(),
base
)
identitytab
=
{}
identitytab
=
{}
self
.
assert
True
(
s
.
translate
(
identitytab
).
__class__
is
str
)
self
.
assert
Is
(
s
.
translate
(
identitytab
).
__class__
,
str
)
self
.
assertEqual
(
s
.
translate
(
identitytab
),
base
)
self
.
assertEqual
(
s
.
translate
(
identitytab
),
base
)
self
.
assert
True
(
s
.
replace
(
"x"
,
"x"
).
__class__
is
str
)
self
.
assert
Is
(
s
.
replace
(
"x"
,
"x"
).
__class__
,
str
)
self
.
assertEqual
(
s
.
replace
(
"x"
,
"x"
),
base
)
self
.
assertEqual
(
s
.
replace
(
"x"
,
"x"
),
base
)
self
.
assert
True
(
s
.
ljust
(
len
(
s
)).
__class__
is
str
)
self
.
assert
Is
(
s
.
ljust
(
len
(
s
)).
__class__
,
str
)
self
.
assertEqual
(
s
.
ljust
(
len
(
s
)),
base
)
self
.
assertEqual
(
s
.
ljust
(
len
(
s
)),
base
)
self
.
assert
True
(
s
.
rjust
(
len
(
s
)).
__class__
is
str
)
self
.
assert
Is
(
s
.
rjust
(
len
(
s
)).
__class__
,
str
)
self
.
assertEqual
(
s
.
rjust
(
len
(
s
)),
base
)
self
.
assertEqual
(
s
.
rjust
(
len
(
s
)),
base
)
self
.
assert
True
(
s
.
center
(
len
(
s
)).
__class__
is
str
)
self
.
assert
Is
(
s
.
center
(
len
(
s
)).
__class__
,
str
)
self
.
assertEqual
(
s
.
center
(
len
(
s
)),
base
)
self
.
assertEqual
(
s
.
center
(
len
(
s
)),
base
)
self
.
assert
True
(
s
.
lower
().
__class__
is
str
)
self
.
assert
Is
(
s
.
lower
().
__class__
,
str
)
self
.
assertEqual
(
s
.
lower
(),
base
)
self
.
assertEqual
(
s
.
lower
(),
base
)
class
madunicode
(
str
):
class
madunicode
(
str
):
...
@@ -2630,47 +2638,47 @@ order (MRO) for bases """
...
@@ -2630,47 +2638,47 @@ order (MRO) for bases """
base
=
"12345"
base
=
"12345"
u
=
madunicode
(
base
)
u
=
madunicode
(
base
)
self
.
assertEqual
(
str
(
u
),
base
)
self
.
assertEqual
(
str
(
u
),
base
)
self
.
assert
True
(
str
(
u
).
__class__
is
str
)
self
.
assert
Is
(
str
(
u
).
__class__
,
str
)
self
.
assertEqual
(
hash
(
u
),
hash
(
base
))
self
.
assertEqual
(
hash
(
u
),
hash
(
base
))
self
.
assertEqual
({
u
:
1
}[
base
],
1
)
self
.
assertEqual
({
u
:
1
}[
base
],
1
)
self
.
assertEqual
({
base
:
1
}[
u
],
1
)
self
.
assertEqual
({
base
:
1
}[
u
],
1
)
self
.
assert
True
(
u
.
strip
().
__class__
is
str
)
self
.
assert
Is
(
u
.
strip
().
__class__
,
str
)
self
.
assertEqual
(
u
.
strip
(),
base
)
self
.
assertEqual
(
u
.
strip
(),
base
)
self
.
assert
True
(
u
.
lstrip
().
__class__
is
str
)
self
.
assert
Is
(
u
.
lstrip
().
__class__
,
str
)
self
.
assertEqual
(
u
.
lstrip
(),
base
)
self
.
assertEqual
(
u
.
lstrip
(),
base
)
self
.
assert
True
(
u
.
rstrip
().
__class__
is
str
)
self
.
assert
Is
(
u
.
rstrip
().
__class__
,
str
)
self
.
assertEqual
(
u
.
rstrip
(),
base
)
self
.
assertEqual
(
u
.
rstrip
(),
base
)
self
.
assert
True
(
u
.
replace
(
"x"
,
"x"
).
__class__
is
str
)
self
.
assert
Is
(
u
.
replace
(
"x"
,
"x"
).
__class__
,
str
)
self
.
assertEqual
(
u
.
replace
(
"x"
,
"x"
),
base
)
self
.
assertEqual
(
u
.
replace
(
"x"
,
"x"
),
base
)
self
.
assert
True
(
u
.
replace
(
"xy"
,
"xy"
).
__class__
is
str
)
self
.
assert
Is
(
u
.
replace
(
"xy"
,
"xy"
).
__class__
,
str
)
self
.
assertEqual
(
u
.
replace
(
"xy"
,
"xy"
),
base
)
self
.
assertEqual
(
u
.
replace
(
"xy"
,
"xy"
),
base
)
self
.
assert
True
(
u
.
center
(
len
(
u
)).
__class__
is
str
)
self
.
assert
Is
(
u
.
center
(
len
(
u
)).
__class__
,
str
)
self
.
assertEqual
(
u
.
center
(
len
(
u
)),
base
)
self
.
assertEqual
(
u
.
center
(
len
(
u
)),
base
)
self
.
assert
True
(
u
.
ljust
(
len
(
u
)).
__class__
is
str
)
self
.
assert
Is
(
u
.
ljust
(
len
(
u
)).
__class__
,
str
)
self
.
assertEqual
(
u
.
ljust
(
len
(
u
)),
base
)
self
.
assertEqual
(
u
.
ljust
(
len
(
u
)),
base
)
self
.
assert
True
(
u
.
rjust
(
len
(
u
)).
__class__
is
str
)
self
.
assert
Is
(
u
.
rjust
(
len
(
u
)).
__class__
,
str
)
self
.
assertEqual
(
u
.
rjust
(
len
(
u
)),
base
)
self
.
assertEqual
(
u
.
rjust
(
len
(
u
)),
base
)
self
.
assert
True
(
u
.
lower
().
__class__
is
str
)
self
.
assert
Is
(
u
.
lower
().
__class__
,
str
)
self
.
assertEqual
(
u
.
lower
(),
base
)
self
.
assertEqual
(
u
.
lower
(),
base
)
self
.
assert
True
(
u
.
upper
().
__class__
is
str
)
self
.
assert
Is
(
u
.
upper
().
__class__
,
str
)
self
.
assertEqual
(
u
.
upper
(),
base
)
self
.
assertEqual
(
u
.
upper
(),
base
)
self
.
assert
True
(
u
.
capitalize
().
__class__
is
str
)
self
.
assert
Is
(
u
.
capitalize
().
__class__
,
str
)
self
.
assertEqual
(
u
.
capitalize
(),
base
)
self
.
assertEqual
(
u
.
capitalize
(),
base
)
self
.
assert
True
(
u
.
title
().
__class__
is
str
)
self
.
assert
Is
(
u
.
title
().
__class__
,
str
)
self
.
assertEqual
(
u
.
title
(),
base
)
self
.
assertEqual
(
u
.
title
(),
base
)
self
.
assert
True
((
u
+
""
).
__class__
is
str
)
self
.
assert
Is
((
u
+
""
).
__class__
,
str
)
self
.
assertEqual
(
u
+
""
,
base
)
self
.
assertEqual
(
u
+
""
,
base
)
self
.
assert
True
((
""
+
u
).
__class__
is
str
)
self
.
assert
Is
((
""
+
u
).
__class__
,
str
)
self
.
assertEqual
(
""
+
u
,
base
)
self
.
assertEqual
(
""
+
u
,
base
)
self
.
assert
True
((
u
*
0
).
__class__
is
str
)
self
.
assert
Is
((
u
*
0
).
__class__
,
str
)
self
.
assertEqual
(
u
*
0
,
""
)
self
.
assertEqual
(
u
*
0
,
""
)
self
.
assert
True
((
u
*
1
).
__class__
is
str
)
self
.
assert
Is
((
u
*
1
).
__class__
,
str
)
self
.
assertEqual
(
u
*
1
,
base
)
self
.
assertEqual
(
u
*
1
,
base
)
self
.
assert
True
((
u
*
2
).
__class__
is
str
)
self
.
assert
Is
((
u
*
2
).
__class__
,
str
)
self
.
assertEqual
(
u
*
2
,
base
+
base
)
self
.
assertEqual
(
u
*
2
,
base
+
base
)
self
.
assert
True
(
u
[:].
__class__
is
str
)
self
.
assert
Is
(
u
[:].
__class__
,
str
)
self
.
assertEqual
(
u
[:],
base
)
self
.
assertEqual
(
u
[:],
base
)
self
.
assert
True
(
u
[
0
:
0
].
__class__
is
str
)
self
.
assert
Is
(
u
[
0
:
0
].
__class__
,
str
)
self
.
assertEqual
(
u
[
0
:
0
],
""
)
self
.
assertEqual
(
u
[
0
:
0
],
""
)
class
sublist
(
list
):
class
sublist
(
list
):
...
@@ -2846,13 +2854,13 @@ order (MRO) for bases """
...
@@ -2846,13 +2854,13 @@ order (MRO) for bases """
for
x
in
1
,
2
,
3
:
for
x
in
1
,
2
,
3
:
for
y
in
1
,
2
,
3
:
for
y
in
1
,
2
,
3
:
for
op
in
"<"
,
"<="
,
"=="
,
"!="
,
">"
,
">="
:
for
op
in
"<"
,
"<="
,
"=="
,
"!="
,
">"
,
">="
:
self
.
assert
True
(
eval
(
"c[x] %s c[y]"
%
op
)
==
self
.
assert
Equal
(
eval
(
"c[x] %s c[y]"
%
op
),
eval
(
"x %s y"
%
op
),
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
"x=%d, y=%d"
%
(
x
,
y
))
self
.
assert
True
(
eval
(
"c[x] %s y"
%
op
)
==
self
.
assert
Equal
(
eval
(
"c[x] %s y"
%
op
),
eval
(
"x %s y"
%
op
),
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
"x=%d, y=%d"
%
(
x
,
y
))
self
.
assert
True
(
eval
(
"x %s c[y]"
%
op
)
==
self
.
assert
Equal
(
eval
(
"x %s c[y]"
%
op
),
eval
(
"x %s y"
%
op
),
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
"x=%d, y=%d"
%
(
x
,
y
))
...
@@ -2925,12 +2933,15 @@ order (MRO) for bases """
...
@@ -2925,12 +2933,15 @@ order (MRO) for bases """
for
x
in
1
,
2
,
3
:
for
x
in
1
,
2
,
3
:
for
y
in
1
,
2
,
3
:
for
y
in
1
,
2
,
3
:
for
op
in
"<"
,
"<="
,
"=="
,
"!="
,
">"
,
">="
:
for
op
in
"<"
,
"<="
,
"=="
,
"!="
,
">"
,
">="
:
self
.
assertTrue
(
eval
(
"c[x] %s c[y]"
%
op
)
==
eval
(
"x %s y"
%
op
),
self
.
assertEqual
(
eval
(
"c[x] %s c[y]"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
eval
(
"x %s y"
%
op
),
self
.
assertTrue
(
eval
(
"c[x] %s y"
%
op
)
==
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
"x=%d, y=%d"
%
(
x
,
y
))
self
.
assertEqual
(
eval
(
"c[x] %s y"
%
op
),
self
.
assertTrue
(
eval
(
"x %s c[y]"
%
op
)
==
eval
(
"x %s y"
%
op
),
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
"x=%d, y=%d"
%
(
x
,
y
))
self
.
assertEqual
(
eval
(
"x %s c[y]"
%
op
),
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
def
test_descrdoc
(
self
):
def
test_descrdoc
(
self
):
# Testing descriptor doc strings...
# Testing descriptor doc strings...
...
@@ -2969,9 +2980,9 @@ order (MRO) for bases """
...
@@ -2969,9 +2980,9 @@ order (MRO) for bases """
for
cls2
in
C
,
D
,
E
,
F
:
for
cls2
in
C
,
D
,
E
,
F
:
x
=
cls
()
x
=
cls
()
x
.
__class__
=
cls2
x
.
__class__
=
cls2
self
.
assert
True
(
x
.
__class__
is
cls2
)
self
.
assert
Is
(
x
.
__class__
,
cls2
)
x
.
__class__
=
cls
x
.
__class__
=
cls
self
.
assert
True
(
x
.
__class__
is
cls
)
self
.
assert
Is
(
x
.
__class__
,
cls
)
def
cant
(
x
,
C
):
def
cant
(
x
,
C
):
try
:
try
:
x
.
__class__
=
C
x
.
__class__
=
C
...
@@ -3027,11 +3038,11 @@ order (MRO) for bases """
...
@@ -3027,11 +3038,11 @@ order (MRO) for bases """
x
=
cls
()
x
=
cls
()
x
.
a
=
1
x
.
a
=
1
x
.
__class__
=
cls2
x
.
__class__
=
cls2
self
.
assert
True
(
x
.
__class__
is
cls2
,
self
.
assert
Is
(
x
.
__class__
,
cls2
,
"assigning %r as __class__ for %r silently failed"
%
(
cls2
,
x
))
"assigning %r as __class__ for %r silently failed"
%
(
cls2
,
x
))
self
.
assertEqual
(
x
.
a
,
1
)
self
.
assertEqual
(
x
.
a
,
1
)
x
.
__class__
=
cls
x
.
__class__
=
cls
self
.
assert
True
(
x
.
__class__
is
cls
,
self
.
assert
Is
(
x
.
__class__
,
cls
,
"assigning %r as __class__ for %r silently failed"
%
(
cls
,
x
))
"assigning %r as __class__ for %r silently failed"
%
(
cls
,
x
))
self
.
assertEqual
(
x
.
a
,
1
)
self
.
assertEqual
(
x
.
a
,
1
)
for
cls
in
G
,
J
,
K
,
L
,
M
,
N
,
P
,
R
,
list
,
Int
:
for
cls
in
G
,
J
,
K
,
L
,
M
,
N
,
P
,
R
,
list
,
Int
:
...
@@ -3200,7 +3211,7 @@ order (MRO) for bases """
...
@@ -3200,7 +3211,7 @@ order (MRO) for bases """
for
cls
in
C
,
C1
,
C2
:
for
cls
in
C
,
C1
,
C2
:
s
=
pickle
.
dumps
(
cls
,
bin
)
s
=
pickle
.
dumps
(
cls
,
bin
)
cls2
=
pickle
.
loads
(
s
)
cls2
=
pickle
.
loads
(
s
)
self
.
assert
True
(
cls2
is
cls
)
self
.
assert
Is
(
cls2
,
cls
)
a
=
C1
(
1
,
2
);
a
.
append
(
42
);
a
.
append
(
24
)
a
=
C1
(
1
,
2
);
a
.
append
(
42
);
a
.
append
(
24
)
b
=
C2
(
"hello"
,
"world"
,
42
)
b
=
C2
(
"hello"
,
"world"
,
42
)
...
@@ -3230,7 +3241,7 @@ order (MRO) for bases """
...
@@ -3230,7 +3241,7 @@ order (MRO) for bases """
import
copy
import
copy
for
cls
in
C
,
C1
,
C2
:
for
cls
in
C
,
C1
,
C2
:
cls2
=
copy
.
deepcopy
(
cls
)
cls2
=
copy
.
deepcopy
(
cls
)
self
.
assert
True
(
cls2
is
cls
)
self
.
assert
Is
(
cls2
,
cls
)
a
=
C1
(
1
,
2
);
a
.
append
(
42
);
a
.
append
(
24
)
a
=
C1
(
1
,
2
);
a
.
append
(
42
);
a
.
append
(
24
)
b
=
C2
(
"hello"
,
"world"
,
42
)
b
=
C2
(
"hello"
,
"world"
,
42
)
...
@@ -3290,7 +3301,7 @@ order (MRO) for bases """
...
@@ -3290,7 +3301,7 @@ order (MRO) for bases """
# Now it should work
# Now it should work
x
=
C
()
x
=
C
()
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
self
.
assert
Equal
(
hasattr
(
y
,
'a'
),
0
)
self
.
assert
NotHasAttr
(
y
,
'a'
)
x
.
a
=
42
x
.
a
=
42
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
y
=
pickle
.
loads
(
pickle
.
dumps
(
x
))
self
.
assertEqual
(
y
.
a
,
42
)
self
.
assertEqual
(
y
.
a
,
42
)
...
@@ -3590,9 +3601,9 @@ order (MRO) for bases """
...
@@ -3590,9 +3601,9 @@ order (MRO) for bases """
from
types
import
ModuleType
as
M
from
types
import
ModuleType
as
M
m
=
M
.
__new__
(
M
)
m
=
M
.
__new__
(
M
)
str
(
m
)
str
(
m
)
self
.
assert
Equal
(
hasattr
(
m
,
"__name__"
),
0
)
self
.
assert
NotHasAttr
(
m
,
"__name__"
)
self
.
assert
Equal
(
hasattr
(
m
,
"__file__"
),
0
)
self
.
assert
NotHasAttr
(
m
,
"__file__"
)
self
.
assert
Equal
(
hasattr
(
m
,
"foo"
),
0
)
self
.
assert
NotHasAttr
(
m
,
"foo"
)
self
.
assertFalse
(
m
.
__dict__
)
# None or {} are both reasonable answers
self
.
assertFalse
(
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
})
...
@@ -3772,8 +3783,8 @@ order (MRO) for bases """
...
@@ -3772,8 +3783,8 @@ order (MRO) for bases """
__slots__
=
()
__slots__
=
()
if
support
.
check_impl_detail
():
if
support
.
check_impl_detail
():
self
.
assertEqual
(
C
.
__basicsize__
,
B
.
__basicsize__
)
self
.
assertEqual
(
C
.
__basicsize__
,
B
.
__basicsize__
)
self
.
assert
True
(
hasattr
(
C
,
'__dict__'
)
)
self
.
assert
HasAttr
(
C
,
'__dict__'
)
self
.
assert
True
(
hasattr
(
C
,
'__weakref__'
)
)
self
.
assert
HasAttr
(
C
,
'__weakref__'
)
C
().
x
=
2
C
().
x
=
2
def
test_rmul
(
self
):
def
test_rmul
(
self
):
...
@@ -4251,7 +4262,7 @@ order (MRO) for bases """
...
@@ -4251,7 +4262,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:
support
.
gc_collect
()
support
.
gc_collect
()
self
.
assert
Equal
(
hasattr
(
c
,
'attr'
),
False
)
self
.
assert
NotHasAttr
(
c
,
'attr'
)
def
test_init
(
self
):
def
test_init
(
self
):
# SF 1155938
# SF 1155938
...
@@ -4274,17 +4285,17 @@ order (MRO) for bases """
...
@@ -4274,17 +4285,17 @@ order (MRO) for bases """
l
=
[]
l
=
[]
self
.
assertEqual
(
l
.
__add__
,
l
.
__add__
)
self
.
assertEqual
(
l
.
__add__
,
l
.
__add__
)
self
.
assertEqual
(
l
.
__add__
,
[].
__add__
)
self
.
assertEqual
(
l
.
__add__
,
[].
__add__
)
self
.
assert
True
(
l
.
__add__
!=
[
5
].
__add__
)
self
.
assert
NotEqual
(
l
.
__add__
,
[
5
].
__add__
)
self
.
assert
True
(
l
.
__add__
!=
l
.
__mul__
)
self
.
assert
NotEqual
(
l
.
__add__
,
l
.
__mul__
)
self
.
assert
True
(
l
.
__add__
.
__name__
==
'__add__'
)
self
.
assert
Equal
(
l
.
__add__
.
__name__
,
'__add__'
)
if
hasattr
(
l
.
__add__
,
'__self__'
):
if
hasattr
(
l
.
__add__
,
'__self__'
):
# CPython
# CPython
self
.
assert
True
(
l
.
__add__
.
__self__
is
l
)
self
.
assert
Is
(
l
.
__add__
.
__self__
,
l
)
self
.
assert
True
(
l
.
__add__
.
__objclass__
is
list
)
self
.
assert
Is
(
l
.
__add__
.
__objclass__
,
list
)
else
:
else
:
# Python implementations where [].__add__ is a normal bound method
# Python implementations where [].__add__ is a normal bound method
self
.
assert
True
(
l
.
__add__
.
im_self
is
l
)
self
.
assert
Is
(
l
.
__add__
.
im_self
,
l
)
self
.
assert
True
(
l
.
__add__
.
im_class
is
list
)
self
.
assert
Is
(
l
.
__add__
.
im_class
,
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__
)
...
@@ -4451,7 +4462,7 @@ order (MRO) for bases """
...
@@ -4451,7 +4462,7 @@ order (MRO) for bases """
fake_str
=
FakeStr
()
fake_str
=
FakeStr
()
# isinstance() reads __class__
# isinstance() reads __class__
self
.
assert
True
(
isinstance
(
fake_str
,
str
)
)
self
.
assert
IsInstance
(
fake_str
,
str
)
# call a method descriptor
# call a method descriptor
with
self
.
assertRaises
(
TypeError
):
with
self
.
assertRaises
(
TypeError
):
...
...
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