Skip to content

Commit 04a148c

Browse files
committed
Simplify some test cases
1 parent 115a524 commit 04a148c

3 files changed

Lines changed: 21 additions & 98 deletions

File tree

Lib/test/test_clinic.py

Lines changed: 15 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,47 +2751,6 @@ class Foo "FooObject *" "Foo_Type"
27512751
self.assertTrue(func.vectorcall)
27522752
self.assertTrue(func.vectorcall_exact_only)
27532753

2754-
def test_vectorcall_init_with_kwargs(self):
2755-
block = """
2756-
module m
2757-
class Foo "FooObject *" "Foo_Type"
2758-
@vectorcall
2759-
Foo.__init__
2760-
source: object = NULL
2761-
encoding: str = NULL
2762-
errors: str = NULL
2763-
"""
2764-
func = self.parse_function(block, signatures_in_block=3,
2765-
function_index=2)
2766-
self.assertTrue(func.vectorcall)
2767-
2768-
def test_vectorcall_new_with_kwargs(self):
2769-
block = """
2770-
module m
2771-
class Foo "FooObject *" "Foo_Type"
2772-
@classmethod
2773-
@vectorcall
2774-
Foo.__new__
2775-
source: object = NULL
2776-
*
2777-
encoding: str = NULL
2778-
errors: str = NULL
2779-
"""
2780-
func = self.parse_function(block, signatures_in_block=3,
2781-
function_index=2)
2782-
self.assertTrue(func.vectorcall)
2783-
2784-
def test_vectorcall_init_no_args(self):
2785-
block = """
2786-
module m
2787-
class Foo "FooObject *" "Foo_Type"
2788-
@vectorcall
2789-
Foo.__init__
2790-
"""
2791-
func = self.parse_function(block, signatures_in_block=3,
2792-
function_index=2)
2793-
self.assertTrue(func.vectorcall)
2794-
27952754
def test_vectorcall_zero_arg(self):
27962755
block = """
27972756
module m
@@ -4478,33 +4437,19 @@ def test_kwds_with_pos_only_and_stararg(self):
44784437
class VectorcallFunctionalTest(unittest.TestCase):
44794438
"""Runtime tests for @vectorcall exemplar types."""
44804439

4481-
def test_vc_new_no_args(self):
4482-
obj = ac_tester.VcNew()
4483-
self.assertIsInstance(obj, ac_tester.VcNew)
4484-
4485-
def test_vc_new_with_arg(self):
4486-
obj = ac_tester.VcNew(1)
4487-
self.assertIsInstance(obj, ac_tester.VcNew)
4488-
4489-
def test_vc_new_with_kwarg(self):
4490-
obj = ac_tester.VcNew(a=1)
4491-
self.assertIsInstance(obj, ac_tester.VcNew)
4440+
def test_vc_new(self):
4441+
self.assertIsInstance(ac_tester.VcNew(), ac_tester.VcNew)
4442+
self.assertIsInstance(ac_tester.VcNew(1), ac_tester.VcNew)
4443+
self.assertIsInstance(ac_tester.VcNew(a=1), ac_tester.VcNew)
44924444

44934445
def test_vc_new_rejects_extra_args(self):
44944446
with self.assertRaises(TypeError):
44954447
ac_tester.VcNew(1, 2)
44964448

4497-
def test_vc_init_required_pos_only(self):
4498-
obj = ac_tester.VcInit(1)
4499-
self.assertIsInstance(obj, ac_tester.VcInit)
4500-
4501-
def test_vc_init_with_keyword(self):
4502-
obj = ac_tester.VcInit(1, b=2)
4503-
self.assertIsInstance(obj, ac_tester.VcInit)
4504-
4505-
def test_vc_init_with_positional_optional(self):
4506-
obj = ac_tester.VcInit(1, 2)
4507-
self.assertIsInstance(obj, ac_tester.VcInit)
4449+
def test_vc_init(self):
4450+
self.assertIsInstance(ac_tester.VcInit(1), ac_tester.VcInit)
4451+
self.assertIsInstance(ac_tester.VcInit(1, 2), ac_tester.VcInit)
4452+
self.assertIsInstance(ac_tester.VcInit(1, b=2), ac_tester.VcInit)
45084453

45094454
def test_vc_init_missing_required(self):
45104455
with self.assertRaises(TypeError):
@@ -4515,13 +4460,9 @@ def test_vc_init_rejects_a_as_keyword(self):
45154460
with self.assertRaises(TypeError):
45164461
ac_tester.VcInit(a=1)
45174462

4518-
def test_vc_new_exact_one_arg(self):
4519-
obj = ac_tester.VcNewExact(1)
4520-
self.assertIsInstance(obj, ac_tester.VcNewExact)
4521-
4522-
def test_vc_new_exact_two_args(self):
4523-
obj = ac_tester.VcNewExact(1, 2)
4524-
self.assertIsInstance(obj, ac_tester.VcNewExact)
4463+
def test_vc_new_exact(self):
4464+
self.assertIsInstance(ac_tester.VcNewExact(1), ac_tester.VcNewExact)
4465+
self.assertIsInstance(ac_tester.VcNewExact(1, 2), ac_tester.VcNewExact)
45254466

45264467
def test_vc_new_exact_missing_required(self):
45274468
with self.assertRaises(TypeError):
@@ -4539,17 +4480,10 @@ def test_vc_new_zeroarg_no_args(self):
45394480
result = ac_tester.VcNewZeroArg()
45404481
self.assertIs(result, None)
45414482

4542-
def test_vc_new_zeroarg_with_pos(self):
4543-
obj = ac_tester.VcNewZeroArg(1)
4544-
self.assertIsInstance(obj, ac_tester.VcNewZeroArg)
4545-
4546-
def test_vc_new_zeroarg_with_kwonly(self):
4547-
obj = ac_tester.VcNewZeroArg(b=2)
4548-
self.assertIsInstance(obj, ac_tester.VcNewZeroArg)
4549-
4550-
def test_vc_new_zeroarg_with_both(self):
4551-
obj = ac_tester.VcNewZeroArg(1, b=2)
4552-
self.assertIsInstance(obj, ac_tester.VcNewZeroArg)
4483+
def test_vc_new_zeroarg_with_args(self):
4484+
self.assertIsInstance(ac_tester.VcNewZeroArg(1), ac_tester.VcNewZeroArg)
4485+
self.assertIsInstance(ac_tester.VcNewZeroArg(b=2), ac_tester.VcNewZeroArg)
4486+
self.assertIsInstance(ac_tester.VcNewZeroArg(1, b=2), ac_tester.VcNewZeroArg)
45534487

45544488
def test_vc_new_zeroarg_rejects_a_as_keyword(self):
45554489
# 'a' is positional-only

Modules/_testclinic.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,16 +2322,9 @@ output pop
23222322
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e7c7c42daced52b0]*/
23232323

23242324

2325-
/*
2326-
* Vectorcall exemplars.
2327-
*
2328-
* Each type exercises a different @vectorcall code-generation path.
2329-
* There is one type per exemplar because tp_vectorcall is a single slot.
2330-
*/
2331-
2325+
/* @vectorcall test types. One type per exemplar because tp_vectorcall is a single slot. */
23322326

2333-
/* --- VcNew: @vectorcall on __new__, single pos-or-kw optional
2334-
* (general + kw fast-path, METHOD_NEW finale) --- */
2327+
/* VcNew: __new__ with one optional positional-or-keyword arg */
23352328

23362329
/*[clinic input]
23372330
class _testclinic.VcNew "PyObject *" "&VcNew_Type"
@@ -2358,8 +2351,7 @@ static PyTypeObject VcNew_Type = {
23582351
};
23592352

23602353

2361-
/* --- VcInit: @vectorcall on __init__, pos-only + pos-or-kw optional
2362-
* (general + kw fast-path) --- */
2354+
/* VcInit: __init__ with one required positional-only and one optional keyword arg */
23632355

23642356
/*[clinic input]
23652357
class _testclinic.VcInit "PyObject *" "&VcInit_Type"
@@ -2388,8 +2380,7 @@ static PyTypeObject VcInit_Type = {
23882380
};
23892381

23902382

2391-
/* --- VcNewExact: @vectorcall exact_only on __new__, pos-only required +
2392-
* pos-or-kw optional (general + kw fast-path + exact_only guard) --- */
2383+
/* VcNewExact: __new__ with exact_only; subclasses fall back to tp_new */
23932384

23942385
/*[clinic input]
23952386
class _testclinic.VcNewExact "PyObject *" "&VcNewExact_Type"
@@ -2418,8 +2409,7 @@ static PyTypeObject VcNewExact_Type = {
24182409
};
24192410

24202411

2421-
/* --- VcNewZeroArg: @vectorcall zero_arg on __new__, pos-only optional +
2422-
* kw-only optional (general path, no kw fast-path + zero_arg) --- */
2412+
/* VcNewZeroArg: __new__ with zero_arg; returns Py_None when called with no args */
24232413

24242414
/*[clinic input]
24252415
class _testclinic.VcNewZeroArg "PyObject *" "&VcNewZeroArg_Type"

Modules/clinic/_testclinic.c.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)