8000 gh-111495: Add tests for PyList C API by rawwar · Pull Request #111562 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111495: Add tests for PyList C API #111562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Nov 8, 2023
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
pr feedback fixes
Signed-off-by: kalyanr <kalyan.ben10@live.com>
  • Loading branch information
rawwar committed Nov 1, 2023
commit 0e340a129c6e66b8ba6c3c15b0ddbdd63c1b8706
18 changes: 15 additions & 3 deletions Lib/test/test_capi/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,33 @@ def test_list_get_item(self):
self.assertNotEqual(get_item(lst, 1), 12)
# CRASHES for out of index: get_item(lst, 3)
# CRASHES get_item(21, 2)
# CRASHES get_item(NULL, 0)
# CRASHES get_item(Null,1)


def test_list_setitem(self):
# Test PyList_SET_ITEM()
# Test PyList_SetItem()
setitem = _testcapi.list_setitem
lst = [1, 2, 3]
setitem(lst, 1, 10)
self.assertEqual(lst, [1, 10, 3])
self.assertEqual(lst[1], 10)
self.assertRaises(IndexError, setitem, [1], -1, 5)
self.assertRaises(TypeError, setitem, lst, 1.5, 10)
self.assertRaises(TypeError, setitem, 23, 'a', 5)
self.assertRaises(SystemError, setitem, {}, 0, 5)

# CRASHES setitem(NULL, 'a', 5)

def test_list_set_item(self):
# Test PyList_SET_ITEM()
set_item = _testcapi.list_set_item
lst = [1, 2, 3]
set_item(lst, 1, 10)
# self.assertEqual(lst[1], 10)
# self.assertRaises(IndexError, set_item, [1], -1, 5)
# self.assertRaises(TypeError, set_item, lst, 1.5, 10)
# self.assertRaises(TypeError, set_item, 23, 'a', 5)
# self.assertRaises(SystemError, set_item, {}, 0, 5)


def test_list_insert(self):
# Test PyList_Insert()
Expand Down
12 changes: 4 additions & 8 deletions Modules/_testcapi/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ list_setitem(PyObject *Py_UNUSED(module), PyObject *args)
}
NULLABLE(obj);
NULLABLE(value);
value = Py_XNewRef(value);
RETURN_INT(PyList_SetItem(obj, i, value));
RETURN_INT(PyList_SetItem(obj, i, Py_XNewRef(value)));

}

Expand All @@ -84,8 +83,7 @@ list_set_item(PyObject *Py_UNUSED(module), PyObject *args)
}
NULLABLE(obj);
NULLABLE(value);
value = Py_XNewRef(value);
PyList_SET_ITEM(obj, i, value);
PyList_SET_ITEM(obj, i, Py_XNewRef(value));
Py_RETURN_NONE;

}
Expand All @@ -100,8 +98,7 @@ list_insert(PyObject *Py_UNUSED(module), PyObject *args)
}
NULLABLE(obj);
NULLABLE(value);
value = Py_XNewRef(value);
RETURN_INT(PyList_Insert(obj, where, value));
RETURN_INT(PyList_Insert(obj, where, Py_XNewRef(value)));

}

Expand Down Expand Up @@ -140,8 +137,7 @@ list_setslice(PyObject *Py_UNUSED(module), PyObject *args)
}
NULLABLE(obj);
NULLABLE(value);
value = Py_XNewRef(value);
return PyList_SetSlice(obj, ilow, ihigh, value);
return PyList_SetSlice(obj, ilow, ihigh, Py_XNewRef(value));

}

Expand Down
0