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 0011 TESTFN2 = test_support.TESTFN + '2' 0012 0013 class TestMacostools(unittest.TestCase): 0014 0015 def setUp(self): 0016 fp = open(test_support.TESTFN, 'w') 0017 fp.write('hello world\n') 0018 fp.close() 0019 rfp = MacOS.openrf(test_support.TESTFN, '*wb') 0020 rfp.write('goodbye world\n') 0021 rfp.close() 0022 0023 def tearDown(self): 0024 try: 0025 os.unlink(test_support.TESTFN) 0026 except: 0027 pass 0028 try: 0029 os.unlink(TESTFN2) 0030 except: 0031 pass 0032 0033 def compareData(self): 0034 fp = open(test_support.TESTFN, 'r') 0035 data1 = fp.read() 0036 fp.close() 0037 fp = open(TESTFN2, 'r') 0038 data2 = fp.read() 0039 fp.close() 0040 if data1 != data2: 0041 return 'Data forks differ' 0042 rfp = MacOS.openrf(test_support.TESTFN, '*rb') 0043 data1 = rfp.read(1000) 0044 rfp.close() 0045 rfp = MacOS.openrf(TESTFN2, '*rb') 0046 data2 = rfp.read(1000) 0047 rfp.close() 0048 if data1 != data2: 0049 return 'Resource forks differ' 0050 return '' 0051 0052 def test_touched(self): 0053 # This really only tests that nothing unforeseen happens. 0054 macostools.touched(test_support.TESTFN) 0055 0056 def test_copy(self): 0057 try: 0058 os.unlink(TESTFN2) 0059 except: 0060 pass 0061 macostools.copy(test_support.TESTFN, TESTFN2) 0062 self.assertEqual(self.compareData(), '') 0063 0064 def test_mkalias(self): 0065 try: 0066 os.unlink(TESTFN2) 0067 except: 0068 pass 0069 macostools.mkalias(test_support.TESTFN, TESTFN2) 0070 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0) 0071 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN)) 0072 0073 def test_mkalias_relative(self): 0074 try: 0075 os.unlink(TESTFN2) 0076 except: 0077 pass 0078 macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix) 0079 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0) 0080 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN)) 0081 0082 0083 def test_main(): 0084 test_support.run_unittest(TestMacostools) 0085 0086 0087 if __name__ == '__main__': 0088 test_main() 0089
Generated by PyXR 0.9.4