| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -880,6 +880,41 @@ def __init__(self): | |||
| 880 | 880 | _testcapi.clear_managed_dict(c) | |
| 881 | 881 | self.assertEqual(c.__dict__, {}) | |
| 882 | 882 | ||
| 883 | + def test_function_get_code(self): | ||
| 884 | + import types | ||
| 885 | + | ||
| 886 | + def some(): | ||
| 887 | + pass | ||
| 888 | + | ||
| 889 | + code = _testcapi.function_get_code(some) | ||
| 890 | + self.assertIsInstance(code, types.CodeType) | ||
| 891 | + self.assertEqual(code, some.__code__) | ||
| 892 | + | ||
| 893 | + with self.assertRaises(SystemError): | ||
| 894 | + _testcapi.function_get_code(None) # not a function | ||
| 895 | + | ||
| 896 | + def test_function_get_globals(self): | ||
| 897 | + def some(): | ||
| 898 | + pass | ||
| 899 | + | ||
| 900 | + globals_ = _testcapi.function_get_globals(some) | ||
| 901 | + self.assertIsInstance(globals_, dict) | ||
| 902 | + self.assertEqual(globals_, some.__globals__) | ||
| 903 | + | ||
| 904 | + with self.assertRaises(SystemError): | ||
| 905 | + _testcapi.function_get_globals(None) # not a function | ||
| 906 | + | ||
| 907 | + def test_function_get_module(self): | ||
| 908 | + def some(): | ||
| 909 | + pass | ||
| 910 | + | ||
| 911 | + module = _testcapi.function_get_module(some) | ||
| 912 | + self.assertIsInstance(module, str) | ||
| 913 | + self.assertEqual(module, some.__module__) | ||
| 914 | + | ||
| 915 | + with self.assertRaises(SystemError): | ||
| 916 | + _testcapi.function_get_module(None) # not a function | ||
| 917 | + | ||
| 883 | 918 | ||
| 884 | 919 | class TestPendingCalls(unittest.TestCase): | |
| 885 | 920 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5652,6 +5652,42 @@ test_macros(PyObject *self, PyObject *Py_UNUSED(args)) | |||
| 5652 | 5652 | Py_RETURN_NONE; | |
| 5653 | 5653 | } | |
| 5654 | 5654 | ||
| 5655 | + static PyObject * | ||
| 5656 | + function_get_code(PyObject *self, PyObject *func) | ||
| 5657 | + { | ||
| 5658 | + PyObject *code = PyFunction_GetCode(func); | ||
| 5659 | + if (code != NULL) { | ||
| 5660 | + Py_INCREF(code); | ||
| 5661 | + return code; | ||
| 5662 | + } else { | ||
| 5663 | + return NULL; | ||
| 5664 | + } | ||
| 5665 | + } | ||
| 5666 | + | ||
| 5667 | + static PyObject * | ||
| 5668 | + function_get_globals(PyObject *self, PyObject *func) | ||
| 5669 | + { | ||
| 5670 | + PyObject *globals = PyFunction_GetGlobals(func); | ||
| 5671 | + if (globals != NULL) { | ||
| 5672 | + Py_INCREF(globals); | ||
| 5673 | + return globals; | ||
| 5674 | + } else { | ||
| 5675 | + return NULL; | ||
| 5676 | + } | ||
| 5677 | + } | ||
| 5678 | + | ||
| 5679 | + static PyObject * | ||
| 5680 | + function_get_module(PyObject *self, PyObject *func) | ||
| 5681 | + { | ||
| 5682 | + PyObject *module = PyFunction_GetModule(func); | ||
| 5683 | + if (module != NULL) { | ||
| 5684 | + Py_INCREF(module); | ||
| 5685 | + return module; | ||
| 5686 | + } else { | ||
| 5687 | + return NULL; | ||
| 5688 | + } | ||
| 5689 | + } | ||
| 5690 | + | ||
| 5655 | 5691 | ||
| 5656 | 5692 | static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *); | |
| 5657 | 5693 | static PyObject *getargs_s_hash_int(PyObject *, PyObject *, PyObject*); | |
@@ -5935,6 +5971,9 @@ static PyMethodDef TestMethods[] = { | |||
| 5935 | 5971 | {"watch_dict", watch_dict, METH_VARARGS, NULL}, | |
| 5936 | 5972 | {"unwatch_dict", unwatch_dict, METH_VARARGS, NULL}, | |
| 5937 | 5973 | {"get_dict_watcher_events", get_dict_watcher_events, METH_NOARGS, NULL}, | |
| 5974 | + {"function_get_code", function_get_code, METH_O, NULL}, | ||
| 5975 | + {"function_get_globals", function_get_globals, METH_O, NULL}, | ||
| 5976 | + {"function_get_module", function_get_module, METH_O, NULL}, | ||
| 5938 | 5977 | {NULL, NULL} /* sentinel */ | |
| 5939 | 5978 | }; | |
| 5940 | 5979 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments