Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f00bb03
Support functional test for Argument Clinic
colorfulappl Aug 22, 2022
a59e304
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 22, 2022
2bd331e
Revert "Support functional test for Argument Clinic"
colorfulappl Aug 23, 2022
fac5b77
Add functional test for Argument Clinic
colorfulappl Aug 23, 2022
962434c
Add testcases written in C
colorfulappl Aug 23, 2022
b93b2ae
Rename _testclinicfunctionality.c to _testclinic.c
colorfulappl Oct 25, 2022
35c5f13
Add _testclinic to stdlib IGNORE list
colorfulappl Oct 25, 2022
86703de
Merge TestClinicFunctionalityC class into TestClinicFunctionality
colorfulappl Oct 25, 2022
e66d60b
Format code in _testclinic.c
colorfulappl Oct 25, 2022
f1fb377
Merge test_clinic_functionality.py into test_clinic.py
colorfulappl Oct 26, 2022
449c8fe
Simplify testcases
colorfulappl Oct 26, 2022
1553574
Merge branch 'main' into test_clinic_functionality
colorfulappl Oct 26, 2022
81fe77b
Add more testcases
colorfulappl Oct 28, 2022
7c269d0
Rename class TestClinicFunctionality to ClinicFunctionalTest
colorfulappl Nov 1, 2022
a3a3455
Fix UB problem
colorfulappl Nov 2, 2022
80ba71a
Fix refleaks
colorfulappl Nov 4, 2022
cf77785
Clean code
colorfulappl Nov 4, 2022
10ce3c7
Add PoC of GH-99233
colorfulappl Nov 8, 2022
2cc6c0a
Add PoC of GH-99240
colorfulappl Nov 8, 2022
6a2d334
Delete test cases which fail this test
colorfulappl Nov 10, 2022
d82ef72
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 10, 2022
b27b43d
Rerun `make regen-all`
colorfulappl Nov 10, 2022
1cae160
Fix leaking
colorfulappl Nov 13, 2022
fb6d3be
Fix code style
colorfulappl Nov 13, 2022
fd1ed14
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 13, 2022
e82c88a
Rerun `make regen-all`
colorfulappl Nov 13, 2022
598568c
Fix object leaking and code style
colorfulappl Nov 14, 2022
dd43f24
Change argument release order
colorfulappl Nov 14, 2022
325e35b
Rename macro
colorfulappl Nov 14, 2022
967dda6
Update news
colorfulappl Nov 14, 2022
d568683
Fix object leaking
colorfulappl Nov 14, 2022
ce337e8
Remove unnecessary logic
colorfulappl Nov 15, 2022
3314465
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 15, 2022
68277c5
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 15, 2022
da0789f
Merge branch 'main' into test_clinic_functionality
colorfulappl Nov 17, 2022
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
Fix code style
  • Loading branch information
colorfulappl committed Nov 13, 2022
commit fb6d3be51c3abd92967557db63f0d166148ba94e
44 changes: 22 additions & 22 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,36 +837,36 @@ def test_objects_converter(self):
def test_bytes_object_converter(self):
with self.assertRaises(TypeError):
ac_tester.bytes_object_converter(1)
self.assertEqual(ac_tester.bytes_object_converter(b'BytesObject'), (b'BytesObject', ))
self.assertEqual(ac_tester.bytes_object_converter(b'BytesObject'), (b'BytesObject',))

def test_byte_array_object_converter(self):
with self.assertRaises(TypeError):
ac_tester.byte_array_object_converter(1)
byte_arr = bytearray(b'ByteArrayObject')
self.assertEqual(ac_tester.byte_array_object_converter(byte_arr), (byte_arr, ))
self.assertEqual(ac_tester.byte_array_object_converter(byte_arr), (byte_arr,))

def test_unicode_converter(self):
with self.assertRaises(TypeError):
ac_tester.unicode_converter(1)
self.assertEqual(ac_tester.unicode_converter('unicode'), ('unicode', ))
self.assertEqual(ac_tester.unicode_converter('unicode'), ('unicode',))

def test_bool_converter(self):
with self.assertRaises(TypeError):
ac_tester.bool_converter(False, False, 'not a int')
self.assertEqual(ac_tester.bool_converter(), (True, True, True))
self.assertEqual(ac_tester.bool_converter('', [], 5), (False, False, True))
self.assertEqual(ac_tester.bool_converter(('not empty', ), {1: 2}, 0), (True, True, False))
self.assertEqual(ac_tester.bool_converter(('not empty',), {1: 2}, 0), (True, True, False))

def test_char_converter(self):
with self.assertRaises(TypeError):
ac_tester.char_converter(1)
with self.assertRaises(TypeError):
ac_tester.char_converter(b'ab')
chars = [b'A', b'\a', b'\b', b'\t', b'\n', b'\v', b'\f', b'\r', b'"', b"'", b'?', b'\\', b'\000', b'\377']
expected = tuple([ord(c) for c in chars])
expected = tuple(ord(c) for c in chars)
self.assertEqual(ac_tester.char_converter(), expected)
chars = [b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'0', b'a', b'b', b'c', b'd']
expected = tuple([ord(c) for c in chars])
expected = tuple(ord(c) for c in chars)
self.assertEqual(ac_tester.char_converter(*chars), expected)

def test_unsigned_char_converter(self):
Expand All @@ -891,8 +891,8 @@ def test_short_converter(self):
ac_tester.short_converter(SHRT_MAX + 1)
with self.assertRaises(TypeError):
ac_tester.short_converter([])
self.assertEqual(ac_tester.short_converter(-1234), (-1234, ))
self.assertEqual(ac_tester.short_converter(4321), (4321, ))
self.assertEqual(ac_tester.short_converter(-1234), (-1234,))
self.assertEqual(ac_tester.short_converter(4321), (4321,))

def test_unsigned_short_converter(self):
from _testcapi import USHRT_MAX
Expand Down Expand Up @@ -943,8 +943,8 @@ def test_long_converter(self):
ac_tester.long_converter(LONG_MAX + 1)
with self.assertRaises(TypeError):
ac_tester.long_converter([])
self.assertEqual(ac_tester.long_converter(), (12, ))
self.assertEqual(ac_tester.long_converter(-1234), (-1234, ))
self.assertEqual(ac_tester.long_converter(), (12,))
self.assertEqual(ac_tester.long_converter(-1234), (-1234,))

def test_unsigned_long_converter(self):
from _testcapi import ULONG_MAX
Expand All @@ -968,8 +968,8 @@ def test_long_long_converter(self):
ac_tester.long_long_converter(LLONG_MAX + 1)
with self.assertRaises(TypeError):
ac_tester.long_long_converter([])
self.assertEqual(ac_tester.long_long_converter(), (12, ))
self.assertEqual(ac_tester.long_long_converter(-1234), (-1234, ))
self.assertEqual(ac_tester.long_long_converter(), (12,))
self.assertEqual(ac_tester.long_long_converter(-1234), (-1234,))

def test_unsigned_long_long_converter(self):
from _testcapi import ULLONG_MAX
Expand Down Expand Up @@ -1012,27 +1012,27 @@ def test_size_t_converter(self):
ac_tester.size_t_converter(-1)
with self.assertRaises(TypeError):
ac_tester.size_t_converter([])
self.assertEqual(ac_tester.size_t_converter(), (12, ))
self.assertEqual(ac_tester.size_t_converter(), (12,))

def test_float_converter(self):
with self.assertRaises(TypeError):
ac_tester.float_converter([])
self.assertEqual(ac_tester.float_converter(), (12.5, ))
self.assertEqual(ac_tester.float_converter(-0.5), (-0.5, ))
self.assertEqual(ac_tester.float_converter(), (12.5,))
self.assertEqual(ac_tester.float_converter(-0.5), (-0.5,))

def test_double_converter(self):
with self.assertRaises(TypeError):
ac_tester.double_converter([])
self.assertEqual(ac_tester.double_converter(), (12.5, ))
self.assertEqual(ac_tester.double_converter(-0.5), (-0.5, ))
self.assertEqual(ac_tester.double_converter(), (12.5,))
self.assertEqual(ac_tester.double_converter(-0.5), (-0.5,))

def test_py_complex_converter(self):
with self.assertRaises(TypeError):
ac_tester.py_complex_converter([])
self.assertEqual(ac_tester.py_complex_converter(complex(1, 2)), (complex(1, 2), ))
self.assertEqual(ac_tester.py_complex_converter(complex('-1-2j')), (complex('-1-2j'), ))
self.assertEqual(ac_tester.py_complex_converter(-0.5), (-0.5, ))
self.assertEqual(ac_tester.py_complex_converter(10), (10, ))
self.assertEqual(ac_tester.py_complex_converter(complex(1, 2)), (complex(1, 2),))
self.assertEqual(ac_tester.py_complex_converter(complex('-1-2j')), (complex('-1-2j'),))
self.assertEqual(ac_tester.py_complex_converter(-0.5), (-0.5,))
self.assertEqual(ac_tester.py_complex_converter(10), (10,))

def test_str_converter(self):
with self.assertRaises(TypeError):
Expand Down Expand Up @@ -1209,7 +1209,7 @@ def test_keyword_only_parameter(self):
ac_tester.keyword_only_parameter()
with self.assertRaises(TypeError):
ac_tester.keyword_only_parameter(1)
self.assertEqual(ac_tester.keyword_only_parameter(a=1), (1, ))
self.assertEqual(ac_tester.keyword_only_parameter(a=1), (1,))


if __name__ == "__main__":
Expand Down
49 changes: 28 additions & 21 deletions Modules/_testclinic.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "clinic/_testclinic.c.h"


/* Pack arguments to a tuple, implicitly increase all the arguments' refcount.
* NULL arguments will be replaced to Py_None. */
static PyObject *
Expand All @@ -34,7 +35,8 @@ pack_arguments_newref(int argc, ...) {
Py_DECREF(tuple);
return NULL;
Comment thread
colorfulappl marked this conversation as resolved.
}
} else {
}
else {
arg = Py_None;
}
PyTuple_SET_ITEM(tuple, i, Py_NewRef(arg));
Expand Down Expand Up @@ -119,7 +121,8 @@ bytes_object_converter_impl(PyObject *module, PyBytesObject *a)
/*[clinic end generated code: output=7732da869d74b784 input=94211751e7996236]*/
{
if (!PyBytes_Check(a)) {
PyErr_SetString(PyExc_AssertionError, "argument a is not a PyBytesObject");
PyErr_SetString(PyExc_AssertionError,
"argument a is not a PyBytesObject");
}
Comment thread
colorfulappl marked this conversation as resolved.
return pack_arguments_newref(1, a);
}
Expand All @@ -138,7 +141,8 @@ byte_array_object_converter_impl(PyObject *module, PyByteArrayObject *a)
/*[clinic end generated code: output=51f15c76f302b1f7 input=b04d253db51c6f56]*/
{
if (!PyByteArray_Check(a)) {
PyErr_SetString(PyExc_AssertionError, "argument a is not a PyByteArrayObject");
PyErr_SetString(PyExc_AssertionError,
"argument a is not a PyByteArrayObject");
}
return pack_arguments_newref(1, a);
}
Expand All @@ -157,7 +161,8 @@ unicode_converter_impl(PyObject *module, PyObject *a)
/*[clinic end generated code: output=1b4a4adbb6ac6e34 input=de7b5adbf07435ba]*/
{
if (!PyUnicode_Check(a)) {
PyErr_SetString(PyExc_AssertionError, "argument a is not a unicode object");
PyErr_SetString(PyExc_AssertionError,
"argument a is not a unicode object");
}
return pack_arguments_newref(1, a);
}
Expand Down Expand Up @@ -221,20 +226,20 @@ char_converter_impl(PyObject *module, char a, char b, char c, char d, char e,
/*[clinic end generated code: output=f929dbd2e55a9871 input=b601bc5bc7fe85e3]*/
{
return pack_arguments(14,
PyLong_FromUnsignedLong((unsigned char) a),
PyLong_FromUnsignedLong((unsigned char) b),
PyLong_FromUnsignedLong((unsigned char) c),
PyLong_FromUnsignedLong((unsigned char) d),
PyLong_FromUnsignedLong((unsigned char) e),
PyLong_FromUnsignedLong((unsigned char) f),
PyLong_FromUnsignedLong((unsigned char) g),
PyLong_FromUnsignedLong((unsigned char) h),
PyLong_FromUnsignedLong((unsigned char) i),
PyLong_FromUnsignedLong((unsigned char) j),
PyLong_FromUnsignedLong((unsigned char) k),
PyLong_FromUnsignedLong((unsigned char) l),
PyLong_FromUnsignedLong((unsigned char) m),
PyLong_FromUnsignedLong((unsigned char) n));
PyLong_FromUnsignedLong((unsigned char)a),
PyLong_FromUnsignedLong((unsigned char)b),
PyLong_FromUnsignedLong((unsigned char)c),
PyLong_FromUnsignedLong((unsigned char)d),
PyLong_FromUnsignedLong((unsigned char)e),
PyLong_FromUnsignedLong((unsigned char)f),
PyLong_FromUnsignedLong((unsigned char)g),
PyLong_FromUnsignedLong((unsigned char)h),
PyLong_FromUnsignedLong((unsigned char)i),
PyLong_FromUnsignedLong((unsigned char)j),
PyLong_FromUnsignedLong((unsigned char)k),
PyLong_FromUnsignedLong((unsigned char)l),
PyLong_FromUnsignedLong((unsigned char)m),
PyLong_FromUnsignedLong((unsigned char)n));
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
}


Expand Down Expand Up @@ -489,7 +494,7 @@ static PyObject *
float_converter_impl(PyObject *module, float a)
/*[clinic end generated code: output=1c98f64f2cf1d55c input=a625b59ad68047d8]*/
{
return pack_arguments(1, PyFloat_FromDouble((double) a));
return pack_arguments(1, PyFloat_FromDouble((double)a));
}


Expand Down Expand Up @@ -564,7 +569,8 @@ py_buffer_converter_impl(PyObject *module, Py_buffer *a, Py_buffer *b)
if (!new_a) {
return NULL;
}
if (PyBuffer_ToContiguous(((PyBytesObject *)new_a)->ob_sval, a, a->len, 'C') < 0) {
if (PyBuffer_ToContiguous(((PyBytesObject *)new_a)->ob_sval, a, a->len,
Comment thread
colorfulappl marked this conversation as resolved.
Outdated
'C') < 0) {
Comment thread
colorfulappl marked this conversation as resolved.
Outdated
Py_DECREF(new_a);
return NULL;
}
Expand All @@ -575,7 +581,8 @@ py_buffer_converter_impl(PyObject *module, Py_buffer *a, Py_buffer *b)
Py_DECREF(new_a);
return NULL;
}
if (PyBuffer_ToContiguous(((PyBytesObject *)new_b)->ob_sval, b, b->len, 'C') < 0) {
if (PyBuffer_ToContiguous(((PyBytesObject *)new_b)->ob_sval, b, b->len,
'C') < 0) {
Comment thread
colorfulappl marked this conversation as resolved.
Outdated
Py_DECREF(new_a);
Py_DECREF(new_b);
return NULL;
Expand Down