home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_381 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.1 KB  |  81 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from ctypes import *
  5. import unittest
  6. import sys
  7. from ctypes.test import is_resource_enabled
  8. from _ctypes import PyObj_FromPtr
  9. from sys import getrefcount as grc
  10. if sys.version_info > (2, 4):
  11.     c_py_ssize_t = c_size_t
  12. else:
  13.     c_py_ssize_t = c_int
  14.  
  15. class PythonAPITestCase(unittest.TestCase):
  16.     
  17.     def test_PyString_FromStringAndSize(self):
  18.         PyString_FromStringAndSize = pythonapi.PyString_FromStringAndSize
  19.         PyString_FromStringAndSize.restype = py_object
  20.         PyString_FromStringAndSize.argtypes = (c_char_p, c_py_ssize_t)
  21.         self.failUnlessEqual(PyString_FromStringAndSize('abcdefghi', 3), 'abc')
  22.  
  23.     
  24.     def test_PyString_FromString(self):
  25.         pythonapi.PyString_FromString.restype = py_object
  26.         pythonapi.PyString_FromString.argtypes = (c_char_p,)
  27.         s = 'abc'
  28.         refcnt = grc(s)
  29.         pyob = pythonapi.PyString_FromString(s)
  30.         self.failUnlessEqual(grc(s), refcnt)
  31.         self.failUnlessEqual(s, pyob)
  32.         del pyob
  33.         self.failUnlessEqual(grc(s), refcnt)
  34.  
  35.     if is_resource_enabled('refcount'):
  36.         
  37.         def test_PyInt_Long(self):
  38.             ref42 = grc(42)
  39.             pythonapi.PyInt_FromLong.restype = py_object
  40.             self.failUnlessEqual(pythonapi.PyInt_FromLong(42), 42)
  41.             self.failUnlessEqual(grc(42), ref42)
  42.             pythonapi.PyInt_AsLong.argtypes = (py_object,)
  43.             pythonapi.PyInt_AsLong.restype = c_long
  44.             res = pythonapi.PyInt_AsLong(42)
  45.             self.failUnlessEqual(grc(res), ref42 + 1)
  46.             del res
  47.             self.failUnlessEqual(grc(42), ref42)
  48.  
  49.     
  50.     
  51.     def test_PyObj_FromPtr(self):
  52.         s = 'abc def ghi jkl'
  53.         ref = grc(s)
  54.         pyobj = PyObj_FromPtr(id(s))
  55.         self.failUnless(s is pyobj)
  56.         self.failUnlessEqual(grc(s), ref + 1)
  57.         del pyobj
  58.         self.failUnlessEqual(grc(s), ref)
  59.  
  60.     
  61.     def test_PyOS_snprintf(self):
  62.         PyOS_snprintf = pythonapi.PyOS_snprintf
  63.         PyOS_snprintf.argtypes = (POINTER(c_char), c_size_t, c_char_p)
  64.         buf = c_buffer(256)
  65.         PyOS_snprintf(buf, sizeof(buf), 'Hello from %s', 'ctypes')
  66.         self.failUnlessEqual(buf.value, 'Hello from ctypes')
  67.         PyOS_snprintf(buf, sizeof(buf), 'Hello from %s', 'ctypes', 1, 2, 3)
  68.         self.failUnlessEqual(buf.value, 'Hello from ctypes')
  69.         self.failUnlessRaises(TypeError, PyOS_snprintf, buf)
  70.  
  71.     
  72.     def test_pyobject_repr(self):
  73.         self.failUnlessEqual(repr(py_object()), 'py_object(<NULL>)')
  74.         self.failUnlessEqual(repr(py_object(42)), 'py_object(42)')
  75.         self.failUnlessEqual(repr(py_object(object)), 'py_object(%r)' % object)
  76.  
  77.  
  78. if __name__ == '__main__':
  79.     unittest.main()
  80.  
  81.