0001 # Copyright (C) 2003 Python Software Foundation 0002 0003 import unittest 0004 import macostools 0005 import Carbon.File 0006 import MacOS 0007 import os 0008 import sys 0009 from test import test_support 0010 import struct 0011 import applesingle 0012 0013 AS_MAGIC=0x00051600 0014 AS_VERSION=0x00020000 0015 dataforkdata = 'hello\r\0world\n' 0016 resourceforkdata = 'goodbye\ncruel\0world\r' 0017 0018 applesingledata = struct.pack("ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \ 0019 struct.pack("llllll", 1, 50, len(dataforkdata), 0020 2, 50+len(dataforkdata), len(resourceforkdata)) + \ 0021 dataforkdata + \ 0022 resourceforkdata 0023 TESTFN2 = test_support.TESTFN + '2' 0024 0025 class TestApplesingle(unittest.TestCase): 0026 0027 def setUp(self): 0028 fp = open(test_support.TESTFN, 'w') 0029 fp.write(applesingledata) 0030 fp.close() 0031 0032 def tearDown(self): 0033 try: 0034 os.unlink(test_support.TESTFN) 0035 except: 0036 pass 0037 try: 0038 os.unlink(TESTFN2) 0039 except: 0040 pass 0041 0042 def compareData(self, isrf, data): 0043 if isrf: 0044 fp = MacOS.openrf(TESTFN2, '*rb') 0045 else: 0046 fp = open(TESTFN2, 'rb') 0047 filedata = fp.read(1000) 0048 self.assertEqual(data, filedata) 0049 0050 def test_applesingle(self): 0051 try: 0052 os.unlink(TESTFN2) 0053 except: 0054 pass 0055 applesingle.decode(test_support.TESTFN, TESTFN2) 0056 self.compareData(False, dataforkdata) 0057 self.compareData(True, resourceforkdata) 0058 0059 def test_applesingle_resonly(self): 0060 try: 0061 os.unlink(TESTFN2) 0062 except: 0063 pass 0064 applesingle.decode(test_support.TESTFN, TESTFN2, resonly=True) 0065 self.compareData(False, resourceforkdata) 0066 0067 def test_main(): 0068 test_support.run_unittest(TestApplesingle) 0069 0070 0071 if __name__ == '__main__': 0072 test_main() 0073
Generated by PyXR 0.9.4