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