|
21 | 21 | fromclinicimportDSLParser |
22 | 22 |
|
23 | 23 |
|
24 | | -def_make_clinic(*,filename='clinic_tests'): |
| 24 | +def_make_clinic(*,filename='clinic_tests',limited_capi=False): |
25 | 25 | 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) |
27 | 27 | c.block_parser=clinic.BlockParser('',clang) |
28 | 28 | returnc |
29 | 29 |
|
@@ -3614,6 +3614,46 @@ def test_depr_multi(self): |
3614 | 3614 | self.assertRaises(TypeError,fn,a="a",b="b",c="c",d="d",e="e",f="f",g="g") |
3615 | 3615 |
|
3616 | 3616 |
|
| 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 | + |
3617 | 3657 | try: |
3618 | 3658 | import_testclinic_limited |
3619 | 3659 | exceptImportError: |
@@ -3644,6 +3684,20 @@ def test_my_int_sum(self): |
3644 | 3684 | withself.assertRaises(TypeError): |
3645 | 3685 | _testclinic_limited.my_int_sum(1,"str") |
3646 | 3686 |
|
| 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 | + |
3647 | 3701 |
|
3648 | 3702 |
|
3649 | 3703 | classPermutationTests(unittest.TestCase): |
|