blob: f3292ced3298b49b3b50d7a89fa35bc19294b5af [file] [log] [blame]
Jack Jansen10882f62003-01-28 21:39:28 +00001# Copyright (C) 2003 Python Software Foundation
2
3import unittest
4import macostools
Jack Jansen98fc6832003-02-27 23:18:46 +00005import Carbon.File
Jack Jansen10882f62003-01-28 21:39:28 +00006import MacOS
7import os
Jack Jansenaddc5852003-01-28 23:54:05 +00008import sys
Jack Jansen10882f62003-01-28 21:39:28 +00009from test import test_support
10
11TESTFN2 = test_support.TESTFN + '2'
12
13class TestMacostools(unittest.TestCase):
14
15 def setUp(self):
16 fp = open(test_support.TESTFN, 'w')
17 fp.write('hello world\n')
18 fp.close()
19 rfp = MacOS.openrf(test_support.TESTFN, '*wb')
20 rfp.write('goodbye world\n')
21 rfp.close()
22
23 def tearDown(self):
24 try:
25 os.unlink(test_support.TESTFN)
26 except:
27 pass
28 try:
29 os.unlink(TESTFN2)
30 except:
31 pass
Tim Petersf2715e02003-02-19 02:35:07 +000032
Jack Jansen10882f62003-01-28 21:39:28 +000033 def compareData(self):
34 fp = open(test_support.TESTFN, 'r')
35 data1 = fp.read()
36 fp.close()
37 fp = open(TESTFN2, 'r')
38 data2 = fp.read()
39 fp.close()
40 if data1 != data2:
41 return 'Data forks differ'
42 rfp = MacOS.openrf(test_support.TESTFN, '*rb')
43 data1 = rfp.read(1000)
44 rfp.close()
45 rfp = MacOS.openrf(TESTFN2, '*rb')
46 data2 = rfp.read(1000)
47 rfp.close()
48 if data1 != data2:
49 return 'Resource forks differ'
50 return ''
Tim Petersf2715e02003-02-19 02:35:07 +000051
Jack Jansen10882f62003-01-28 21:39:28 +000052 def test_touched(self):
53 # This really only tests that nothing unforeseen happens.
54 macostools.touched(test_support.TESTFN)
Tim Petersf2715e02003-02-19 02:35:07 +000055
Jack Jansen10882f62003-01-28 21:39:28 +000056 def test_copy(self):
57 try:
58 os.unlink(TESTFN2)
59 except:
60 pass
61 macostools.copy(test_support.TESTFN, TESTFN2)
62 self.assertEqual(self.compareData(), '')
Tim Petersf2715e02003-02-19 02:35:07 +000063
Jack Jansenaddc5852003-01-28 23:54:05 +000064 def test_mkalias(self):
65 try:
66 os.unlink(TESTFN2)
67 except:
68 pass
69 macostools.mkalias(test_support.TESTFN, TESTFN2)
Jack Jansen98fc6832003-02-27 23:18:46 +000070 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
Jack Jansenb86a2e82003-02-05 11:14:16 +000071 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
Tim Petersf2715e02003-02-19 02:35:07 +000072
Jack Jansenaddc5852003-01-28 23:54:05 +000073 def test_mkalias_relative(self):
74 try:
75 os.unlink(TESTFN2)
76 except:
77 pass
Brett Cannonc8aa8482004-12-06 06:08:59 +000078 # If the directory doesn't exist, then chances are this is a new
79 # install of Python so don't create it since the user might end up
80 # running ``sudo make install`` and creating the directory here won't
81 # leave it with the proper permissions.
82 if not os.path.exists(sys.prefix):
83 return
Jack Jansenaddc5852003-01-28 23:54:05 +000084 macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix)
Jack Jansen98fc6832003-02-27 23:18:46 +000085 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
Jack Jansenb86a2e82003-02-05 11:14:16 +000086 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
Tim Petersf2715e02003-02-19 02:35:07 +000087
88
Jack Jansen10882f62003-01-28 21:39:28 +000089def test_main():
90 test_support.run_unittest(TestMacostools)
91
92
93if __name__ == '__main__':
94 test_main()