Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d7fde6

Browse files
pythongh-116417: Argument Clinic: test generated Limited C API code for float args (python#116573)
1 parent4704e55 commit8d7fde6

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

‎Lib/test/test_clinic.py‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
fromclinicimportDSLParser
2222

2323

24-
def_make_clinic(*,filename='clinic_tests'):
24+
def_make_clinic(*,filename='clinic_tests',limited_capi=False):
2525
clang=clinic.CLanguage(filename)
26-
c=clinic.Clinic(clang,filename=filename,limited_capi=False)
26+
c=clinic.Clinic(clang,filename=filename,limited_capi=limited_capi)
2727
c.block_parser=clinic.BlockParser('',clang)
2828
returnc
2929

@@ -3614,6 +3614,46 @@ def test_depr_multi(self):
36143614
self.assertRaises(TypeError,fn,a="a",b="b",c="c",d="d",e="e",f="f",g="g")
36153615

36163616

3617+
classLimitedCAPIOutputTests(unittest.TestCase):
3618+
3619+
defsetUp(self):
3620+
self.clinic=_make_clinic(limited_capi=True)
3621+
3622+
@staticmethod
3623+
defwrap_clinic_input(block):
3624+
returndedent(f"""
3625+
/*[clinic input]
3626+
output everything buffer
3627+
{block}
3628+
[clinic start generated code]*/
3629+
/*[clinic input]
3630+
dump buffer
3631+
[clinic start generated code]*/
3632+
""")
3633+
3634+
deftest_limited_capi_float(self):
3635+
block=self.wrap_clinic_input("""
3636+
func
3637+
f: float
3638+
/
3639+
""")
3640+
generated=self.clinic.parse(block)
3641+
self.assertNotIn("PyFloat_AS_DOUBLE",generated)
3642+
self.assertIn("float f;",generated)
3643+
self.assertIn("f = (float) PyFloat_AsDouble",generated)
3644+
3645+
deftest_limited_capi_double(self):
3646+
block=self.wrap_clinic_input("""
3647+
func
3648+
f: double
3649+
/
3650+
""")
3651+
generated=self.clinic.parse(block)
3652+
self.assertNotIn("PyFloat_AS_DOUBLE",generated)
3653+
self.assertIn("double f;",generated)
3654+
self.assertIn("f = PyFloat_AsDouble",generated)
3655+
3656+
36173657
try:
36183658
import_testclinic_limited
36193659
exceptImportError:
@@ -3644,6 +3684,20 @@ def test_my_int_sum(self):
36443684
withself.assertRaises(TypeError):
36453685
_testclinic_limited.my_int_sum(1,"str")
36463686

3687+
deftest_my_double_sum(self):
3688+
forfuncin (
3689+
_testclinic_limited.my_float_sum,
3690+
_testclinic_limited.my_double_sum,
3691+
):
3692+
withself.subTest(func=func.__name__):
3693+
self.assertEqual(func(1.0,2.5),3.5)
3694+
withself.assertRaises(TypeError):
3695+
func()
3696+
withself.assertRaises(TypeError):
3697+
func(1)
3698+
withself.assertRaises(TypeError):
3699+
func(1.,"2")
3700+
36473701

36483702

36493703
classPermutationTests(unittest.TestCase):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp