summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_aepack.py
blob: 8a4b035f05cf327ef7a972699863699d43ed337b (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright (C) 2003 Python Software Foundation

import unittest
import aepack
import aetypes
import os
from test import test_support

class TestAepack(unittest.TestCase):
    OBJECTS = [
        aetypes.Enum('enum'),
        aetypes.Type('type'),
        aetypes.Keyword('kwrd'),
        aetypes.Range(1, 10),
        aetypes.Comparison(1, '<   ', 10),
        aetypes.Logical('not ', 1),
        aetypes.IntlText(0, 0, 'international text'),
        aetypes.IntlWritingCode(0,0),
        aetypes.QDPoint(50,100),
        aetypes.QDRectangle(50,100,150,200),
        aetypes.RGBColor(0x7000, 0x6000, 0x5000),
        aetypes.Unknown('xxxx', 'unknown type data'),
        aetypes.Character(1),
        aetypes.Character(2, aetypes.Line(2)),
    ]

    def test_roundtrip_string(self):
        o = 'a string'
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_int(self):
        o = 12
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_float(self):
        o = 12.1
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_None(self):
        o = None
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o, unpacked)

    def test_roundtrip_aeobjects(self):
        for o in self.OBJECTS:
            packed = aepack.pack(o)
            unpacked = aepack.unpack(packed)
            self.assertEqual(repr(o), repr(unpacked))

    def test_roundtrip_FSSpec(self):
        try:
            import Carbon.File
        except:
            return
        o = Carbon.File.FSSpec(os.curdir)
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o.as_pathname(), unpacked.as_pathname())

    def test_roundtrip_Alias(self):
        try:
            import Carbon.File
        except:
            return
        o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
        packed = aepack.pack(o)
        unpacked = aepack.unpack(packed)
        self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
            unpacked.FSResolveAlias(None)[0].as_pathname())


def test_main():
    test_support.run_unittest(TestAepack)


if __name__ == '__main__':
    test_main()