blob: 5d4ab3e20b0797a37ebb0ab8fd397e1a4f9e02bc [file] [log] [blame]
Jack Jansen090da4b2003-01-29 10:41:18 +00001# Copyright (C) 2003 Python Software Foundation
2
3import unittest
Jack Jansen090da4b2003-01-29 10:41:18 +00004import os
5from test import test_support
6
R. David Murray59beec32009-03-30 19:04:00 +00007aetypes = test_support.import_module('aetypes')
8aepack = test_support.import_module('aepack')
9
Jack Jansen090da4b2003-01-29 10:41:18 +000010class TestAepack(unittest.TestCase):
11 OBJECTS = [
12 aetypes.Enum('enum'),
13 aetypes.Type('type'),
14 aetypes.Keyword('kwrd'),
15 aetypes.Range(1, 10),
16 aetypes.Comparison(1, '< ', 10),
17 aetypes.Logical('not ', 1),
18 aetypes.IntlText(0, 0, 'international text'),
19 aetypes.IntlWritingCode(0,0),
20 aetypes.QDPoint(50,100),
21 aetypes.QDRectangle(50,100,150,200),
22 aetypes.RGBColor(0x7000, 0x6000, 0x5000),
23 aetypes.Unknown('xxxx', 'unknown type data'),
24 aetypes.Character(1),
25 aetypes.Character(2, aetypes.Line(2)),
26 ]
27
28 def test_roundtrip_string(self):
29 o = 'a string'
30 packed = aepack.pack(o)
31 unpacked = aepack.unpack(packed)
32 self.assertEqual(o, unpacked)
33
34 def test_roundtrip_int(self):
35 o = 12
36 packed = aepack.pack(o)
37 unpacked = aepack.unpack(packed)
38 self.assertEqual(o, unpacked)
39
40 def test_roundtrip_float(self):
41 o = 12.1
42 packed = aepack.pack(o)
43 unpacked = aepack.unpack(packed)
44 self.assertEqual(o, unpacked)
45
46 def test_roundtrip_None(self):
47 o = None
48 packed = aepack.pack(o)
49 unpacked = aepack.unpack(packed)
50 self.assertEqual(o, unpacked)
51
52 def test_roundtrip_aeobjects(self):
53 for o in self.OBJECTS:
54 packed = aepack.pack(o)
55 unpacked = aepack.unpack(packed)
56 self.assertEqual(repr(o), repr(unpacked))
Tim Petersf2715e02003-02-19 02:35:07 +000057
Jack Jansen090da4b2003-01-29 10:41:18 +000058 def test_roundtrip_FSSpec(self):
59 try:
60 import Carbon.File
61 except:
62 return
63 o = Carbon.File.FSSpec(os.curdir)
64 packed = aepack.pack(o)
65 unpacked = aepack.unpack(packed)
66 self.assertEqual(o.as_pathname(), unpacked.as_pathname())
67
68 def test_roundtrip_Alias(self):
69 try:
70 import Carbon.File
71 except:
72 return
73 o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
74 packed = aepack.pack(o)
75 unpacked = aepack.unpack(packed)
Tim Petersf2715e02003-02-19 02:35:07 +000076 self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
Jack Jansen090da4b2003-01-29 10:41:18 +000077 unpacked.FSResolveAlias(None)[0].as_pathname())
Tim Petersf2715e02003-02-19 02:35:07 +000078
Jack Jansen090da4b2003-01-29 10:41:18 +000079
80def test_main():
81 test_support.run_unittest(TestAepack)
82
83
84if __name__ == '__main__':
85 test_main()