0001 # Copyright (C) 2003 Python Software Foundation 0002 0003 import unittest 0004 import aepack 0005 import aetypes 0006 import os 0007 from test import test_support 0008 0009 class TestAepack(unittest.TestCase): 0010 OBJECTS = [ 0011 aetypes.Enum('enum'), 0012 aetypes.Type('type'), 0013 aetypes.Keyword('kwrd'), 0014 aetypes.Range(1, 10), 0015 aetypes.Comparison(1, '< ', 10), 0016 aetypes.Logical('not ', 1), 0017 aetypes.IntlText(0, 0, 'international text'), 0018 aetypes.IntlWritingCode(0,0), 0019 aetypes.QDPoint(50,100), 0020 aetypes.QDRectangle(50,100,150,200), 0021 aetypes.RGBColor(0x7000, 0x6000, 0x5000), 0022 aetypes.Unknown('xxxx', 'unknown type data'), 0023 aetypes.Character(1), 0024 aetypes.Character(2, aetypes.Line(2)), 0025 ] 0026 0027 def test_roundtrip_string(self): 0028 o = 'a string' 0029 packed = aepack.pack(o) 0030 unpacked = aepack.unpack(packed) 0031 self.assertEqual(o, unpacked) 0032 0033 def test_roundtrip_int(self): 0034 o = 12 0035 packed = aepack.pack(o) 0036 unpacked = aepack.unpack(packed) 0037 self.assertEqual(o, unpacked) 0038 0039 def test_roundtrip_float(self): 0040 o = 12.1 0041 packed = aepack.pack(o) 0042 unpacked = aepack.unpack(packed) 0043 self.assertEqual(o, unpacked) 0044 0045 def test_roundtrip_None(self): 0046 o = None 0047 packed = aepack.pack(o) 0048 unpacked = aepack.unpack(packed) 0049 self.assertEqual(o, unpacked) 0050 0051 def test_roundtrip_aeobjects(self): 0052 for o in self.OBJECTS: 0053 packed = aepack.pack(o) 0054 unpacked = aepack.unpack(packed) 0055 self.assertEqual(repr(o), repr(unpacked)) 0056 0057 def test_roundtrip_FSSpec(self): 0058 try: 0059 import Carbon.File 0060 except: 0061 return 0062 o = Carbon.File.FSSpec(os.curdir) 0063 packed = aepack.pack(o) 0064 unpacked = aepack.unpack(packed) 0065 self.assertEqual(o.as_pathname(), unpacked.as_pathname()) 0066 0067 def test_roundtrip_Alias(self): 0068 try: 0069 import Carbon.File 0070 except: 0071 return 0072 o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal() 0073 packed = aepack.pack(o) 0074 unpacked = aepack.unpack(packed) 0075 self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(), 0076 unpacked.FSResolveAlias(None)[0].as_pathname()) 0077 0078 0079 def test_main(): 0080 test_support.run_unittest(TestAepack) 0081 0082 0083 if __name__ == '__main__': 0084 test_main() 0085
Generated by PyXR 0.9.4