blob: aa6591911f1312c78a1bc0268e323bfa4eaaad5e [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):
Ezio Melotti1d55ec32010-08-02 23:34:49 +000024 test_support.unlink(test_support.TESTFN)
25 test_support.unlink(TESTFN2)
Tim Petersf2715e02003-02-19 02:35:07 +000026
Jack Jansen10882f62003-01-28 21:39:28 +000027 def compareData(self):
28 fp = open(test_support.TESTFN, 'r')
29 data1 = fp.read()
30 fp.close()
31 fp = open(TESTFN2, 'r')
32 data2 = fp.read()
33 fp.close()
34 if data1 != data2:
35 return 'Data forks differ'
36 rfp = MacOS.openrf(test_support.TESTFN, '*rb')
37 data1 = rfp.read(1000)
38 rfp.close()
39 rfp = MacOS.openrf(TESTFN2, '*rb')
40 data2 = rfp.read(1000)
41 rfp.close()
42 if data1 != data2:
43 return 'Resource forks differ'
44 return ''
Tim Petersf2715e02003-02-19 02:35:07 +000045
Jack Jansen10882f62003-01-28 21:39:28 +000046 def test_touched(self):
47 # This really only tests that nothing unforeseen happens.
Ezio Melotti1d55ec32010-08-02 23:34:49 +000048 with test_support.check_warnings(('macostools.touched*',
49 DeprecationWarning), quiet=True):
Brett Cannon5e263512007-05-20 23:17:38 +000050 macostools.touched(test_support.TESTFN)
Tim Petersf2715e02003-02-19 02:35:07 +000051
Ronald Oussoren4da7d782010-02-07 11:39:16 +000052 if sys.maxint < 2**32:
53 def test_copy(self):
Ezio Melotti1d55ec32010-08-02 23:34:49 +000054 test_support.unlink(TESTFN2)
Ronald Oussoren4da7d782010-02-07 11:39:16 +000055 macostools.copy(test_support.TESTFN, TESTFN2)
56 self.assertEqual(self.compareData(), '')
Tim Petersf2715e02003-02-19 02:35:07 +000057
Ronald Oussoren4da7d782010-02-07 11:39:16 +000058 if sys.maxint < 2**32:
59 def test_mkalias(self):
Ezio Melotti1d55ec32010-08-02 23:34:49 +000060 test_support.unlink(TESTFN2)
Ronald Oussoren4da7d782010-02-07 11:39:16 +000061 macostools.mkalias(test_support.TESTFN, TESTFN2)
62 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
63 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
Tim Petersf2715e02003-02-19 02:35:07 +000064
Ronald Oussoren4da7d782010-02-07 11:39:16 +000065 def test_mkalias_relative(self):
Ezio Melotti1d55ec32010-08-02 23:34:49 +000066 test_support.unlink(TESTFN2)
Ronald Oussoren4da7d782010-02-07 11:39:16 +000067 # If the directory doesn't exist, then chances are this is a new
68 # install of Python so don't create it since the user might end up
69 # running ``sudo make install`` and creating the directory here won't
70 # leave it with the proper permissions.
71 if not os.path.exists(sys.prefix):
72 return
73 macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix)
74 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
75 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
Tim Petersf2715e02003-02-19 02:35:07 +000076
77
Jack Jansen10882f62003-01-28 21:39:28 +000078def test_main():
Benjamin Peterson6f5a2b52008-06-19 21:39:06 +000079 # Skip on wide unicode
80 if len(u'\0'.encode('unicode-internal')) == 4:
81 raise test_support.TestSkipped("test_macostools is broken in USC4")
Jack Jansen10882f62003-01-28 21:39:28 +000082 test_support.run_unittest(TestMacostools)
83
84
85if __name__ == '__main__':
86 test_main()