Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_pickling.PickleTest_2 Class Reference
Inheritance diagram for ctypes.test.test_pickling.PickleTest_2:
Inheritance graph
[legend]
Collaboration diagram for ctypes.test.test_pickling.PickleTest_2:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def dumps
def loads
def test_simple
def test_struct
def test_unpickable
def test_wchar

Detailed Description

Definition at line 78 of file test_pickling.py.


Member Function Documentation

Reimplemented from ctypes.test.test_pickling.PickleTest.

Definition at line 79 of file test_pickling.py.

00079 
00080     def dumps(self, item):
00081         return pickle.dumps(item, 2)

Here is the call graph for this function:

Here is the caller graph for this function:

def ctypes.test.test_pickling.PickleTest.loads (   self,
  item 
) [inherited]

Definition at line 21 of file test_pickling.py.

00021 
00022     def loads(self, item):
00023         return pickle.loads(item)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 24 of file test_pickling.py.

00024 
00025     def test_simple(self):
00026         for src in [
00027             c_int(42),
00028             c_double(3.14),
00029             ]:
00030             dst = self.loads(self.dumps(src))
00031             self.assertEqual(src.__dict__, dst.__dict__)
00032             self.assertEqual(memoryview(src).tobytes(),
00033                                  memoryview(dst).tobytes())

Here is the call graph for this function:

Definition at line 34 of file test_pickling.py.

00034 
00035     def test_struct(self):
00036         X.init_called = 0
00037 
00038         x = X()
00039         x.a = 42
00040         self.assertEqual(X.init_called, 1)
00041 
00042         y = self.loads(self.dumps(x))
00043 
00044         # loads must NOT call __init__
00045         self.assertEqual(X.init_called, 1)
00046 
00047         # ctypes instances are identical when the instance __dict__
00048         # and the memory buffer are identical
00049         self.assertEqual(y.__dict__, x.__dict__)
00050         self.assertEqual(memoryview(y).tobytes(),
00051                              memoryview(x).tobytes())

Here is the call graph for this function:

Definition at line 52 of file test_pickling.py.

00052 
00053     def test_unpickable(self):
00054         # ctypes objects that are pointers or contain pointers are
00055         # unpickable.
00056         self.assertRaises(ValueError, lambda: self.dumps(Y()))
00057 
00058         prototype = CFUNCTYPE(c_int)
00059 
00060         for item in [
00061             c_char_p(),
00062             c_wchar_p(),
00063             c_void_p(),
00064             pointer(c_int(42)),
00065             dll._testfunc_p_p,
00066             prototype(lambda: 42),
00067             ]:
00068             self.assertRaises(ValueError, lambda: self.dumps(item))

Here is the call graph for this function:

Definition at line 69 of file test_pickling.py.

00069 
00070     def test_wchar(self):
00071         pickle.dumps(c_char(b"x"))
00072         # Issue 5049
00073         pickle.dumps(c_wchar("x"))

Here is the call graph for this function:


The documentation for this class was generated from the following file: