mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
gh-94808: Cover PyFunction_GetCode
, PyFunction_GetGlobals
, PyFunction_GetModule
(#98158)
This commit is contained in:
parent
660f10248b
commit
7b48d02933
2 changed files with 74 additions and 0 deletions
|
@ -895,6 +895,41 @@ class CAPITest(unittest.TestCase):
|
|||
self.assertEqual(_testcapi.eval_get_func_name(sum), "sum") # c function
|
||||
self.assertEqual(_testcapi.eval_get_func_name(A), "type")
|
||||
|
||||
def test_function_get_code(self):
|
||||
import types
|
||||
|
||||
def some():
|
||||
pass
|
||||
|
||||
code = _testcapi.function_get_code(some)
|
||||
self.assertIsInstance(code, types.CodeType)
|
||||
self.assertEqual(code, some.__code__)
|
||||
|
||||
with self.assertRaises(SystemError):
|
||||
_testcapi.function_get_code(None) # not a function
|
||||
|
||||
def test_function_get_globals(self):
|
||||
def some():
|
||||
pass
|
||||
|
||||
globals_ = _testcapi.function_get_globals(some)
|
||||
self.assertIsInstance(globals_, dict)
|
||||
self.assertEqual(globals_, some.__globals__)
|
||||
|
||||
with self.assertRaises(SystemError):
|
||||
_testcapi.function_get_globals(None) # not a function
|
||||
|
||||
def test_function_get_module(self):
|
||||
def some():
|
||||
pass
|
||||
|
||||
module = _testcapi.function_get_module(some)
|
||||
self.assertIsInstance(module, str)
|
||||
self.assertEqual(module, some.__module__)
|
||||
|
||||
with self.assertRaises(SystemError):
|
||||
_testcapi.function_get_module(None) # not a function
|
||||
|
||||
|
||||
class TestPendingCalls(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue