test_aepack.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright (C) 2003 Python Software Foundation
  2. import unittest
  3. import os
  4. from test import test_support
  5. aetypes = test_support.import_module('aetypes')
  6. aepack = test_support.import_module('aepack')
  7. class TestAepack(unittest.TestCase):
  8. OBJECTS = [
  9. aetypes.Enum('enum'),
  10. aetypes.Type('type'),
  11. aetypes.Keyword('kwrd'),
  12. aetypes.Range(1, 10),
  13. aetypes.Comparison(1, '< ', 10),
  14. aetypes.Logical('not ', 1),
  15. aetypes.IntlText(0, 0, 'international text'),
  16. aetypes.IntlWritingCode(0,0),
  17. aetypes.QDPoint(50,100),
  18. aetypes.QDRectangle(50,100,150,200),
  19. aetypes.RGBColor(0x7000, 0x6000, 0x5000),
  20. aetypes.Unknown('xxxx', 'unknown type data'),
  21. aetypes.Character(1),
  22. aetypes.Character(2, aetypes.Line(2)),
  23. ]
  24. def test_roundtrip_string(self):
  25. o = 'a string'
  26. packed = aepack.pack(o)
  27. unpacked = aepack.unpack(packed)
  28. self.assertEqual(o, unpacked)
  29. def test_roundtrip_int(self):
  30. o = 12
  31. packed = aepack.pack(o)
  32. unpacked = aepack.unpack(packed)
  33. self.assertEqual(o, unpacked)
  34. def test_roundtrip_float(self):
  35. o = 12.1
  36. packed = aepack.pack(o)
  37. unpacked = aepack.unpack(packed)
  38. self.assertEqual(o, unpacked)
  39. def test_roundtrip_None(self):
  40. o = None
  41. packed = aepack.pack(o)
  42. unpacked = aepack.unpack(packed)
  43. self.assertEqual(o, unpacked)
  44. def test_roundtrip_aeobjects(self):
  45. for o in self.OBJECTS:
  46. packed = aepack.pack(o)
  47. unpacked = aepack.unpack(packed)
  48. self.assertEqual(repr(o), repr(unpacked))
  49. def test_roundtrip_FSSpec(self):
  50. try:
  51. import Carbon.File
  52. except:
  53. self.skipTest('Carbon.File not available')
  54. if not hasattr(Carbon.File, "FSSpec"):
  55. self.skipTest('Carbon.File.FSSpec not available')
  56. o = Carbon.File.FSSpec(os.curdir)
  57. packed = aepack.pack(o)
  58. unpacked = aepack.unpack(packed)
  59. self.assertEqual(o.as_pathname(), unpacked.as_pathname())
  60. def test_roundtrip_Alias(self):
  61. try:
  62. import Carbon.File
  63. except:
  64. self.skipTest('Carbon.File not available')
  65. if not hasattr(Carbon.File, "FSSpec"):
  66. self.skipTest('Carbon.File.FSSpec not available')
  67. o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
  68. packed = aepack.pack(o)
  69. unpacked = aepack.unpack(packed)
  70. self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
  71. unpacked.FSResolveAlias(None)[0].as_pathname())
  72. def test_main():
  73. test_support.run_unittest(TestAepack)
  74. if __name__ == '__main__':
  75. test_main()