Skip to content

Commit 70f757b

Browse files
committed
added exceptions tests
1 parent ede3c74 commit 70f757b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

errors.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn C.PyErr_Format(&C.PyObject, &char, ) &C.PyObject
2222
pub fn C.PyErr_FormatV(&C.PyObject, &char, &C.va_list) &C.PyObject
2323
pub fn C.PyErr_SetImportErrorSubclass(&C.PyObject, &C.PyObject, &C.PyObject, &C.PyObject) &C.PyObject
2424
pub fn C.PyErr_SetImportError(&C.PyObject, &C.PyObject, &C.PyObject) &C.PyObject
25+
pub fn C.PyErr_NewException(&char, &C.PyObject, &C.PyObject) &C.PyObject
2526
pub fn C.PyErr_NewExceptionWithDoc(&char, &char, &C.PyObject, &C.PyObject) &C.PyObject
2627
pub fn C.PyErr_WriteUnraisable(&C.PyObject)
2728
pub fn C.PyErr_SetInterrupt()

exceptions_test.v

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,25 @@ fn testsuite_begin() {
66
}
77

88
fn testsuite_end() {
9+
}
10+
11+
fn test_exc_new_text() {
12+
exc := C.PyErr_NewException(c'mymodule.TestException', C.NULL, C.NULL)
13+
assert exc.ptr() != C.NULL
14+
C.Py_XDECREF(exc)
15+
}
16+
17+
fn test_exc_new_with_doc() {
18+
exc := C.PyErr_NewExceptionWithDoc(c'mymodule.TestException', c'docstring', C.NULL, C.NULL)
19+
assert exc.ptr() != C.NULL
20+
C.Py_XDECREF(exc)
21+
}
22+
23+
fn test_exc_set_context() {
24+
exc := C.PyErr_NewException(c'mymodule.TestException', C.NULL, C.NULL)
25+
assert exc.ptr() != C.NULL
26+
defer { C.Py_XDECREF(exc) }
27+
C.PyException_SetContext(exc, C.PyExc_BufferError)
28+
ctx := C.PyException_GetContext(exc)
29+
assert ctx.ptr() == C.PyExc_BufferError
930
}

0 commit comments

Comments
 (0)