mirror of
https://github.com/python/cpython.git
synced 2025-09-14 04:37:29 +00:00
gh-116417: Argument Clinic: test generated Limited C API code for float args (#116573)
This commit is contained in:
parent
4704e55a71
commit
8d7fde655f
1 changed files with 56 additions and 2 deletions
|
@ -21,9 +21,9 @@ with test_tools.imports_under_tool('clinic'):
|
||||||
from clinic import DSLParser
|
from clinic import DSLParser
|
||||||
|
|
||||||
|
|
||||||
def _make_clinic(*, filename='clinic_tests'):
|
def _make_clinic(*, filename='clinic_tests', limited_capi=False):
|
||||||
clang = clinic.CLanguage(filename)
|
clang = clinic.CLanguage(filename)
|
||||||
c = clinic.Clinic(clang, filename=filename, limited_capi=False)
|
c = clinic.Clinic(clang, filename=filename, limited_capi=limited_capi)
|
||||||
c.block_parser = clinic.BlockParser('', clang)
|
c.block_parser = clinic.BlockParser('', clang)
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
@ -3614,6 +3614,46 @@ class ClinicFunctionalTest(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, fn, a="a", b="b", c="c", d="d", e="e", f="f", g="g")
|
self.assertRaises(TypeError, fn, a="a", b="b", c="c", d="d", e="e", f="f", g="g")
|
||||||
|
|
||||||
|
|
||||||
|
class LimitedCAPIOutputTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.clinic = _make_clinic(limited_capi=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def wrap_clinic_input(block):
|
||||||
|
return dedent(f"""
|
||||||
|
/*[clinic input]
|
||||||
|
output everything buffer
|
||||||
|
{block}
|
||||||
|
[clinic start generated code]*/
|
||||||
|
/*[clinic input]
|
||||||
|
dump buffer
|
||||||
|
[clinic start generated code]*/
|
||||||
|
""")
|
||||||
|
|
||||||
|
def test_limited_capi_float(self):
|
||||||
|
block = self.wrap_clinic_input("""
|
||||||
|
func
|
||||||
|
f: float
|
||||||
|
/
|
||||||
|
""")
|
||||||
|
generated = self.clinic.parse(block)
|
||||||
|
self.assertNotIn("PyFloat_AS_DOUBLE", generated)
|
||||||
|
self.assertIn("float f;", generated)
|
||||||
|
self.assertIn("f = (float) PyFloat_AsDouble", generated)
|
||||||
|
|
||||||
|
def test_limited_capi_double(self):
|
||||||
|
block = self.wrap_clinic_input("""
|
||||||
|
func
|
||||||
|
f: double
|
||||||
|
/
|
||||||
|
""")
|
||||||
|
generated = self.clinic.parse(block)
|
||||||
|
self.assertNotIn("PyFloat_AS_DOUBLE", generated)
|
||||||
|
self.assertIn("double f;", generated)
|
||||||
|
self.assertIn("f = PyFloat_AsDouble", generated)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import _testclinic_limited
|
import _testclinic_limited
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -3644,6 +3684,20 @@ class LimitedCAPIFunctionalTest(unittest.TestCase):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
_testclinic_limited.my_int_sum(1, "str")
|
_testclinic_limited.my_int_sum(1, "str")
|
||||||
|
|
||||||
|
def test_my_double_sum(self):
|
||||||
|
for func in (
|
||||||
|
_testclinic_limited.my_float_sum,
|
||||||
|
_testclinic_limited.my_double_sum,
|
||||||
|
):
|
||||||
|
with self.subTest(func=func.__name__):
|
||||||
|
self.assertEqual(func(1.0, 2.5), 3.5)
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
func()
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
func(1)
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
func(1., "2")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PermutationTests(unittest.TestCase):
|
class PermutationTests(unittest.TestCase):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue