~ubuntu-branches/ubuntu/raring/ipython/raring

« back to all changes in this revision

Viewing changes to IPython/kernel/tests/test_newserialized.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2011-11-22 23:40:57 UTC
  • mfrom: (6.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20111122234057-ta86ocdahnhwmnd8
Tags: 0.11-2
* upload to unstable
* add patch fix-version-checks-for-pyzmq-2.1.10.patch
* fix debianize-error-messages.patch to reraise unknown exceptions
* suggest python-zmq for ipython package
* use dh_sphinxdoc
  - bump sphinx dependency to >= 1.0.7+dfsg-1~, replace libjs-jquery
    dependency with ${sphinxdoc:Depends} and drop ipython-doc.links
* remove empty directory from ipython
* link duplicate images in ipython-doc
* remove obsolete Conflicts and Replaces

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# encoding: utf-8
2
 
 
3
 
"""This file contains unittests for the shell.py module."""
4
 
 
5
 
__docformat__ = "restructuredtext en"
6
 
 
7
 
#-----------------------------------------------------------------------------
8
 
#  Copyright (C) 2008  The IPython Development Team
9
 
#
10
 
#  Distributed under the terms of the BSD License.  The full license is in
11
 
#  the file COPYING, distributed as part of this software.
12
 
#-----------------------------------------------------------------------------
13
 
 
14
 
#-----------------------------------------------------------------------------
15
 
# Imports
16
 
#-----------------------------------------------------------------------------
17
 
 
18
 
# Tell nose to skip this module
19
 
__test__ = {}
20
 
 
21
 
import zope.interface as zi
22
 
from twisted.trial import unittest
23
 
from IPython.testing.util import DeferredTestCase
24
 
 
25
 
from IPython.kernel.newserialized import \
26
 
    ISerialized, \
27
 
    IUnSerialized, \
28
 
    Serialized, \
29
 
    UnSerialized, \
30
 
    SerializeIt, \
31
 
    UnSerializeIt
32
 
 
33
 
 
34
 
#-----------------------------------------------------------------------------
35
 
# Tests
36
 
#-----------------------------------------------------------------------------
37
 
 
38
 
class SerializedTestCase(unittest.TestCase):
39
 
 
40
 
    def setUp(self):
41
 
        pass
42
 
    
43
 
    def tearDown(self):
44
 
        pass
45
 
    
46
 
    def testSerializedInterfaces(self):
47
 
 
48
 
        us = UnSerialized({'a':10, 'b':range(10)})
49
 
        s = ISerialized(us)
50
 
        uss = IUnSerialized(s)
51
 
        self.assert_(ISerialized.providedBy(s))
52
 
        self.assert_(IUnSerialized.providedBy(us))
53
 
        self.assert_(IUnSerialized.providedBy(uss))
54
 
        for m in list(ISerialized):
55
 
            self.assert_(hasattr(s, m))
56
 
        for m in list(IUnSerialized):
57
 
            self.assert_(hasattr(us, m))
58
 
        for m in list(IUnSerialized):
59
 
            self.assert_(hasattr(uss, m))
60
 
 
61
 
    def testPickleSerialized(self):
62
 
        obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L}
63
 
        original = UnSerialized(obj)
64
 
        originalSer = ISerialized(original)
65
 
        firstData = originalSer.getData()
66
 
        firstTD = originalSer.getTypeDescriptor()
67
 
        firstMD = originalSer.getMetadata()
68
 
        self.assert_(firstTD == 'pickle')
69
 
        self.assert_(firstMD == {})
70
 
        unSerialized = IUnSerialized(originalSer)
71
 
        secondObj = unSerialized.getObject()
72
 
        for k, v in secondObj.iteritems():
73
 
            self.assert_(obj[k] == v)
74
 
        secondSer = ISerialized(UnSerialized(secondObj))
75
 
        self.assert_(firstData == secondSer.getData())
76
 
        self.assert_(firstTD == secondSer.getTypeDescriptor() )
77
 
        self.assert_(firstMD == secondSer.getMetadata())
78
 
    
79
 
    def testNDArraySerialized(self):
80
 
        try:
81
 
            import numpy
82
 
        except ImportError:
83
 
            pass
84
 
        else:
85
 
            a = numpy.linspace(0.0, 1.0, 1000)
86
 
            unSer1 = UnSerialized(a)
87
 
            ser1 = ISerialized(unSer1)
88
 
            td = ser1.getTypeDescriptor()
89
 
            self.assert_(td == 'ndarray')
90
 
            md = ser1.getMetadata()
91
 
            self.assert_(md['shape'] == a.shape)
92
 
            self.assert_(md['dtype'] == a.dtype.str)
93
 
            buff = ser1.getData()
94
 
            self.assert_(buff == numpy.getbuffer(a))
95
 
            s = Serialized(buff, td, md)
96
 
            us = IUnSerialized(s)
97
 
            final = us.getObject()
98
 
            self.assert_(numpy.getbuffer(a) == numpy.getbuffer(final))
99
 
            self.assert_(a.dtype.str == final.dtype.str)
100
 
            self.assert_(a.shape == final.shape)
101
 
        
102