Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / test / test_aepack.py
CommitLineData
920dae64
AT
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 o = Carbon.File.FSSpec(os.curdir)
63 packed = aepack.pack(o)
64 unpacked = aepack.unpack(packed)
65 self.assertEqual(o.as_pathname(), unpacked.as_pathname())
66
67 def test_roundtrip_Alias(self):
68 try:
69 import Carbon.File
70 except:
71 return
72 o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
73 packed = aepack.pack(o)
74 unpacked = aepack.unpack(packed)
75 self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
76 unpacked.FSResolveAlias(None)[0].as_pathname())
77
78
79def test_main():
80 test_support.run_unittest(TestAepack)
81
82
83if __name__ == '__main__':
84 test_main()