| 1 |
|
| 2 |
|
| 3 |
import unittest |
| 4 |
import os |
| 5 |
import sys |
| 6 |
from test import test_support |
| 7 |
|
| 8 |
MacOS = test_support.import_module('MacOS') |
| 9 |
|
| 10 |
import Carbon.File |
| 11 |
import macostools |
| 12 |
|
| 13 |
TESTFN2 = test_support.TESTFN + '2' |
| 14 |
|
| 15 |
requires_32bit = unittest.skipUnless(sys.maxint < 2**32, '32-bit only test') |
| 16 |
|
| 17 |
class TestMacostools(unittest.TestCase): |
| 18 |
|
| 19 |
def setUp(self): |
| 20 |
fp = open(test_support.TESTFN, 'w') |
| 21 |
fp.write('hello world\n') |
| 22 |
fp.close() |
| 23 |
rfp = MacOS.openrf(test_support.TESTFN, '*wb') |
| 24 |
rfp.write('goodbye world\n') |
| 25 |
rfp.close() |
| 26 |
|
| 27 |
def tearDown(self): |
| 28 |
test_support.unlink(test_support.TESTFN) |
| 29 |
test_support.unlink(TESTFN2) |
| 30 |
|
| 31 |
def compareData(self): |
| 32 |
fp = open(test_support.TESTFN, 'r') |
| 33 |
data1 = fp.read() |
| 34 |
fp.close() |
| 35 |
fp = open(TESTFN2, 'r') |
| 36 |
data2 = fp.read() |
| 37 |
fp.close() |
| 38 |
if data1 != data2: |
| 39 |
return 'Data forks differ' |
| 40 |
rfp = MacOS.openrf(test_support.TESTFN, '*rb') |
| 41 |
data1 = rfp.read(1000) |
| 42 |
rfp.close() |
| 43 |
rfp = MacOS.openrf(TESTFN2, '*rb') |
| 44 |
data2 = rfp.read(1000) |
| 45 |
rfp.close() |
| 46 |
if data1 != data2: |
| 47 |
return 'Resource forks differ' |
| 48 |
return '' |
| 49 |
|
| 50 |
def test_touched(self): |
| 51 |
|
| 52 |
with test_support.check_warnings(('macostools.touched*', |
| 53 |
DeprecationWarning), quiet=True): |
| 54 |
macostools.touched(test_support.TESTFN) |
| 55 |
|
| 56 |
@requires_32bit |
| 57 |
def test_copy(self): |
| 58 |
test_support.unlink(TESTFN2) |
| 59 |
macostools.copy(test_support.TESTFN, TESTFN2) |
| 60 |
self.assertEqual(self.compareData(), '') |
| 61 |
|
| 62 |
@requires_32bit |
| 63 |
def test_mkalias(self): |
| 64 |
test_support.unlink(TESTFN2) |
| 65 |
macostools.mkalias(test_support.TESTFN, TESTFN2) |
| 66 |
fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0) |
| 67 |
self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN)) |
| 68 |
|
| 69 |
@requires_32bit |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
@unittest.skipUnless(os.path.exists(sys.prefix), |
| 75 |
"%r doesn't exist" % sys.prefix) |
| 76 |
def test_mkalias_relative(self): |
| 77 |
test_support.unlink(TESTFN2) |
| 78 |
|
| 79 |
macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix) |
| 80 |
fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0) |
| 81 |
self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN)) |
| 82 |
|
| 83 |
|
| 84 |
def test_main(): |
| 85 |
|
| 86 |
if len(u'\0'.encode('unicode-internal')) == 4: |
| 87 |
raise unittest.SkipTest("test_macostools is broken in USC4") |
| 88 |
test_support.run_unittest(TestMacostools) |
| 89 |
|
| 90 |
|
| 91 |
if __name__ == '__main__': |
| 92 |
test_main() |