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')
26 test_support
.unlink(test_support
.TESTFN
)
27 test_support
.unlink(TESTFN2
)
29 def compareData(self
):
30 fp
= open(test_support
.TESTFN
, 'r')
33 fp
= open(TESTFN2
, 'r')
37 return 'Data forks differ'
38 rfp
= MacOS
.openrf(test_support
.TESTFN
, '*rb')
39 data1
= rfp
.read(1000)
41 rfp
= MacOS
.openrf(TESTFN2
, '*rb')
42 data2
= rfp
.read(1000)
45 return 'Resource forks differ'
48 def test_touched(self
):
49 # This really only tests that nothing unforeseen happens.
50 with test_support
.check_warnings(('macostools.touched*',
51 DeprecationWarning), quiet
=True):
52 macostools
.touched(test_support
.TESTFN
)
54 if sys
.maxint
< 2**32:
56 test_support
.unlink(TESTFN2
)
57 macostools
.copy(test_support
.TESTFN
, TESTFN2
)
58 self
.assertEqual(self
.compareData(), '')
60 if sys
.maxint
< 2**32:
61 def test_mkalias(self
):
62 test_support
.unlink(TESTFN2
)
63 macostools
.mkalias(test_support
.TESTFN
, TESTFN2
)
64 fss
, _
, _
= Carbon
.File
.ResolveAliasFile(TESTFN2
, 0)
65 self
.assertEqual(fss
.as_pathname(), os
.path
.realpath(test_support
.TESTFN
))
67 def test_mkalias_relative(self
):
68 test_support
.unlink(TESTFN2
)
69 # If the directory doesn't exist, then chances are this is a new
70 # install of Python so don't create it since the user might end up
71 # running ``sudo make install`` and creating the directory here won't
72 # leave it with the proper permissions.
73 if not os
.path
.exists(sys
.prefix
):
75 macostools
.mkalias(test_support
.TESTFN
, TESTFN2
, sys
.prefix
)
76 fss
, _
, _
= Carbon
.File
.ResolveAliasFile(TESTFN2
, 0)
77 self
.assertEqual(fss
.as_pathname(), os
.path
.realpath(test_support
.TESTFN
))
81 # Skip on wide unicode
82 if len(u
'\0'.encode('unicode-internal')) == 4:
83 raise unittest
.SkipTest("test_macostools is broken in USC4")
84 test_support
.run_unittest(TestMacostools
)
87 if __name__
== '__main__':