diff options
author | Matthieu Dartiailh <m.dartiailh@gmail.com> | 2023-02-07 09:34:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-07 09:34:21 (GMT) |
commit | ae62bddaf81176a7e55f95f18d55621c9c46c23d (patch) | |
tree | 0c7a661b7abd64546ebe0b8a495f3004ab30a6f0 /Lib/test | |
parent | c4de6b1d52304a0a9cdfafc1dad5098993710404 (diff) | |
download | cpython-ae62bddaf81176a7e55f95f18d55621c9c46c23d.zip cpython-ae62bddaf81176a7e55f95f18d55621c9c46c23d.tar.gz cpython-ae62bddaf81176a7e55f95f18d55621c9c46c23d.tar.bz2 |
gh-101072: support default and kw default in PyEval_EvalCodeEx for 3.11+ (#101127)
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_capi/test_eval_code_ex.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_eval_code_ex.py b/Lib/test/test_capi/test_eval_code_ex.py new file mode 100644 index 0000000..2d28e52 --- /dev/null +++ b/Lib/test/test_capi/test_eval_code_ex.py @@ -0,0 +1,56 @@ +import unittest + +from test.support import import_helper + + +# Skip this test if the _testcapi module isn't available. +_testcapi = import_helper.import_module('_testcapi') + + +class PyEval_EvalCodeExTests(unittest.TestCase): + + def test_simple(self): + def f(): + return a + + self.assertEqual(_testcapi.eval_code_ex(f.__code__, dict(a=1)), 1) + + # Need to force the compiler to use LOAD_NAME + # def test_custom_locals(self): + # def f(): + # return + + def test_with_args(self): + def f(a, b, c): + return a + + self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (1, 2, 3)), 1) + + def test_with_kwargs(self): + def f(a, b, c): + return a + + self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), dict(a=1, b=2, c=3)), 1) + + def test_with_default(self): + def f(a): + return a + + self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (1,)), 1) + + def test_with_kwarg_default(self): + def f(*, a): + return a + + self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (), dict(a=1)), 1) + + def test_with_closure(self): + a = 1 + def f(): + return a + + self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (), {}, f.__closure__), 1) + + +if __name__ == "__main__": + unittest.main() |