Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
153ac11a
Commit
153ac11a
authored
May 02, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some crazy exception tests
parent
5b407e21
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
13 deletions
+170
-13
test/tests/descriptors.py
test/tests/descriptors.py
+47
-13
test/tests/exceptions.py
test/tests/exceptions.py
+12
-0
test/tests/exceptions_nested.py
test/tests/exceptions_nested.py
+111
-0
No files found.
test/tests/descriptors.py
View file @
153ac11a
# expected: fail
# expected: fail
# - descriptors not implemented yet
# - descriptors not implemented yet
class
D
(
object
):
def
f1
():
class
D
(
object
):
def
__get__
(
self
,
instance
,
owner
):
def
__get__
(
self
,
instance
,
owner
):
print
"get"
,
instance
,
owner
print
"get"
,
instance
,
owner
return
1
return
1
...
@@ -9,12 +10,45 @@ class D(object):
...
@@ -9,12 +10,45 @@ class D(object):
def
__set__
(
self
,
instance
,
value
):
def
__set__
(
self
,
instance
,
value
):
print
"set"
,
instance
,
value
print
"set"
,
instance
,
value
class
C
(
object
):
class
C
(
object
):
d
=
D
()
d
=
D
()
print
C
.
d
print
C
.
d
print
C
().
d
print
C
().
d
c
=
C
()
c
=
C
()
c
.
d
=
2
c
.
d
=
2
print
c
.
d
print
c
.
d
f1
()
def
f2
():
class
MaybeDescriptorMeta
(
type
):
def
__getattribute__
(
self
,
attr
):
print
"meta __getattribute__"
,
attr
return
2
class
MaybeDescriptor
(
object
):
__metaclass__
=
MaybeDescriptorMeta
def
__getattribute__
(
self
,
attr
):
print
"__getattribute__"
,
attr
return
1
class
HasDescriptor
(
object
):
x
=
MaybeDescriptor
()
hd
=
HasDescriptor
()
# Getting hd.x will look up type(hd.__dict__[x]).__get__
# and not go through __getattribute__
print
hd
.
x
print
hd
.
x
.
__get__
print
type
(
hd
.
x
).
__get__
# But we can still set it here:
def
get
(
*
args
):
print
"get"
,
args
return
3
hd
.
x
.
__get__
=
get
print
hd
.
x
type
(
hd
.
x
).
__get__
=
get
print
hd
.
x
f2
()
test/tests/exceptions.py
0 → 100644
View file @
153ac11a
# expected: fail
# - exceptions
def
throw
(
x
):
try
:
raise
x
except
Exception
,
e
:
print
type
(
e
)
# Both print "Exception"
throw
(
Exception
)
throw
(
Exception
())
test/tests/exceptions_nested.py
0 → 100644
View file @
153ac11a
# expected: fail
# - exceptions
# Different ways of nesting exceptions
import
sys
def
f1
():
print
print
"f1"
# First make sure that xrange iterator really does raise StopIteration:
try
:
iter
(
xrange
(
0
)).
next
()
assert
0
except
StopIteration
:
print
sys
.
exc_info
()[
0
].
__name__
f1
()
def
f2
():
print
print
"f2"
try
:
raise
Exception
except
Exception
:
print
sys
.
exc_info
()[
0
].
__name__
# "Exception"
for
i
in
xrange
(
5
):
pass
print
sys
.
exc_info
()[
0
].
__name__
# "Exception", despite the implicit StopIteration that got raised
def
f
():
try
:
raise
StopIteration
()
except
:
pass
f
()
print
sys
.
exc_info
()[
0
].
__name__
# still "Exception"
def
f2
():
raise
StopIteration
()
def
f3
():
try
:
f2
()
except
StopIteration
:
pass
try
:
f3
()
except
:
pass
print
sys
.
exc_info
()[
0
].
__name__
# still "Exception", since the exception didn't get back up to this frame
try
:
f2
()
except
:
pass
print
sys
.
exc_info
()[
0
].
__name__
# "StopIteration"
f2
()
def
f2_2
():
try
:
raise
Exception
except
Exception
:
# These two look similar, but they have different
# exception-setting behavior:
for
n
in
xrange
(
5
):
print
n
,
sys
.
exc_info
()[
0
].
__name__
it
=
iter
(
xrange
(
5
))
while
True
:
try
:
n
=
it
.
next
()
except
StopIteration
:
break
print
n
,
sys
.
exc_info
()[
0
].
__name__
print
"done"
,
n
,
sys
.
exc_info
()[
0
].
__name__
f2_2
()
def
f3
():
print
print
"f3"
def
f
():
print
"getting the exc handler type"
raise
AssertionError
()
try
:
print
"in the first try"
# f() won't get evaluated until the exception is actually thrown:
try
:
print
"in the second try"
raise
Exception
()
except
f
():
print
"In the inner exception block??"
finally
:
# This will get called even though there was an exception in
# evaluating the exception-handler type:
print
"inner finally"
except
Exception
:
# This will print "AssertionError", from the f() call, *not* the Exception
# that was thrown in the inner try block.
print
"In the outer exception block:"
,
sys
.
exc_info
()[
0
].
__name__
finally
:
print
"outer finally"
f3
()
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