Discussion:
[Python-3000-checkins] r66947 - in python/branches/py3k: Lib/test/test_capi.py Modules/_testcapimodule.c
benjamin.peterson
2008-10-16 23:56:29 UTC
Permalink
Author: benjamin.peterson
Date: Fri Oct 17 01:56:29 2008
New Revision: 66947

Log:
add tests for PyInstanceMethod_Type

Modified:
python/branches/py3k/Lib/test/test_capi.py
python/branches/py3k/Modules/_testcapimodule.c

Modified: python/branches/py3k/Lib/test/test_capi.py
==============================================================================
--- python/branches/py3k/Lib/test/test_capi.py (original)
+++ python/branches/py3k/Lib/test/test_capi.py Fri Oct 17 01:56:29 2008
@@ -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 @@
t.start()
t.join()

+
if __name__ == "__main__":
test_main()

Modified: python/branches/py3k/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k/Modules/_testcapimodule.c (original)
+++ python/branches/py3k/Modules/_testcapimodule.c Fri Oct 17 01:56:29 2008
@@ -1231,6 +1231,8 @@
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);

Loading...