Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
2731cebc
Commit
2731cebc
authored
Jun 30, 2011
by
Lars Buitinck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++ exceptions: test ios_base::failure and underflow_error
Also make bad_alloc test more reliable.
parent
390b35a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
11 deletions
+44
-11
tests/run/cpp_exceptions.pyx
tests/run/cpp_exceptions.pyx
+32
-9
tests/run/cpp_exceptions_helper.h
tests/run/cpp_exceptions_helper.h
+12
-2
No files found.
tests/run/cpp_exceptions.pyx
View file @
2731cebc
...
...
@@ -12,9 +12,11 @@ cdef extern from "cpp_exceptions_helper.h":
cdef
int
raise_index_value
"raise_index"
(
bint
fire
)
except
+
ValueError
cdef
int
raise_index_custom
"raise_index"
(
bint
fire
)
except
+
raise_py_error
cdef
void
raise_
arithmetic
"raise_arithmetic
"
()
except
+
cdef
void
raise_
ios_failure
"raise_ios_failure
"
()
except
+
cdef
void
raise_memory
"raise_memory"
()
except
+
cdef
void
raise_overflow
"raise_overflow"
()
except
+
cdef
void
raise_range_error
"raise_range_error"
()
except
+
cdef
void
raise_underflow
"raise_underflow"
()
except
+
cdef
cppclass
Foo
:
int
bar_raw
"bar"
(
bint
fire
)
except
+
...
...
@@ -22,25 +24,28 @@ cdef extern from "cpp_exceptions_helper.h":
int
bar_custom
"bar"
(
bint
fire
)
except
+
raise_py_error
def
test_
arithmetic
():
def
test_
ios_failure
():
"""
>>> test_
arithmetic
()
>>> test_
ios_failure
()
Traceback (most recent call last):
...
ArithmeticError: range_error
IOError: iostream failure
"""
raise_
arithmetic
()
raise_
ios_failure
()
# XXX The following error message is actually implementation-defined.
# This is the one from GCC/libstdc++ 4.4.5 on Linux.
def
test_memory
():
"""
>>> test_memory()
Traceback (most recent call last):
...
MemoryError
: std::bad_alloc
MemoryError
"""
raise_memory
()
# Re-raise the exception without a description string because we can't
# rely on the implementation-defined value of what() in the doctest.
try
:
raise_memory
()
except
MemoryError
:
raise
MemoryError
def
test_overflow
():
"""
...
...
@@ -51,6 +56,24 @@ def test_overflow():
"""
raise_overflow
()
def
test_range_error
():
"""
>>> test_range_error()
Traceback (most recent call last):
...
ArithmeticError: range_error
"""
raise_range_error
()
def
test_underflow
():
"""
>>> test_underflow()
Traceback (most recent call last):
...
ArithmeticError: underflow_error
"""
raise_underflow
()
def
test_int_raw
(
bint
fire
):
"""
>>> test_int_raw(False)
...
...
tests/run/cpp_exceptions_helper.h
View file @
2731cebc
#include <ios>
#include <new>
#include <stdexcept>
int
raise_int
(
int
fire
)
{
...
...
@@ -24,8 +26,8 @@ class Foo {
}
};
void
raise_
arithmetic
()
{
throw
std
::
range_error
(
"range_error
"
);
void
raise_
ios_failure
()
{
throw
std
::
ios_base
::
failure
(
"iostream failure
"
);
}
void
raise_memory
()
{
...
...
@@ -37,3 +39,11 @@ void raise_memory() {
void
raise_overflow
()
{
throw
std
::
overflow_error
(
"overflow_error"
);
}
void
raise_range_error
()
{
throw
std
::
range_error
(
"range_error"
);
}
void
raise_underflow
()
{
throw
std
::
underflow_error
(
"underflow_error"
);
}
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