| 1 |
|
| 2 |
|
| 3 |
import unittest |
| 4 |
import os |
| 5 |
from test import test_support |
| 6 |
|
| 7 |
aetypes = test_support.import_module('aetypes') |
| 8 |
aepack = test_support.import_module('aepack') |
| 9 |
|
| 10 |
class 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)) |
| 57 |
|
| 58 |
def test_roundtrip_FSSpec(self): |
| 59 |
try: |
| 60 |
import Carbon.File |
| 61 |
except: |
| 62 |
self.skipTest('Carbon.File not available') |
| 63 |
|
| 64 |
if not hasattr(Carbon.File, "FSSpec"): |
| 65 |
self.skipTest('Carbon.File.FSSpec not available') |
| 66 |
o = Carbon.File.FSSpec(os.curdir) |
| 67 |
packed = aepack.pack(o) |
| 68 |
unpacked = aepack.unpack(packed) |
| 69 |
self.assertEqual(o.as_pathname(), unpacked.as_pathname()) |
| 70 |
|
| 71 |
def test_roundtrip_Alias(self): |
| 72 |
try: |
| 73 |
import Carbon.File |
| 74 |
except: |
| 75 |
self.skipTest('Carbon.File not available') |
| 76 |
if not hasattr(Carbon.File, "FSSpec"): |
| 77 |
self.skipTest('Carbon.File.FSSpec not available') |
| 78 |
o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal() |
| 79 |
packed = aepack.pack(o) |
| 80 |
unpacked = aepack.unpack(packed) |
| 81 |
self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(), |
| 82 |
unpacked.FSResolveAlias(None)[0].as_pathname()) |
| 83 |
|
| 84 |
|
| 85 |
def test_main(): |
| 86 |
test_support.run_unittest(TestAepack) |
| 87 |
|
| 88 |
|
| 89 |
if __name__ == '__main__': |
| 90 |
test_main() |