summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-10-16 23:56:29 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-10-16 23:56:29 (GMT)
commit9b6df6afe0b647ab336ab5cd8a03c44b55d6544b (patch)
treeb8efb393d8ded7c1f584185434b0ce95128c9ab6
parenta3b341f1420912fe099416e4db0de539dd82e1a3 (diff)
downloadcpython-9b6df6afe0b647ab336ab5cd8a03c44b55d6544b.zip
cpython-9b6df6afe0b647ab336ab5cd8a03c44b55d6544b.tar.gz
cpython-9b6df6afe0b647ab336ab5cd8a03c44b55d6544b.tar.bz2
add tests for PyInstanceMethod_Type
-rw-r--r--Lib/test/test_capi.py25
-rw-r--r--Modules/_testcapimodule.c2
2 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 6c87645..efa7c34 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -2,10 +2,34 @@
# these are all functions _testcapi exports whose name begins with 'test_'.
import sys
+import unittest
from test import support
import _testcapi
+def testfunction(self):
+ """some doc"""
+ return self
+
+class InstanceMethod:
+ id = _testcapi.instancemethod(id)
+ testfunction = _testcapi.instancemethod(testfunction)
+
+class CAPITest(unittest.TestCase):
+
+ def test_instancemethod(self):
+ inst = InstanceMethod()
+ self.assertEqual(id(inst), inst.id())
+ self.assert_(inst.testfunction() is inst)
+ self.assertEqual(inst.testfunction.__doc__, testfunction.__doc__)
+ self.assertEqual(InstanceMethod.testfunction.__doc__, testfunction.__doc__)
+
+ InstanceMethod.testfunction.attribute = "test"
+ self.assertEqual(testfunction.attribute, "test")
+ self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute", "test")
+
+
def test_main():
+ support.run_unittest(CAPITest)
for name in dir(_testcapi):
if name.startswith('test_'):
@@ -47,5 +71,6 @@ def test_main():
t.start()
t.join()
+
if __name__ == "__main__":
test_main()
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 940605e..b1cb6fe 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1231,6 +1231,8 @@ PyInit__testcapi(void)
PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyLong_FromSsize_t(PY_SSIZE_T_MAX));
PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyLong_FromSsize_t(PY_SSIZE_T_MIN));
PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyLong_FromSsize_t(sizeof(PyGC_Head)));
+ Py_INCREF(&PyInstanceMethod_Type);
+ PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);
TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
Py_INCREF(TestError);