1 # Copyright (C) 2003 Python Software Foundation
6 from test
import test_support
8 MacOS
= test_support
.import_module('MacOS')
9 #The following modules should exist if MacOS exists.
13 TESTFN2
= test_support
.TESTFN
+ '2'
15 class TestMacostools(unittest
.TestCase
):
18 fp
= open(test_support
.TESTFN
, 'w')
19 fp
.write('hello world\n')
21 rfp
= MacOS
.openrf(test_support
.TESTFN
, '*wb')
22 rfp
.write('goodbye world\n')
27 os
.unlink(test_support
.TESTFN
)
35 def compareData(self
):
36 fp
= open(test_support
.TESTFN
, 'r')
39 fp
= open(TESTFN2
, 'r')
43 return 'Data forks differ'
44 rfp
= MacOS
.openrf(test_support
.TESTFN
, '*rb')
45 data1
= rfp
.read(1000)
47 rfp
= MacOS
.openrf(TESTFN2
, '*rb')
48 data2
= rfp
.read(1000)
51 return 'Resource forks differ'
54 def test_touched(self
):
55 # This really only tests that nothing unforeseen happens.
57 with warnings
.catch_warnings():
58 warnings
.filterwarnings('ignore', 'macostools.touched*',
60 macostools
.touched(test_support
.TESTFN
)
67 macostools
.copy(test_support
.TESTFN
, TESTFN2
)
68 self
.assertEqual(self
.compareData(), '')
70 def test_mkalias(self
):
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
))
79 def test_mkalias_relative(self
):
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
):
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
))
96 # Skip on wide unicode
97 if len(u
'\0'.encode('unicode-internal')) == 4:
98 raise unittest
.SkipTest("test_macostools is broken in USC4")
99 test_support
.run_unittest(TestMacostools
)
102 if __name__
== '__main__':