Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ba32a4

Browse files
committed
Add test on --no-compat option
1 parent 233a0d5 commit 1ba32a4

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

tests/test_upgrade_pythoncapi.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import upgrade_pythoncapi # noqa
1212

1313

14-
def patch(source):
14+
def patch(source, no_compat=False):
1515
args = ['script', 'mod.c']
16+
if no_compat:
17+
args.append('--no-compat')
1618
patcher = upgrade_pythoncapi.Patcher(args)
1719
return patcher.patch(source)
1820

@@ -99,10 +101,10 @@ def test_patch_directory(self):
99101
with tempfile.TemporaryDirectory() as tmp_dir:
100102
self._test_patch_file(tmp_dir)
101103

102-
def check_replace(self, source, expected):
104+
def check_replace(self, source, expected, **kwargs):
103105
source = reformat(source)
104106
expected = reformat(expected)
105-
self.assertEqual(patch(source), expected)
107+
self.assertEqual(patch(source, **kwargs), expected)
106108

107109
def check_dont_replace(self, source):
108110
source = reformat(source)
@@ -537,5 +539,21 @@ def test_py_is(self):
537539
""")
538540

539541

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+
540558
if __name__ == "__main__":
541559
unittest.main()

0 commit comments

Comments
 (0)