Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 1 | # Copyright (C) 2003 Python Software Foundation |
| 2 | |
| 3 | import unittest |
| 4 | import aepack |
| 5 | import aetypes |
| 6 | import os |
| 7 | from test import test_support |
| 8 | |
| 9 | class TestAepack(unittest.TestCase): |
| 10 | OBJECTS = [ |
Guido van Rossum | f7a94e4 | 2007-07-27 04:41:00 +0000 | [diff] [blame] | 11 | aetypes.Enum(b'enum'), |
| 12 | aetypes.Type(b'type'), |
| 13 | aetypes.Keyword(b'kwrd'), |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 14 | aetypes.Range(1, 10), |
Guido van Rossum | f7a94e4 | 2007-07-27 04:41:00 +0000 | [diff] [blame] | 15 | aetypes.Comparison(1, b'< ', 10), |
| 16 | aetypes.Logical(b'not ', 1), |
| 17 | aetypes.IntlText(0, 0, b'international text'), |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 18 | aetypes.IntlWritingCode(0,0), |
| 19 | aetypes.QDPoint(50,100), |
| 20 | aetypes.QDRectangle(50,100,150,200), |
| 21 | aetypes.RGBColor(0x7000, 0x6000, 0x5000), |
Guido van Rossum | f7a94e4 | 2007-07-27 04:41:00 +0000 | [diff] [blame] | 22 | aetypes.Unknown(b'xxxx', b'unknown type data'), |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 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)) |
Tim Peters | f2715e0 | 2003-02-19 02:35:07 +0000 | [diff] [blame] | 56 | |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 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) |
Tim Peters | f2715e0 | 2003-02-19 02:35:07 +0000 | [diff] [blame] | 75 | self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(), |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 76 | unpacked.FSResolveAlias(None)[0].as_pathname()) |
Tim Peters | f2715e0 | 2003-02-19 02:35:07 +0000 | [diff] [blame] | 77 | |
Jack Jansen | 090da4b | 2003-01-29 10:41:18 +0000 | [diff] [blame] | 78 | |
| 79 | def test_main(): |
| 80 | test_support.run_unittest(TestAepack) |
| 81 | |
| 82 | |
| 83 | if __name__ == '__main__': |
| 84 | test_main() |