|
11 | 11 | import upgrade_pythoncapi # noqa |
12 | 12 |
|
13 | 13 |
|
14 | | -def patch(source): |
| 14 | +def patch(source, no_compat=False): |
15 | 15 | args = ['script', 'mod.c'] |
| 16 | + if no_compat: |
| 17 | + args.append('--no-compat') |
16 | 18 | patcher = upgrade_pythoncapi.Patcher(args) |
17 | 19 | return patcher.patch(source) |
18 | 20 |
|
@@ -99,10 +101,10 @@ def test_patch_directory(self): |
99 | 101 | with tempfile.TemporaryDirectory() as tmp_dir: |
100 | 102 | self._test_patch_file(tmp_dir) |
101 | 103 |
|
102 | | - def check_replace(self, source, expected): |
| 104 | + def check_replace(self, source, expected, **kwargs): |
103 | 105 | source = reformat(source) |
104 | 106 | expected = reformat(expected) |
105 | | - self.assertEqual(patch(source), expected) |
| 107 | + self.assertEqual(patch(source, **kwargs), expected) |
106 | 108 |
|
107 | 109 | def check_dont_replace(self, source): |
108 | 110 | source = reformat(source) |
@@ -537,5 +539,21 @@ def test_py_is(self): |
537 | 539 | """) |
538 | 540 |
|
539 | 541 |
|
| 542 | + def test_no_compat(self): |
| 543 | + # Don't add "#include "pythoncapi_compat.h" |
| 544 | + source = """ |
| 545 | + void test_type(PyObject *obj, PyTypeObject *type) |
| 546 | + { |
| 547 | + obj->ob_type = type; |
| 548 | + } |
| 549 | + """ |
| 550 | + expected = """ |
| 551 | + void test_type(PyObject *obj, PyTypeObject *type) |
| 552 | + { |
| 553 | + Py_SET_TYPE(obj, type); |
| 554 | + } |
| 555 | + """ |
| 556 | + self.check_replace(source, expected, no_compat=True) |
| 557 | + |
540 | 558 | if __name__ == "__main__": |
541 | 559 | unittest.main() |
0 commit comments