annotate Lib/test/test_macostools.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents b36cb4602e21
children
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 os
27503
620539165e53 Test aliases too.
Jack Jansen <jack.jansen@cwi.nl>
parents: 27489
diff changeset
5 import sys
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 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
7
52456
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52353
diff changeset
8 MacOS = test_support.import_module('MacOS')
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52353
diff changeset
9 #The following modules should exist if MacOS exists.
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52353
diff changeset
10 import Carbon.File
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52353
diff changeset
11 import macostools
f2c90fd05d66 Add import_function method to test.test_support, and modify a number of
R. David Murray <rdmurray@bitdance.com>
parents: 52353
diff changeset
12
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 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
14
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 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
16
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 def setUp(self):
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 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
19 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
20 fp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 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
22 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
23 rfp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 def tearDown(self):
63634
762d89faceaa Merged revisions 79539 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58786
diff changeset
26 test_support.unlink(test_support.TESTFN)
762d89faceaa Merged revisions 79539 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58786
diff changeset
27 test_support.unlink(TESTFN2)
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
28
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 def compareData(self):
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 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
31 data1 = fp.read()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 fp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33 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
34 data2 = fp.read()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35 fp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 if data1 != data2:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37 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
38 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
39 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
40 rfp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 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
42 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
43 rfp.close()
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 if data1 != data2:
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 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
46 return ''
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
47
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 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
49 # This really only tests that nothing unforeseen happens.
63634
762d89faceaa Merged revisions 79539 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58786
diff changeset
50 with test_support.check_warnings(('macostools.touched*',
762d89faceaa Merged revisions 79539 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58786
diff changeset
51 DeprecationWarning), quiet=True):
41824
24b60622b944 Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 34113
diff changeset
52 macostools.touched(test_support.TESTFN)
27963
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
53
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
54 if sys.maxint < 2**32:
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
55 def test_copy(self):
63634
762d89faceaa Merged revisions 79539 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58786
diff changeset
56 test_support.unlink(TESTFN2)
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
57 macostools.copy(test_support.TESTFN, TESTFN2)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
58 self.assertEqual(self.compareData(), '')
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_mkalias(self):
63634
762d89faceaa Merged revisions 79539 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58786
diff changeset
62 test_support.unlink(TESTFN2)
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
63 macostools.mkalias(test_support.TESTFN, TESTFN2)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
64 fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
65 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
66
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
67 def test_mkalias_relative(self):
63634
762d89faceaa Merged revisions 79539 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58786
diff changeset
68 test_support.unlink(TESTFN2)
58786
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
69 # 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
70 # 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
71 # 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
72 # leave it with the proper permissions.
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
73 if not os.path.exists(sys.prefix):
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
74 return
6a6fc0c091cd Merged revisions 78061 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 49099
diff changeset
75 macostools.mkalias(test_support.TESTFN, TESTFN2, sys.prefix)
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
226463445697 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 27691
diff changeset
79
27489
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 def test_main():
47773
db62c448a349 skip test_macostools when UCS4 is enabled
Benjamin Peterson <benjamin@python.org>
parents: 42629
diff changeset
81 # Skip on wide unicode
db62c448a349 skip test_macostools when UCS4 is enabled
Benjamin Peterson <benjamin@python.org>
parents: 42629
diff changeset
82 if len(u'\0'.encode('unicode-internal')) == 4:
52353
e6009b9cd908 remove test_support.TestSkipped and just use unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 49099
diff changeset
83 raise unittest.SkipTest("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
84 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
85
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87 if __name__ == '__main__':
3bc71d234a29 Finally created the first two tests for MacPython modules: macfs and
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 test_main()