summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2003-01-29 10:41:18 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2003-01-29 10:41:18 (GMT)
commit090da4b626fe7cd4d642cc5e6e03041d97d80ffd (patch)
treee7177ebf07702f1e0998aaf2a57508ad76cbf7ce
parent0502d89b49cd2f6ec6c082ef6eb3574a85b7321e (diff)
downloadcpython-090da4b626fe7cd4d642cc5e6e03041d97d80ffd.zip
cpython-090da4b626fe7cd4d642cc5e6e03041d97d80ffd.tar.gz
cpython-090da4b626fe7cd4d642cc5e6e03041d97d80ffd.tar.bz2
Moved aepack test code to the test suite.
-rw-r--r--Lib/plat-mac/aepack.py40
-rwxr-xr-xLib/test/test_aepack.py84
2 files changed, 84 insertions, 40 deletions
diff --git a/Lib/plat-mac/aepack.py b/Lib/plat-mac/aepack.py
index 6797473..bfe539a 100644
--- a/Lib/plat-mac/aepack.py
+++ b/Lib/plat-mac/aepack.py
@@ -343,43 +343,3 @@ def mkobjectfrommodule(dict, modulename):
if classtype:
newobj.__class__ = classtype
return newobj
-
-def _test():
- """Test program. Pack and unpack various things"""
- objs = [
- 'a string',
- 12,
- 12.0,
- None,
- ['a', 'list', 'of', 'strings'],
- {'key1': 'value1', 'key2':'value2'},
- Carbon.File.FSSpec(os.curdir),
- Carbon.File.FSSpec(os.curdir).NewAliasMinimal(),
- aetypes.Enum('enum'),
- aetypes.Type('type'),
- aetypes.Keyword('kwrd'),
- aetypes.Range(1, 10),
- aetypes.Comparison(1, '< ', 10),
- aetypes.Logical('not ', 1),
- # Cannot do StyledText
- # Cannot do AEText
- aetypes.IntlText(0, 0, 'international text'),
- aetypes.IntlWritingCode(0,0),
- aetypes.QDPoint(50,100),
- aetypes.QDRectangle(50,100,150,200),
- aetypes.RGBColor(0x7000, 0x6000, 0x5000),
- aetypes.Unknown('xxxx', 'unknown type data'),
- aetypes.Character(1),
- aetypes.Character(2, aetypes.Line(2)),
- ]
- for o in objs:
- print 'BEFORE', o, `o`
- packed = pack(o)
- unpacked = unpack(packed)
- print 'AFTER ', unpacked, `unpacked`
- import sys
- sys.exit(1)
-
-if __name__ == '__main__':
- _test()
-
diff --git a/Lib/test/test_aepack.py b/Lib/test/test_aepack.py
new file mode 100755
index 0000000..70b89de
--- /dev/null
+++ b/Lib/test/test_aepack.py
@@ -0,0 +1,84 @@
+# Copyright (C) 2003 Python Software Foundation
+
+import unittest
+import aepack
+import aetypes
+import os
+from test import test_support
+
+class TestAepack(unittest.TestCase):
+ OBJECTS = [
+ aetypes.Enum('enum'),
+ aetypes.Type('type'),
+ aetypes.Keyword('kwrd'),
+ aetypes.Range(1, 10),
+ aetypes.Comparison(1, '< ', 10),
+ aetypes.Logical('not ', 1),
+ aetypes.IntlText(0, 0, 'international text'),
+ aetypes.IntlWritingCode(0,0),
+ aetypes.QDPoint(50,100),
+ aetypes.QDRectangle(50,100,150,200),
+ aetypes.RGBColor(0x7000, 0x6000, 0x5000),
+ aetypes.Unknown('xxxx', 'unknown type data'),
+ aetypes.Character(1),
+ aetypes.Character(2, aetypes.Line(2)),
+ ]
+
+ def test_roundtrip_string(self):
+ o = 'a string'
+ packed = aepack.pack(o)
+ unpacked = aepack.unpack(packed)
+ self.assertEqual(o, unpacked)
+
+ def test_roundtrip_int(self):
+ o = 12
+ packed = aepack.pack(o)
+ unpacked = aepack.unpack(packed)
+ self.assertEqual(o, unpacked)
+
+ def test_roundtrip_float(self):
+ o = 12.1
+ packed = aepack.pack(o)
+ unpacked = aepack.unpack(packed)
+ self.assertEqual(o, unpacked)
+
+ def test_roundtrip_None(self):
+ o = None
+ packed = aepack.pack(o)
+ unpacked = aepack.unpack(packed)
+ self.assertEqual(o, unpacked)
+
+ def test_roundtrip_aeobjects(self):
+ for o in self.OBJECTS:
+ packed = aepack.pack(o)
+ unpacked = aepack.unpack(packed)
+ self.assertEqual(repr(o), repr(unpacked))
+
+ def test_roundtrip_FSSpec(self):
+ try:
+ import Carbon.File
+ except:
+ return
+ o = Carbon.File.FSSpec(os.curdir)
+ packed = aepack.pack(o)
+ unpacked = aepack.unpack(packed)
+ self.assertEqual(o.as_pathname(), unpacked.as_pathname())
+
+ def test_roundtrip_Alias(self):
+ try:
+ import Carbon.File
+ except:
+ return
+ o = Carbon.File.FSSpec(os.curdir).NewAliasMinimal()
+ packed = aepack.pack(o)
+ unpacked = aepack.unpack(packed)
+ self.assertEqual(o.FSResolveAlias(None)[0].as_pathname(),
+ unpacked.FSResolveAlias(None)[0].as_pathname())
+
+
+def test_main():
+ test_support.run_unittest(TestAepack)
+
+
+if __name__ == '__main__':
+ test_main()