Example #1
0
 def test_check_list(self) -> None:
     emitter = Emitter(self.context)
     generate_arg_check('x', ListRType(), emitter)
     lines = emitter.fragments
     assert lines == [
         'PyObject *arg_x;\n',
         'if (PyList_Check(obj_x))\n',
         '    arg_x = obj_x;\n',
         'else\n',
         '    return NULL;\n',
     ]
Example #2
0
 def test_check_int(self) -> None:
     emitter = Emitter(self.context)
     generate_arg_check('x', int_rprimitive, emitter)
     lines = emitter.fragments
     self.assert_lines([
         'CPyTagged arg_x;',
         'if (PyLong_Check(obj_x))',
         '    arg_x = CPyTagged_BorrowFromObject(obj_x);',
         'else {',
         '    PyErr_SetString(PyExc_TypeError, "int object expected");',
         '    return NULL;',
         '}',
     ], lines)
Example #3
0
 def test_check_list(self) -> None:
     emitter = Emitter(self.context)
     generate_arg_check('x', list_rprimitive, emitter)
     lines = emitter.fragments
     self.assert_lines([
         'PyObject *arg_x;',
         'if (PyList_Check(obj_x))',
         '    arg_x = obj_x;',
         'else {',
         '    PyErr_SetString(PyExc_TypeError, "list object expected");',
         '    arg_x = NULL;',
         '}',
         'if (arg_x == NULL) return NULL;',
     ], lines)
Example #4
0
 def test_check_list(self) -> None:
     emitter = Emitter(self.context)
     generate_arg_check('x', list_rprimitive, emitter, 'return NULL;')
     lines = emitter.fragments
     self.assert_lines([
         'PyObject *arg_x;',
         'if (likely(PyList_Check(obj_x)))',
         '    arg_x = obj_x;',
         'else {',
         '    CPy_TypeError("list", obj_x);',
         '    arg_x = NULL;',
         '}',
         'if (arg_x == NULL) return NULL;',
     ], lines)
Example #5
0
 def test_check_int(self) -> None:
     emitter = Emitter(self.context)
     generate_arg_check('x', int_rprimitive, emitter, 'return NULL;')
     generate_arg_check('y', int_rprimitive, emitter, 'return NULL;', True)
     lines = emitter.fragments
     self.assert_lines([
         'CPyTagged arg_x;',
         'if (likely(PyLong_Check(obj_x)))',
         '    arg_x = CPyTagged_BorrowFromObject(obj_x);',
         'else {',
         '    CPy_TypeError("int", obj_x);',
         '    return NULL;',
         '}',
         'CPyTagged arg_y;',
         'if (obj_y == NULL) {',
         '    arg_y = CPY_INT_TAG;',
         '} else if (likely(PyLong_Check(obj_y)))',
         '    arg_y = CPyTagged_BorrowFromObject(obj_y);',
         'else {',
         '    CPy_TypeError("int", obj_y);',
         '    return NULL;',
         '}',
     ], lines)