File: pickle_validated_dict_test_case.py

package info (click to toggle)
matplotlib 0.98.1-1%2Blenny4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,624 kB
  • ctags: 22,599
  • sloc: python: 76,915; cpp: 63,459; ansic: 5,353; makefile: 111; sh: 12
file content (39 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from cPickle import dumps, loads
import unittest

from enthought.traits.api import Dict, HasTraits, Int, List

class C(HasTraits):

    # A dict trait containing a list trait
    a = Dict(Int, List(Int))

    # And we must initialize it to something non-trivial
    def __init__(self):
        super(C, self).__init__()
        self.a = {1 : [2,3]}

class PickleValidatedDictTestCase(unittest.TestCase):
    def test(self):

        # And we must unpickle one
        x = dumps(C())
        try:
            loads(x)
        except AttributeError, e:
            self.fail('Unpickling raised an AttributeError: %s' % e)

# Here is a hack to work around a testoob+traits error:
#
#   Traceback (most recent call last):
#     File "/src/enthought/src/lib/enthought/traits/tests/regression/pickle_validated_dict_test_case.py", line 21, in test
#       x = dumps(C())
#   PicklingError: Can't pickle <class 'pickle_validated_dict_test_case.C'>: import of module pickle_validated_dict_test_case failed
#
# We simply force the two classes to be the same.
import pickle_validated_dict_test_case
pickle_validated_dict_test_case.C = C

if __name__ == '__main__':
    import sys
    unittest.main(argv=sys.argv)