Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 1 | # Copyright (C) 2003 Python Software Foundation |
| 2 | |
| 3 | import unittest |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 4 | import os |
| 5 | from test import test_support |
| 6 | |
R. David Murray | 59beec3 | 2009-03-30 19:04:00 +0000 | [diff] [blame] | 7 | aetypes = test_support.import_module('aetypes') |
| 8 | aepack = test_support.import_module('aepack') |
| 9 | |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 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)) |
Tim Peters | f2715e0 | 2003-02-19 02:35:07 +0000 | [diff] [blame] | 57 | |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 58 | def test_roundtrip_FSSpec(self): |
| 59 | try: |
| 60 | import Carbon.File |
| 61 | except: |
Zachary Ware | 1f70221 | 2013-12-10 14:09:20 -0600 | [diff] [blame] | 62 | self.skipTest('Carbon.File not available') |
Ronald Oussoren | 2596758 | 2009-09-06 10:00:26 +0000 | [diff] [blame] | 63 | |
| 64 | if not hasattr(Carbon.File, "FSSpec"): |
Zachary Ware | 1f70221 | 2013-12-10 14:09:20 -0600 | [diff] [blame] | 65 | self.skipTest('Carbon.File.FSSpec not available') |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 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: |
Zachary Ware | 1f70221 | 2013-12-10 14:09:20 -0600 | [diff] [blame] | 75 | self.skipTest('Carbon.File not available') |
Ronald Oussoren | 2596758 | 2009-09-06 10:00:26 +0000 | [diff] [blame] | 76 | if not hasattr(Carbon.File, "FSSpec"): |
Zachary Ware | 1f70221 | 2013-12-10 14:09:20 -0600 | [diff] [blame] | 77 | self.skipTest('Carbon.File.FSSpec not available') |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 78 | o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal() |
| 79 | packed = aepack.pack(o) |
| 80 | unpacked = aepack.unpack(packed) |
Tim Peters | f2715e0 | 2003-02-19 02:35:07 +0000 | [diff] [blame] | 81 | self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(), |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 82 | unpacked.FSResolveAlias(None)[0].as_pathname()) |
Tim Peters | f2715e0 | 2003-02-19 02:35:07 +0000 | [diff] [blame] | 83 | |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 84 | |
| 85 | def test_main(): |
| 86 | test_support.run_unittest(TestAepack) |
| 87 | |
| 88 | |
| 89 | if __name__ == '__main__': |
| 90 | test_main() |