PageRenderTime 55ms CodeModel.GetById 43ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/test/test_aepack.py

http://unladen-swallow.googlecode.com/
Python | 89 lines | 74 code | 14 blank | 1 comment | 7 complexity | 07d0b23648a30765e6aae2afd2b0657d MD5 | raw file
 1# Copyright (C) 2003 Python Software Foundation
 2
 3import unittest
 4import aepack
 5import aetypes
 6import os
 7from test import test_support
 8
 9class TestAepack(unittest.TestCase):
10    OBJECTS = [
11        aetypes.Enum('enum'),
12        aetypes.Type('type'),
13        aetypes.Keyword('kwrd'),
14        aetypes.Range(1, 10),
15        aetypes.Comparison(1, '<   ', 10),
16        aetypes.Logical('not ', 1),
17        aetypes.IntlText(0, 0, 'international text'),
18        aetypes.IntlWritingCode(0,0),
19        aetypes.QDPoint(50,100),
20        aetypes.QDRectangle(50,100,150,200),
21        aetypes.RGBColor(0x7000, 0x6000, 0x5000),
22        aetypes.Unknown('xxxx', 'unknown type data'),
23        aetypes.Character(1),
24        aetypes.Character(2, aetypes.Line(2)),
25    ]
26
27    def test_roundtrip_string(self):
28        o = 'a string'
29        packed = aepack.pack(o)
30        unpacked = aepack.unpack(packed)
31        self.assertEqual(o, unpacked)
32
33    def test_roundtrip_int(self):
34        o = 12
35        packed = aepack.pack(o)
36        unpacked = aepack.unpack(packed)
37        self.assertEqual(o, unpacked)
38
39    def test_roundtrip_float(self):
40        o = 12.1
41        packed = aepack.pack(o)
42        unpacked = aepack.unpack(packed)
43        self.assertEqual(o, unpacked)
44
45    def test_roundtrip_None(self):
46        o = None
47        packed = aepack.pack(o)
48        unpacked = aepack.unpack(packed)
49        self.assertEqual(o, unpacked)
50
51    def test_roundtrip_aeobjects(self):
52        for o in self.OBJECTS:
53            packed = aepack.pack(o)
54            unpacked = aepack.unpack(packed)
55            self.assertEqual(repr(o), repr(unpacked))
56
57    def test_roundtrip_FSSpec(self):
58        try:
59            import Carbon.File
60        except:
61            return
62
63        if not hasattr(Carbon.File, "FSSpec"):
64            return
65        o = Carbon.File.FSSpec(os.curdir)
66        packed = aepack.pack(o)
67        unpacked = aepack.unpack(packed)
68        self.assertEqual(o.as_pathname(), unpacked.as_pathname())
69
70    def test_roundtrip_Alias(self):
71        try:
72            import Carbon.File
73        except:
74            return
75        if not hasattr(Carbon.File, "FSSpec"):
76            return
77        o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
78        packed = aepack.pack(o)
79        unpacked = aepack.unpack(packed)
80        self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
81            unpacked.FSResolveAlias(None)[0].as_pathname())
82
83
84def test_main():
85    test_support.run_unittest(TestAepack)
86
87
88if __name__ == '__main__':
89    test_main()