Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d43d9b2
init test c file
rawwar Oct 31, 2023
119cd0e
single test added
rawwar Oct 31, 2023
ccf1bff
fix lint
rawwar Oct 31, 2023
8d17ca6
fix list check tests
rawwar Oct 31, 2023
bd9415d
lint
rawwar Oct 31, 2023
17d60d1
add 2 tests
rawwar Oct 31, 2023
322eab9
add test
rawwar Oct 31, 2023
5c58022
add getitem test
rawwar Oct 31, 2023
6b12f1f
test list_get_item
rawwar Oct 31, 2023
70e385f
add test for setitem
rawwar Oct 31, 2023
3166ba4
add test for setitem
rawwar Oct 31, 2023
2a50fb8
Merge branch 'kalyan/test-capi-list' of github.com:rawwar/cpython int…
rawwar Oct 31, 2023
1c30f3b
Merge branch 'main' of github.com:rawwar/cpython into kalyan/test-cap…
rawwar Nov 1, 2023
392b3c6
add tests
rawwar Nov 1, 2023
eac8c67
lint fix
rawwar Nov 1, 2023
0f40f6d
add tests
rawwar Nov 1, 2023
40e4022
Update Lib/test/test_capi/test_list.py
rawwar Nov 1, 2023
d31fa57
Update Modules/_testcapi/list.c
rawwar Nov 1, 2023
433351d
Update Lib/test/test_capi/test_list.py
rawwar Nov 1, 2023
34e915b
Update Lib/test/test_capi/test_list.py
rawwar Nov 1, 2023
0e340a1
pr feedback fixes
rawwar Nov 1, 2023
8de9cf8
fixes for the feedback
rawwar Nov 1, 2023
44dcf85
add tests from vstinner PR
rawwar Nov 1, 2023
1000126
Merge branch 'main' into kalyan/test-capi-list
rawwar Nov 1, 2023
2c6a41c
remove unused import
rawwar Nov 1, 2023
e486451
Update list.c
rawwar Nov 1, 2023
633951b
Merge branch 'main' into kalyan/test-capi-list
rawwar Nov 1, 2023
9afa50c
Merge branch 'main' into kalyan/test-capi-list
rawwar Nov 2, 2023
361b045
Merge branch 'main' into kalyan/test-capi-list
rawwar Nov 2, 2023
ca07ac9
Update Modules/_testcapi/list.c
vstinner Nov 8, 2023
dc039f1
Update Modules/_testcapi/list.c
vstinner Nov 8, 2023
5ecfa40
Merge branch 'main' into kalyan/test-capi-list
serhiy-storchaka Nov 8, 2023
42a2a54
Minor fixes.
serhiy-storchaka Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test for setitem
Signed-off-by: kalyanr <kalyan.ben10@live.com>
  • Loading branch information
rawwar committed Oct 31, 2023
commit 3166ba44bb6a176be161ce9a2434602982c337d7
14 changes: 14 additions & 0 deletions Lib/test/test_capi/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class ListSubclass(list):
...
Comment thread
rawwar marked this conversation as resolved.
Outdated


class CAPITest(unittest.TestCase):
def test_check(self):
# Test PyList_Check()
Comment thread
rawwar marked this conversation as resolved.
Expand Down Expand Up @@ -69,3 +70,16 @@ def test_list_get_item(self):

# CRASHES for out of index: get_item(lst, 3)
# CRASHES get_item(21, 2)


def test_list_setitem(self):
setitem = _testcapi.list_setitem
lst = [1, 2, 3]
setitem(lst, 1, 10)
self.assertEqual(lst[1], 10)
Comment thread
rawwar marked this conversation as resolved.
Outdated
self.assertRaises(IndexError, setitem, [1], -1, 5)
Comment thread
rawwar marked this conversation as resolved.
Outdated
self.assertRaises(TypeError, setitem, lst, 1.5, 10)
self.assertRaises(TypeError, setitem, 23, 'a', 5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only tests the wrapper, not the C API function.

self.assertRaises(SystemError, setitem, {}, 0, 5)

# CRASHES setitem(NULL, 'a', 5)
16 changes: 15 additions & 1 deletion Modules/_testcapi/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ list_get_item(PyObject *Py_UNUSED(module), PyObject *args)
return PyList_GET_ITEM(obj, i);
}

static PyObject *
list_setitem(PyObject *Py_UNUSED(module), PyObject *args)
{
PyObject *obj, *value;
Py_ssize_t i;
if ( !PyArg_ParseTuple(args, "OnO", &obj, &i, &value)){
return NULL;
}
NULLABLE(obj);
NULLABLE(value);
RETURN_INT(PyList_SetItem(obj, i, value));
Comment thread
rawwar marked this conversation as resolved.
Outdated

}


static PyMethodDef test_methods[] = {
{"list_check", list_check, METH_O},
Expand All @@ -60,7 +74,7 @@ static PyMethodDef test_methods[] = {
{"list_size", list_size, METH_O},
{"list_getitem", list_getitem, METH_VARARGS},
{"list_get_item", list_get_item, METH_VARARGS},
// {"list_setitem", list_setitem, METH_VARARGS},
{"list_setitem", list_setitem, METH_VARARGS},
// {"list_insert"},
// {"list_append"},
// {"list_get_slice"},
Expand Down