annotate Lib/test/test_macostools.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 6a6fc0c091cd
children 762d89faceaa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 # Copyright (C) 2003 Python Software Foundation
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 import unittest
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 import macostools
28098
2d59ca29f384 Getting rid of macfs.
Jack Jansen <jack.jansen@cwi.nl>
parents: 27963
diff changeset
5 import Carbon.File
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 import MacOS
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 import os
27503
620539165e53 Test aliases too.
Jack Jansen <jack.jansen@cwi.nl>
parents: 27489
diff changeset
8 import sys
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 from test import test_support
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 TESTFN2 = test_support.TESTFN + '2'
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 class TestMacostools(unittest.TestCase):
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 def setUp(self):
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 fp = open(test_support.TESTFN, 'w')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 fp.write('hello world\n')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 fp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 rfp = MacOS.openrf(test_support.TESTFN, '*wb')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 rfp.write('goodbye world\n')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 rfp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 def tearDown(self):
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24 try:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 os.unlink(test_support.TESTFN)
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 except:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 pass
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 try:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 os.unlink(TESTFN2)
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 except:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 pass
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
32
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 def compareData(self):
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 fp = open(test_support.TESTFN, 'r')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 data1 = fp.read()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 fp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 fp = open(TESTFN2, 'r')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 data2 = fp.read()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39 fp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 if data1 != data2:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 return 'Data forks differ'
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 rfp = MacOS.openrf(test_support.TESTFN, '*rb')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 data1 = rfp.read(1000)
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 rfp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 rfp = MacOS.openrf(TESTFN2, '*rb')
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 data2 = rfp.read(1000)
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 rfp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 if data1 != data2:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 return 'Resource forks differ'
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 return ''
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
51
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 def test_touched(self):
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 # This really only tests that nothing unforeseen happens.
41824
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 34113
diff changeset
54 import warnings
49099
ff96a313cd1c warnings.catch_warnings() now returns a list or None instead of the custom
Brett Cannon <bcannon@gmail.com>
parents: 47773
diff changeset
55 with warnings.catch_warnings():
41824
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 34113
diff changeset
56 warnings.filterwarnings('ignore', 'macostools.touched*',
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 34113
diff changeset
57 DeprecationWarning)
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 34113
diff changeset
58 macostools.touched(test_support.TESTFN)
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
59
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
60 if sys.maxint < 2**32:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
61 def test_copy(self):
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
62 try:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
63 os.unlink(TESTFN2)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
64 except:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
65 pass
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
66 macostools.copy(test_support.TESTFN, TESTFN2)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
67 self.assertEqual(self.compareData(), '')
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
68
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
69 if sys.maxint < 2**32:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
70 def test_mkalias(self):
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
71 try:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
72 os.unlink(TESTFN2)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
73 except:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
74 pass
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
75 macostools.mkalias(test_support.TESTFN, TESTFN2)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
76 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
77 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
78
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
79 def test_mkalias_relative(self):
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
80 try:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
81 os.unlink(TESTFN2)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
82 except:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
83 pass
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
84 # If the directory doesn't exist, then chances are this is a new
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
85 # install of Python so don't create it since the user might end up
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
86 # running ``sudo make install`` and creating the directory here won't
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
87 # leave it with the proper permissions.
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
88 if not os.path.exists(sys.prefix):
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
89 return
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
90 macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
91 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
92 self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
93
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
94
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 def test_main():
47773
db62c448a349 skip test_macostools when UCS4 is enabled
Benjamin Peterson <benjamin@python.org>
parents: 42629
diff changeset
96 # Skip on wide unicode
db62c448a349 skip test_macostools when UCS4 is enabled
Benjamin Peterson <benjamin@python.org>
parents: 42629
diff changeset
97 if len(u'\0'.encode('unicode-internal')) == 4:
db62c448a349 skip test_macostools when UCS4 is enabled
Benjamin Peterson <benjamin@python.org>
parents: 42629
diff changeset
98 raise test_support.TestSkipped("test_macostools is broken in USC4")
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 test_support.run_unittest(TestMacostools)
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 if __name__ == '__main__':
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 test_main()