22# Copyright 2012-2013 by Larry Hastings.
33# Licensed to the PSF under a contributor agreement.
44
5- from functools import partial
5+ from functools import partial , wraps
66from test import support , test_tools
77from test .support import force_not_colorized_test_class
88from test .support import os_helper
@@ -3570,6 +3570,18 @@ class Foo "FooObject *" "Foo_Type"
35703570 """
35713571 self .expect_failure (block , err , lineno = 7 )
35723572
3573+ def test_vectorcall_with_deprecated_parameters (self ):
3574+ err = "@vectorcall does not support deprecated parameters"
3575+ block = """
3576+ module m
3577+ class Foo "FooObject *" "Foo_Type"
3578+ @vectorcall
3579+ Foo.__init__
3580+ a: object = None
3581+ / [from 3.14]
3582+ """
3583+ self .expect_failure (block , err , lineno = 5 )
3584+
35733585 def test_unused_param (self ):
35743586 block = self .parse ("""
35753587 module foo
@@ -4621,6 +4633,16 @@ def test_file_dest(self):
46214633except ImportError :
46224634 ac_tester = None
46234635
4636+ def static_and_heap (test ):
4637+ # Run test with both a static type and a heap type.
4638+ @wraps (test )
4639+ def wrapper (self ):
4640+ for cls in ac_tester .TestClass , ac_tester .HeapTestClass :
4641+ with self .subTest (cls = cls ):
4642+ test (self , cls )
4643+ return wrapper
4644+
4645+
46244646@unittest .skipIf (ac_tester is None , "_testclinic is missing" )
46254647class ClinicFunctionalTest (unittest .TestCase ):
46264648 locals ().update ((name , getattr (ac_tester , name ))
@@ -5295,53 +5317,56 @@ def test_cloned_func_with_converter_exception_message(self):
52955317 func = getattr (ac_tester , name )
52965318 self .assertEqual (func (), name )
52975319
5298- def test_get_defining_class (self ):
5299- obj = ac_tester .TestClass ()
5320+ @static_and_heap
5321+ def test_get_defining_class (self , cls ):
5322+ obj = cls ()
53005323 meth = obj .get_defining_class
5301- self .assertIs (obj .get_defining_class (), ac_tester . TestClass )
5324+ self .assertIs (obj .get_defining_class (), cls )
53025325
53035326 # 'defining_class' argument is a positional only argument
53045327 with self .assertRaises (TypeError ):
5305- obj .get_defining_class_arg (cls = ac_tester . TestClass )
5328+ obj .get_defining_class_arg (cls = cls )
53065329
53075330 check = partial (self .assertRaisesRegex , TypeError , "no arguments" )
53085331 check (meth , 1 )
53095332 check (meth , a = 1 )
53105333
5311- def test_get_defining_class_capi (self ):
5334+ @static_and_heap
5335+ def test_get_defining_class_capi (self , cls ):
53125336 from _testcapi import pyobject_vectorcall
5313- obj = ac_tester . TestClass ()
5337+ obj = cls ()
53145338 meth = obj .get_defining_class
53155339 pyobject_vectorcall (meth , None , None )
53165340 pyobject_vectorcall (meth , (), None )
53175341 pyobject_vectorcall (meth , (), ())
53185342 pyobject_vectorcall (meth , None , ())
5319- self .assertIs (pyobject_vectorcall (meth , (), ()), ac_tester . TestClass )
5343+ self .assertIs (pyobject_vectorcall (meth , (), ()), cls )
53205344
53215345 check = partial (self .assertRaisesRegex , TypeError , "no arguments" )
53225346 check (pyobject_vectorcall , meth , (1 ,), None )
53235347 check (pyobject_vectorcall , meth , (1 ,), ("a" ,))
53245348
5325- def test_get_defining_class_arg (self ):
5326- obj = ac_tester .TestClass ()
5349+ @static_and_heap
5350+ def test_get_defining_class_arg (self , cls ):
5351+ obj = cls ()
53275352 self .assertEqual (obj .get_defining_class_arg ("arg" ),
5328- (ac_tester . TestClass , "arg" ))
5353+ (cls , "arg" ))
53295354 self .assertEqual (obj .get_defining_class_arg (arg = 123 ),
5330- (ac_tester . TestClass , 123 ))
5355+ (cls , 123 ))
53315356
53325357 # 'defining_class' argument is a positional only argument
53335358 with self .assertRaises (TypeError ):
5334- obj .get_defining_class_arg (cls = ac_tester . TestClass , arg = "arg" )
5359+ obj .get_defining_class_arg (cls = cls , arg = "arg" )
53355360
53365361 # wrong number of arguments
53375362 with self .assertRaises (TypeError ):
53385363 obj .get_defining_class_arg ()
53395364 with self .assertRaises (TypeError ):
53405365 obj .get_defining_class_arg ("arg1" , "arg2" )
53415366
5342- def test_defclass_varpos (self ):
5367+ @static_and_heap
5368+ def test_defclass_varpos (self , cls ):
53435369 # fn(*args)
5344- cls = ac_tester .TestClass
53455370 obj = cls ()
53465371 fn = obj .defclass_varpos
53475372 self .assertEqual (fn (), (cls , ()))
@@ -5351,9 +5376,9 @@ def test_defclass_varpos(self):
53515376 self .assertEqual (fn (obj ), (cls , ()))
53525377 self .assertEqual (fn (obj , 1 , 2 ), (cls , (1 , 2 )))
53535378
5354- def test_defclass_posonly_varpos (self ):
5379+ @static_and_heap
5380+ def test_defclass_posonly_varpos (self , cls ):
53555381 # fn(a, b, /, *args)
5356- cls = ac_tester .TestClass
53575382 obj = cls ()
53585383 fn = obj .defclass_posonly_varpos
53595384 errmsg = 'expected at least 2 arguments'
0 commit comments