blob: ac965acd40b072c27bcf536c3b00eb3e048a6c3b [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.
Brett Cannon5e263512007-05-20 23:17:38 +000054 import warnings
Brett Cannon672237d2008-09-09 00:49:16 +000055 with warnings.catch_warnings():
Brett Cannon5e263512007-05-20 23:17:38 +000056 warnings.filterwarnings('ignore', 'macostools.touched*',
57 DeprecationWarning)
58 macostools.touched(test_support.TESTFN)
Tim Petersf2715e02003-02-19 02:35:07 +000059
Ronald Oussoren4da7d782010-02-07 11:39:16 +000060 if sys.maxint < 2**32:
61 def test_copy(self):
62 try:
63 os.unlink(TESTFN2)
64 except:
65 pass
66 macostools.copy(test_support.TESTFN, TESTFN2)
67 self.assertEqual(self.compareData(), '')
Tim Petersf2715e02003-02-19 02:35:07 +000068
Ronald Oussoren4da7d782010-02-07 11:39:16 +000069 if sys.maxint < 2**32:
70 def test_mkalias(self):
71 try:
72 os.unlink(TESTFN2)
73 except:
74 pass
75 macostools.mkalias(test_support.TESTFN, TESTFN2)
76 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
77 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
Tim Petersf2715e02003-02-19 02:35:07 +000078
Ronald Oussoren4da7d782010-02-07 11:39:16 +000079 def test_mkalias_relative(self):
80 try:
81 os.unlink(TESTFN2)
82 except:
83 pass
84 # If the directory doesn't exist, then chances are this is a new
85 # install of Python so don't create it since the user might end up
86 # running ``sudo make install`` and creating the directory here won't
87 # leave it with the proper permissions.
88 if not os.path.exists(sys.prefix):
89 return
90 macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix)
91 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
92 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
Tim Petersf2715e02003-02-19 02:35:07 +000093
94
Jack Jansen10882f62003-01-28 21:39:28 +000095def test_main():
Benjamin Peterson6f5a2b52008-06-19 21:39:06 +000096 # Skip on wide unicode
97 if len(u'\0'.encode('unicode-internal')) == 4:
98 raise test_support.TestSkipped("test_macostools is broken in USC4")
Jack Jansen10882f62003-01-28 21:39:28 +000099 test_support.run_unittest(TestMacostools)
100
101
102if __name__ == '__main__':
103 test_main()